#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;

long long d[400500], k[400500], x[400500], y[400500], u[400500], v[400500];
int ansl[100500], ansr[100500];
long long mn1[30][100500], mn2[30][100500];

long long get1(int l, int r){
    int len = (r - l + 1), l2 = log2(len);
    return max(mn1[l2][l], mn1[l2][r - (1 << l2) + 1]);
}

long long get2(int l, int r){
    int len = (r - l + 1), l2 = log2(len);
    return max(mn2[l2][l], mn2[l2][r - (1 << l2) + 1]);
}

int main(){
    freopen("mountain.in", "r", stdin);
    freopen("mountain.out", "w", stdout);
    int n, q;
    x[0] = y[0] = 0;
    cin >> n >> q;

    for (int i = 1; i <= n; i++){
        cin >> d[i]>> k[i];
        x[i] = x[i - 1] + d[i];
        y[i] = y[i - 1] + k[i] * d[i];
    }

    if (n > 3000 || q > 3000){
        long long ul = 1e9 + 100, ur = -1e9 - 100, vl = 1e9 + 100, vr = -1e9 -100;
        for (int i = 0; i < q; i++){
            //cin >> u[i] >> v[i];
            scanf("%d%d", &u[i], &v[i]);
            ul = min(ul, u[i]);
            ur = max(ur, u[i]);
            vl = min(vl, v[i]);
            vr = max(vr, v[i]);
        }
        if (ul == ur){
            vector<pair<int, int> > v1;
            for (int i = 0; i < q; i++)
                v1.push_back(make_pair(v[i], i));
            int pos = 0, posl, l, r, posr;
            while (pos <= n && x[pos] <= ul)
                pos++;
            posr = pos + 1;
            posl = pos - 1;
            sort(v1.begin(), v1.end());
            for (int i = 0; i < q; i++){
                while (posl > 0 && y[posl] + ul * (long long)k[posl] - x[posl] * (long long)k[posl] <= v1[i].first)
                    posl--;
                ansl[v1[i].second] = x[posl];
                while (posr <= n && y[posr] + ul * (long long)k[posr] - x[posr] * (long long)k[posr] <= v1[i].first)
                    posr++;
                ansr[v1[i].second] = x[min(n, posr - 1)];
            }
            for (int i = 0; i < q; i++)
                cout << ansl[i] << " " << ansr[i] << endl;
        }else
        if (vr == vl){

        }else{
            int uu, vv;
            int n1 = n + 1;
            mn2[0][0] = -1e18;
            for (int i = 0; i < n1; i++)
                if (i == 0){
                    mn1[0][n] = -1e18;
                    mn2[0][i + 1] = -1e18;
                }else
                if (k[i] == 1){
                    mn1[0][i - 1] = (y[i] - x[i]);
                    mn2[0][i] = -1e18;
                }else{
                    mn1[0][i - 1] = -1e18;
                    mn2[0][i] = (y[i] + x[i]);
                }
            for (int t = 1; t < 30; t++)
                for (int i = 0; i <= n; i++)
                    mn1[t][i] = max(mn1[t - 1][i], (i + (1 << (t - 1)) <= n? mn1[t - 1][i + (1 << (t - 1))]:(long long)-1e18));
            for (int t = 1; t < 30; t++)
                for (int i = 0; i <= n; i++)
                    mn2[t][i] = max(mn2[t - 1][i], (i + (1 << (t - 1)) <= n? mn2[t - 1][i + (1 << (t - 1))]:(long long)-1e18));
            for (int i = 0; i < q; i++){
                uu = u[i];
                vv = v[i];
                int l = 0, r = n + 1, m, pos;
                while (l + 1 != r){
                    m = (l + r) / 2;
                    if (x[m] <= uu)
                        l = m;
                    else
                        r = m;
                }
                pos = r;
                l = -1, r = pos - 1;
                if (u == 0)
                    cout << "0 ";
                else{
                    if (x[r] == uu)
                        r--;
                    while (l + 1 != r){
                        m = (l + r) / 2;
                        //cout << m << " " << pos - 1 << " " << get1(m, pos - 1) << endl;
                        if (get1(m, pos - 1) + uu <= vv)
                            r = m;
                        else
                            l = m;
                    }
                    //cout << get1(r - 1, pos - 1) << endl;
                    cout << x[r] << " ";
                }
                //cout << x[max(r - 1, 0)] << " ";
                if (pos >= n)
                    cout << x[n] << "\n";
                else{
                    l = pos, r = n + 1;
                    while (l + 1 != r){
                        m = (l + r) / 2;
                    //cout << m << " " << pos - 1 << " " << get2(pos, m) << endl;
                        if (get2(pos, m) - uu <= vv)
                            l = m;
                        else
                            r = m;
                    }
                    cout <<x[l] << "\n";
                }
            }
        }
    }else{
        int u, v;
        for (int i = 0; i < q; i++){
            cin >> u >> v;
            int pos = 0, pos1, l, r;
            while (pos <= n && x[pos] <= u)
                pos++;
            pos1 = pos;
            pos--;
            while (pos > 0 && y[pos] + u * (long long)k[pos] - x[pos] * (long long)k[pos] <= v)
                pos--;
            l = x[pos];
            pos = pos1;
            pos++;
            while (pos <= n && y[pos] + u * (long long)k[pos] - x[pos] * (long long)k[pos] <= v)
                pos++;
            pos = min(pos, n + 1);
            r = x[pos - 1];
            cout << l << " " << r << "\n";
        }
    }
    return 0;
}
