#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(a, b), point(a, c));
    long long s3 = vec(point(a, b), point(a, d));
    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;


void change(int i, int x) {
    d[i] = make_pair(x, i - ss);
    while (i > 0) {
        i /= 2;
        d[i] = max(d[i * 2], d[i * 2 + 1]);
    }
}


pair<int, int> rmq(int v, int vl, int vr, int l, int r) {
    if (vr < l || vl > r) {
        return make_pair(0, 0);
    }
    if (l <= vl && vr <= r) {
        return d[v];
    }
    return max(rmq(v * 2, vl, (vl + vr) / 2, l, r), rmq(v * 2 + 1, (vl + vr) / 2 + 1, vr, l, r));
}


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);
    }
    if (b) {
        while (ss <= n) {
            ss *= 2;
        }
        vector<pair<int, int> > g;
        for (int i = 1; i <= n; i++) {
            if (i != n) {
                if (k[i] == 1 && k[i + 1] == -1) {
                    g.push_back(make_pair(p[i].x, p[i].y));
                    //cout << p[i].x << ' ' << p[i].y << endl;
                }
            }
        }
        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 = 0, ansr = p[n].x;
            int l = lower_bound(g.begin(), g.end(), make_pair(x, y)) - g.begin();
            if (l != (int)g.size()) {
                if (g.back().first - x > y - g.back().second) {
                    int l1 = l;
                    int r1 = (int)g.size() - 1;
                    while (l1 != r1) {
                        int m = (l1 + r1) / 2;
                        if (g[m].first - x > y - g[m].second) {
                            r1 = m;
                        } else {
                            l1 = m + 1;
                        }
                    }
                    ansr = g[l1].first;
                }
            }
            if (l != 0) {
                if (x - g[0].first > y - g[0].second) {
                    int l1 = 0;
                    int r1 = l - 1;
                    while (l1 != r1) {
                        int m = (l1 + r1) / 2;
                        if (x - g[m].first > y - g[m].second) {
                            r1 = m;
                        } else {
                            l1 = m - 1;
                        }
                    }
                    ansl = g[l1].first;
                }
            }
            printf("%d %d\n", ansl, ansr);
        }
    }
    return 0;
}
/*
6 1
3 1
2 -1
1 1
1 -1
1 1
2 -1
5 3
*/
