#includeusingnamespace std;#definefifirst#definesesecond#defineIOSstd::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);#defineintlonglongconstint N =1e3+10;constint mod =1e9+7;typedef pair<int,int>PII;//--------------------------------------------------------------constdouble eps =1e-9;constdouble pi =acos(-1);inlinedoublesqr(double x){return x * x;}//平方intsign(double x){if(fabs(x)< eps)return0;if(x >0)return1;return-1;}//符号structpoint{double x , y;point(){}point(double a ,double b):x(a),y(b){}friend point operator+(const point &a ,const point &b){returnpoint(a.x + b.x , a.y + b.y);}friend point operator-(const point &a ,const point &b){returnpoint(a.x - b.x , a.y - b.y);}friendbooloperator==(const point &a ,const point &b){return!sign(a.x - b.x)&&!sign(a.y - b.y);}friend point operator*(const point &a ,constdouble&b){returnpoint(a.x * b , a.y * b);}friend point operator*(constdouble&a ,const point &b){returnpoint(a * b.x , a * b.y);}friend point operator/(const point &a ,constdouble&b){returnpoint(a.x / b , a.y / b);}//向量模长 doublenorm(){returnsqrt(sqr(x)+sqr(y));}};structline{
point a , b;line(){}line(point x , point y):a(x),b(y){}};doubledet(const point &a ,const point &b){return a.x * b.y - a.y * b.x;}//叉积 判断两点共线 doubledot(const point &a ,const point &b){return a.x * b.x + a.y * b.y;}//点积doubledist(const point &a ,const point &b){return(a - b).norm();}//两点距离
point rotate_point(const point &a ,const point &p ,double A){double tx = p.x - a.x , ty = p.y - a.y;returnpoint(a.x + tx *cos(A)- ty *sin(A), a.y + tx *sin(A)+ ty *cos(A));}// p 点 绕 a 点逆时针旋转 A 弧度inttoleft(const point &p ,const point &a ,const point &b){returnsign(det(b - a , p - a));// 1 左 0 上 -1 右}//只适用凸多边形//判断点 p 是否在线段 st 上(包括端点)boolpoint_on_segment(point p , point s , point t){returnsign(det(p - s , t - s))==0&&sign(dot(p - s , p - t))<=0;}boolparallel(line a , line b){return!sign(det(a.a - a.b , b.a - b.b));}boolline_make_point(line a , line b , point &res){if(parallel(a , b))return0;double s1 =det(a.a - b.a , b.b - b.a);double s2 =det(a.b - b.a , b.b - b.a);
res =(s1 * a.b - s2 * a.a)/(s1 - s2);return1;}//--------------------------------------------------------------//--------------------------------------------------------------int n , m;
point st , ed , p[N], now;double x , y;int h , k;
vector<tuple<double,double,double>>ans[N];signedmain(){
IOS
cout << fixed <<setprecision(10);
cin >> n >> m;
cin >> x >> y;
st = point{x , y};
cin >> x >> y;
ed = point{x , y};for(int i =1; i <= n ; i ++){
cin >> x >> y;
p[i]= point{x , y};}
line l = line{st , ed};for(int i =1; i <= n ; i ++){for(int j = i +1; j <= n ; j ++){
line r = line{p[i], p[j]};if(toleft(st , p[i], p[j])*toleft(ed , p[i], p[j])>0)continue;line_make_point(l , r , now);
ans[i].emplace_back(now.x , now.y ,dist(now , st));
ans[j].emplace_back(now.x , now.y ,dist(now , st));}}for(int i =1; i <= n ; i ++)sort(ans[i].begin(), ans[i].end(),[&](tuple<double,double,double> a , tuple<double,double,double> b){returnget<2>(a)<get<2>(b);});for(int i =1; i <= m ; i ++){
cin >> h >> k;if(ans[h].size()< k){
cout <<"-1\n";}else{auto[x , y , z]= ans[h][k -1];
cout << x <<" "<< y <<"\n";}}return0;}//freopen("文件名.in","r",stdin);//freopen("文件名.out","w",stdout);