#include<bits/stdc++.h>
#define x first
#define y second
#define sd(n) scanf("%d",&n)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define MAXN 100000
#define EPS 1e-9
PII ar[2*MAXN];
// * Line intersection
// * Returns the point of intersection of two lines:
// * (x[0],y[0])-(x[1],y[1]) and (x[2],y[2])-(x[3],y[3]). Puts the result (x, y) into (r[0], r[1])
// and returns true. If there is no intersection, return false.
bool lineIntersect( vector<double>& x, vector<double>& y, vector<double>& r ){
double n[2]; n[0] = y[3] - y[2]; n[1] = x[2] - x[3];
double denom = n[0] * ( x[1] - x[0] ) + n[1] * ( y[1] - y[0] );
if( fabs( denom ) < EPS ) return false;
double num = n[0] * ( x[0] - x[2] ) + n[1] * ( y[0] - y[2] );
double t = -num / denom;
r[0] = x[0] + t * ( x[1] - x[0] );
r[1] = y[0] + t * ( y[1] - y[0] );
return true;
}
//check if region of edge (mid, mid+1) exceeds k
//find interesection of lines (mid, mid+1) and (idx, idx+1)
//use distance to check if valid or not
int f(int mid, int idx, int k){
vector<double> x(4),y(4),r(2);
x[0]=ar[mid].x; x[1]=ar[mid+1].x;
y[0]=ar[mid].y; y[1]=ar[mid+1].y;
x[2]=ar[idx].x; x[3]=ar[idx+1].x;
y[2]=ar[idx].y; y[3]=ar[idx+1].y;
if(not lineIntersect(x, y, r))return true;
double dist1=sqrt((r[0]-ar[idx].x)*(r[0]-ar[idx].x)
+ (r[1]-ar[idx].y)*(r[1]-ar[idx].y));
double dist2=sqrt((r[0]-ar[idx+1].x)*(r[0]-ar[idx+1].x)
+ (r[1]-ar[idx+1].y)*(r[1]-ar[idx+1].y));
if(fabs(dist1-k) < EPS)return 2;
if(dist1 < dist2 or dist1 + EPS > k)
return 1;
return 0;
}
int main()
{
int n,q;
sd(n),sd(q);
for(int i=0; i<n; i++)
sd(ar[i].x),sd(ar[i].y);
for(int i=n; i<2*n; i++)
ar[i]=ar[i-n];
while(q--){
int idx,k;
sd(idx),sd(k);
//binary search on edge
int l=idx, r=l+n, mid;
while(r-l>1){
mid=(l+r)/2;
if(f(mid, idx, k) >= 1)
r=mid;
else l=mid;
}
if(f((l+1)%n, idx, k) == 2)
printf("%d %d\n",(l+1)%n, (l+2)%n);
else
printf("%d\n", (l+1)%n);
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCiNkZWZpbmUgeCBmaXJzdAojZGVmaW5lIHkgc2Vjb25kCiNkZWZpbmUgc2Qobikgc2NhbmYoIiVkIiwmbikKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgbG9uZyBsb25nIExMOwp0eXBlZGVmIHBhaXI8aW50LGludD4gUElJOwoKI2RlZmluZSBNQVhOIDEwMDAwMAojZGVmaW5lIEVQUyAxZS05ClBJSSBhclsyKk1BWE5dOwoKLy8gKiBMaW5lIGludGVyc2VjdGlvbgovLyAqIFJldHVybnMgdGhlIHBvaW50IG9mIGludGVyc2VjdGlvbiBvZiB0d28gbGluZXM6Ci8vICogKHhbMF0seVswXSktKHhbMV0seVsxXSkgYW5kICh4WzJdLHlbMl0pLSh4WzNdLHlbM10pLiBQdXRzIHRoZSByZXN1bHQgKHgsIHkpIGludG8gKHJbMF0sIHJbMV0pCi8vICAgYW5kIHJldHVybnMgdHJ1ZS4gSWYgdGhlcmUgaXMgbm8gaW50ZXJzZWN0aW9uLCByZXR1cm4gZmFsc2UuCmJvb2wgbGluZUludGVyc2VjdCggdmVjdG9yPGRvdWJsZT4mIHgsIHZlY3Rvcjxkb3VibGU+JiB5LCB2ZWN0b3I8ZG91YmxlPiYgciApewogICAgZG91YmxlIG5bMl07IG5bMF0gPSB5WzNdIC0geVsyXTsgblsxXSA9IHhbMl0gLSB4WzNdOwogICAgZG91YmxlIGRlbm9tID0gblswXSAqICggeFsxXSAtIHhbMF0gKSArIG5bMV0gKiAoIHlbMV0gLSB5WzBdICk7CiAgICBpZiggZmFicyggZGVub20gKSA8IEVQUyApIHJldHVybiBmYWxzZTsKICAgIGRvdWJsZSBudW0gPSBuWzBdICogKCB4WzBdIC0geFsyXSApICsgblsxXSAqICggeVswXSAtIHlbMl0gKTsKICAgIGRvdWJsZSB0ID0gLW51bSAvIGRlbm9tOwogICAgclswXSA9IHhbMF0gKyB0ICogKCB4WzFdIC0geFswXSApOwogICAgclsxXSA9IHlbMF0gKyB0ICogKCB5WzFdIC0geVswXSApOwogICAgcmV0dXJuIHRydWU7Cn0KCgovL2NoZWNrIGlmIHJlZ2lvbiBvZiBlZGdlIChtaWQsIG1pZCsxKSBleGNlZWRzIGsKLy9maW5kIGludGVyZXNlY3Rpb24gb2YgbGluZXMgKG1pZCwgbWlkKzEpIGFuZCAoaWR4LCBpZHgrMSkKLy91c2UgZGlzdGFuY2UgdG8gY2hlY2sgaWYgdmFsaWQgb3Igbm90CmludCBmKGludCBtaWQsIGludCBpZHgsIGludCBrKXsKICAgIHZlY3Rvcjxkb3VibGU+IHgoNCkseSg0KSxyKDIpOwogICAgeFswXT1hclttaWRdLng7IHhbMV09YXJbbWlkKzFdLng7CiAgICB5WzBdPWFyW21pZF0ueTsgeVsxXT1hclttaWQrMV0ueTsKICAgIHhbMl09YXJbaWR4XS54OyB4WzNdPWFyW2lkeCsxXS54OwogICAgeVsyXT1hcltpZHhdLnk7IHlbM109YXJbaWR4KzFdLnk7CgogICAgaWYobm90IGxpbmVJbnRlcnNlY3QoeCwgeSwgcikpcmV0dXJuIHRydWU7CgogICAgZG91YmxlIGRpc3QxPXNxcnQoKHJbMF0tYXJbaWR4XS54KSooclswXS1hcltpZHhdLngpIAogICAgICAgICAgICArIChyWzFdLWFyW2lkeF0ueSkqKHJbMV0tYXJbaWR4XS55KSk7CiAgICBkb3VibGUgZGlzdDI9c3FydCgoclswXS1hcltpZHgrMV0ueCkqKHJbMF0tYXJbaWR4KzFdLngpIAogICAgICAgICAgICArIChyWzFdLWFyW2lkeCsxXS55KSooclsxXS1hcltpZHgrMV0ueSkpOwogICAgaWYoZmFicyhkaXN0MS1rKSA8IEVQUylyZXR1cm4gMjsKICAgIGlmKGRpc3QxIDwgZGlzdDIgb3IgZGlzdDEgKyBFUFMgPiBrKQogICAgICAgIHJldHVybiAxOwogICAgcmV0dXJuIDA7Cn0KCmludCBtYWluKCkKewogICAgaW50IG4scTsKICAgIHNkKG4pLHNkKHEpOwogICAgZm9yKGludCBpPTA7IGk8bjsgaSsrKQogICAgICAgIHNkKGFyW2ldLngpLHNkKGFyW2ldLnkpOwogICAgZm9yKGludCBpPW47IGk8MipuOyBpKyspCiAgICAgICAgYXJbaV09YXJbaS1uXTsKICAgIHdoaWxlKHEtLSl7CiAgICAgICAgaW50IGlkeCxrOwogICAgICAgIHNkKGlkeCksc2Qoayk7CgogICAgICAgIC8vYmluYXJ5IHNlYXJjaCBvbiBlZGdlCiAgICAgICAgaW50IGw9aWR4LCByPWwrbiwgbWlkOwogICAgICAgIHdoaWxlKHItbD4xKXsKICAgICAgICAgICAgbWlkPShsK3IpLzI7CiAgICAgICAgICAgIGlmKGYobWlkLCBpZHgsIGspID49IDEpCiAgICAgICAgICAgICAgICByPW1pZDsKICAgICAgICAgICAgZWxzZSBsPW1pZDsKICAgICAgICB9CgogICAgICAgIGlmKGYoKGwrMSklbiwgaWR4LCBrKSA9PSAyKQogICAgICAgICAgICBwcmludGYoIiVkICVkXG4iLChsKzEpJW4sIChsKzIpJW4pOwogICAgICAgIGVsc2UKICAgICAgICAgICAgcHJpbnRmKCIlZFxuIiwgKGwrMSklbik7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==