#include <bits/stdc++.h>

using namespace std;

struct point{
    long long x, y;
    point(){
        x = y = 0;
    }
};

vector<point> p;
long long k[400001];
long long mx[800001];
long long mx1[800001];
long long mx2[800001];
long long x2[400001];
long long y2[400001];
const long long INF = 1e18;

void init(int l, int r, int i){
    if (l == r - 1){
        mx[i] = k[l + 1] * (x2[0] - p[l].x) + p[l].y;
        return;
    }
    int m = (l + r) / 2;
    init(l, m, 2 * i + 1);
    init(m, r, 2 * i + 2);
    mx[i] = max(mx[2 * i + 1], mx[2 * i + 2]);
}

void init1(int l, int r, int i){
    if (l == r - 1){
        if (k[l + 1] == 1){
            mx1[i] = p[l].y - p[l].x;
            mx2[i] = -INF;
        }
        else{
            mx1[i] = -INF;
            mx2[i] = p[l + 1].y + p[l + 1].x;
        }
        return;
    }
    int m = (l + r) / 2;
    init1(l, m, 2 * i + 1);
    init1(m, r, 2 * i + 2);
    mx1[i] = max(mx1[2 * i + 1], mx1[2 * i + 2]);
    mx2[i] = max(mx2[2 * i + 1], mx2[2 * i + 2]);
}

long long maxx(int ql, int qr, int l, int r, int i){
    if (ql >= r || l >= qr) return -INF;
    if (l >= ql && qr >= r) return mx[i];
    int m = (l + r) / 2;
    return max(maxx(ql, qr, l, m, 2 * i + 1), maxx(ql, qr, m, r, 2 * i + 2));
}

long long maxx1(int ql, int qr, int l, int r, int i){
    if (ql >= r || l >= qr) return -INF;
    if (l >= ql && qr >= r) return mx1[i];
    int m = (l + r) / 2;
    return max(maxx1(ql, qr, l, m, 2 * i + 1), maxx1(ql, qr, m, r, 2 * i + 2));
}

long long maxx2(int ql, int qr, int l, int r, int i){
    if (ql >= r || l >= qr) return -INF;
    if (l >= ql && qr >= r) return mx2[i];
    int m = (l + r) / 2;
    return max(maxx2(ql, qr, l, m, 2 * i + 1), maxx2(ql, qr, m, r, 2 * i + 2));
}

int main(){
    #ifdef DEBUG
    freopen("input.txt", "r", stdin);
    #else
    freopen("mountain.in", "r", stdin);
    freopen("mountain.out", "w", stdout);
    #endif // DEBUG
    int n, q;
    cin >> n >> q;
    p.resize(n + 1);
    bool b1 = true;
    for (int i = 1; i <= n; i++){
        long long d;
        cin >> d >> k[i];
        b1 &= (k[i] == 1 || k[i] == -1);
        p[i].x = p[i - 1].x + d;
        p[i].y = p[i - 1].y + d * k[i];
    }
    bool b = true;
    for (int ct = 0; ct < q; ct++){
        cin >> x2[ct] >> y2[ct];
        if (ct > 0){
            b &= x2[ct] == x2[ct - 1];
        }
    }
    if (b){
        init(0, n, 0);
        for (int ct = 0; ct < q; ct++){
            long long x1 = x2[ct], y1 = y2[ct];
            int l = 0;
            int r = n;
            while (l < r - 1){
                int m = (l + r) / 2;
                if (p[m].x > x1){
                    r = m;
                }
                else{
                    l = m;
                }
            }
            int i = l;
            l = -1;
            r = i;
            while (l < r - 1){
                int m = (l + r) / 2;
                if (maxx(m, i, 0, n, 0) > y1){
                    l = m;
                }
                else{
                    r = m;
                }
            }
            cout << p[r].x << " ";
            l = i + 1;
            r = n + 1;
            while (l < r - 1){
                int m = (l + r) / 2;
                if (maxx(i, m, 0, n, 0) > y1){
                    r = m;
                }
                else{
                    l = m;
                }
            }
            cout << p[l].x << "\n";
        }
        return 0;
    }
    if (b1){
        init1(0, n, 0);
        for (int ct = 0; ct < q; ct++){
            long long x1 = x2[ct], y1 = y2[ct];
            int l = 0;
            int r = n;
            while (l < r - 1){
                int m = (l + r) / 2;
                if (p[m].x > x1){
                    r = m;
                }
                else{
                    l = m;
                }
            }
            int i = l;
            l = -1;
            r = i;
            while (l < r - 1){
                int m = (l + r) / 2;
                if (maxx1(m, i, 0, n, 0) > y1 - x1){
                    l = m;
                }
                else{
                    r = m;
                }
            }
            cout << p[r].x << " ";
            l = i + 1;
            r = n + 1;
            while (l < r - 1){
                int m = (l + r) / 2;
                if (maxx2(i, m, 0, n, 0) > y1 + x1){
                    r = m;
                }
                else{
                    l = m;
                }
            }
            cout << p[l].x << "\n";
        }
        return 0;
    }
    for (int ct = 0; ct < q; ct++){
        long long x1, y1;
        x1 = x2[ct];
        y1 = y2[ct];
        int l = 0;
        int r = n;
        while (l < r - 1){
            int m = (l + r) / 2;
            if (p[m].x > x1){
                r = m;
            }
            else{
                l = m;
            }
        }
        int i = l;
        while (i > 0){
            long long y2 = p[i - 1].y + (x1 - p[i - 1].x) * k[i];
            if (y2 > y1)
                break;
            i--;
        }
        cout << p[i].x << " ";
        i = l + 1;
        while (i <= n){
            long long y2 = p[i - 1].y + (x1 - p[i - 1].x) * k[i];
            if (y2 > y1){
                break;
            }
            i++;
        }
        i--;
        cout << p[i].x << "\n";
    }
    return 0;
}
