#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) {
    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;
    }
    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 (s2 >= 0 && s3 >= 0) {
        return 0;
    }
    return 1;
}


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


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);
    }
    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;
            if (j != 0 && intersection(p[j], p[j + 1], p[j - 1], point(x, y))) {
                break;
            }
        }
        for (int j = s; j <= n; j++) {
            ansr = p[j].x;
            if (j != 0 && j != n && intersection(p[j], p[j - 1], p[j + 1], point(x, y))) {
                break;
            }
        }
        printf("%d %d\n", ansl, ansr);
    }
    return 0;
}
/*
6 1
3 1
2 -1
1 1
1 -1
1 1
2 -1
5 3
*/
