#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

typedef long long ll;

const long long inf = 2000000000;

int main()
{
    freopen("mountain.in", "r", stdin);
    freopen("mountain.out", "w", stdout);
    long long n, q;
    long long i, j;
    cin >> n >> q;
    vector<long long> x(n), y(n), k(n), d(n);
    long long x0 = 0, y0 = 0, sum = 0;
    bool fl = true;
    for (i = 0; i < n; i++)
    {
        x[i] = x0;
        y[i] = y0;
        cin >> d[i] >> k[i];
        sum += d[i];
        x0 += d[i];
        y0 += d[i] * k[i];
        if (k[i] != 1 && k[i] != -1)
            fl = false;
    }
    if (fl)
    {
        vector<int> vs, ns;
        for (i = 0; i < n; i++)
        {
            if (k[i] > 0)
                vs.push_back(i);
            else
                ns.push_back(i);
        }
        for (j = 0; j < q; j++)
        {
            ll u, v;
            cin >> u >> v;
            ll l1, r1, l = 0, r = sum;
            l1 = 0;
            r1 = vs.size();
            while (l1 < r1 - 1)
            {
                ll mid = (l1 + r1) / 2;
                i = vs[mid];
                long long dx = u - x[i];
                y0 = dx * k[i] + y[i];
                if (y0 > v)
                {
                    l1 = mid;
                }
                else
                    r1 = mid;
            }
            ll mid = l1;
            i = vs[mid];
            long long dx = u - x[i];
            y0 = dx * k[i] + y[i];
            if (y0 > v)
                l = x[i] + d[i];
            l1 = 0;
            r1 = ns.size();
            while (l1 < r1 - 1)
            {
                ll mid = (l1 + r1) / 2;
                i = ns[mid];
                long long dx = u - x[i];
                y0 = dx * k[i] + y[i];
                if (y0 <= v)
                {
                    l1 = mid;
                }
                else
                    r1 = mid;
            }
            if (l1 + 1 < ns.size())
            {
                mid = l1 + 1;
                i = ns[mid];
                dx = u - x[i];
                y0 = dx * k[i] + y[i];
                if (y0 > v)
                    r = x[i];
            }
            mid = l1;
            i = ns[mid];
            dx = u - x[i];
            y0 = dx * k[i] + y[i];
            if (y0 > v)
                r = x[i];
            cout << l << ' ' << r << endl;
        }
    }
    return 0;
}
