#include <iostream>
#include <sstream>
#include <cstdio>
#include <set>
#include <algorithm>
#include <cmath>
#include <vector>


using namespace std;

struct point{
    int x, y;
    point(){}
    point(int _x, int _y) {
        x = _x;
        y = _y;
    }
    point(point a, point b) {
        x = b.x - a.x;
        y = b.y - a.y;
    }
};


long long vec(point a, point b) {
    return 1LL * a.x * b.y - 1LL * a.y * b.x;
}


bool intersection(point a, point b, point c, point d, bool bb) {
    long long s2 = vec(point(c, d), point(c, a));
    long long s3 = vec(point(c, d), point(c, b));
    if (s2 == 0 && s3 == 0) {
        return 0;
    }
    if (!(max(c.x, d.x) <= min(a.x, b.x) || max(a.x, b.x) <= min(d.x, c.x))) {
        //cout << a.x << ' ' << a.y << ' ' << b.x << ' ' << b.y << endl;
        // cout << c.x << ' ' << c.y << ' ' << d.x << ' ' << d.y << endl;
        // cout << "popa" << endl;
        if (s2 >= 0 && s3 >= 0 && !bb) {
            return 1;
        }
        if (s2 <= 0 && s3 <= 0 && bb) {
            return 1;
        }
    }
    if (s2 >= 0 && s3 >= 0) {
        return 0;
    }
    if (s2 <= 0 && s3 <= 0) {
        return 0;
    }
    long long s = vec(point(a, b), point(a, c));
    long long s1 = vec(point(a, b), point(a, d));
    if (s <= 0 && s1 <= 0) {
        return 0;
    }
    if (s >= 0 && s1 >= 0) {
        return 0;
    }
    return 1;
}

int n;
int q;
point p[100001];
int k[100001];
pair<int, int> d[300001];
int ss = 1;
pair<int, int> anss[100001];


int main() {
    freopen("mountain.in", "r", stdin);
    freopen("mountain.out", "w", stdout);
    cin >> n >> q;
    p[0] = point(0, 0);
    bool b = 1;
    vector<int> v;
    v.push_back(0);
    for (int i = 1; i <= n; i++) {
        int d;
        scanf("%d %d", &d, &k[i]);
        if (k[i] != 1 && k[i] != -1) {
            b = 0;
        }
        p[i] = point(p[i - 1].x + d, p[i - 1].y + k[i] * d);
        v.push_back(p[i].x);
        //cout << p[i].x << endl;
    }
    if (n > 3000 || q > 3000) {
        vector<pair<pair<int, int>, int> > vv;
        for (int i = 0; i < q; i++) {
            int x, y;
            scanf("%d %d", &x, &y);
            vv.push_back(make_pair(make_pair(y, x), i));
        }
        sort(vv.begin(), vv.end());
        int ansl = vv[0].first.second;
        int ansr = vv[0].first.second;
        int x = vv[0].first.second;
        int s = lower_bound(v.begin(), v.end(), x) - v.begin();
        int l = s - 1;
        int r = s;
        for (int i = 0; i < q; i++) {
           // cout << s << endl;
            int y = vv[i].first.first;
            //cout << s << endl;
            for (int j = l; j >= 0; j--) {
                ansl = p[j].x;
                bool bb = 1;
                for (int k = max(j - 2, 0); k <= min(j + 2, n); k++) {
                    if (k != 0 && j != 0 && k != n && k != j - 1 && intersection(p[k], p[k + 1], p[j - 1], point(x, y), 0)) {
                        bb = 0;
                        break;
                    }
                }
                if (!bb) {
                    break;
                }
                l--;
            }
            for (int j = r; j <= n; j++) {
                ansr = p[j].x;
                bool bb = 1;
                for (int k = min(j + 2, n); k >= max(0, j - 2); k--) {
                    if (k != 0 && j != n && k != j + 1 && intersection(p[k - 1], p[k], p[j + 1], point(x, y), 1)) {
                        bb = 0;
                        break;
                    }
                }
                if (!bb) {
                    break;
                }
                r++;
            }
            anss[vv[i].second] = make_pair(ansl, ansr);
        }
        for (int i = 0; i < q; i++) {
            printf("%d %d\n", anss[i].first, anss[i].second);
        }
        return 0;
    }
    for (int i = 0; i < q; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        int s = lower_bound(v.begin(), v.end(), x) - v.begin();
       // cout << s << endl;
        int ansl = x, ansr = x;
        //cout << s << endl;
        for (int j = s - 1; j >= 0; j--) {
            ansl = p[j].x;
            bool bb = 1;
            for (int k = max(j - 3, 0); k <= min(j + 3, n); k++) {
                if (k != 0 && j != 0 && k != n && k != j - 1 && intersection(p[k], p[k + 1], p[j - 1], point(x, y), 0)) {
                    bb = 0;
                    break;
                }
            }
            if (!bb) {
                break;
            }
        }
        for (int j = s; j <= n; j++) {
            ansr = p[j].x;
            bool bb = 1;
            for (int k = min(j + 3, n); k >= max(0, j - 3); k--) {
                if (k != 0 && j != n && k != j + 1 && intersection(p[k - 1], p[k], p[j + 1], point(x, y), 1)) {
                    bb = 0;
                    break;
                }
            }
            if (!bb) {
                break;
            }
        }
        printf("%d %d\n", ansl, ansr);
    }
    return 0;
}
/*
8 4
1 -3
2 0
1 1
2 0
1 -3
1 3
1 2
1 0
2 -2
6 -1
6 4
7 -4
6 1
3 1
 2 -1
 1 1
 1 -1
 1 1
 2 -1

*/
