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

typedef long long ll;
typedef __int128_t int_type;
using namespace std;

struct point
{
    int_type x, y;
    point() {}
};

struct vect
{
    int_type x, y;
    vect(point a, point b)
    {
        x = b.x - a.x;
        y = b.y - a.y;
    }
};

int_type cp(vect u, vect v)
{
    return u.x * v.y - v.x * u.y;
}

struct query
{
    point p;
    int i;
    query() {};
};

bool operator<(const query& q, const query& p)
{
    if (q.p.x != p.p.x)
        return q.p.x < p.p.x;
    return q.p.y < p.p.y;
}

struct event
{
    point p; int type; int i;
    event() {}
};

bool operator<(const event& e, const event& w)
{
    if (e.p.x != w.p.x)
        return e.p.x < w.p.x;
    else
        return e.type < w.type;
}

int main()
{
#ifndef LOCAL
    freopen("mountain.in", "r", stdin);
    freopen("mountain.out", "w", stdout);
#endif
    int n, q;
    cin >> n >> q;
    point a;
    a.x = 0, a.y = 0;
    vector<point> pts(n + 1);
    pts[0] = a;
    bool kpmo = true;
    for (int i = 0; i < n; i++)
    {
        int k, d;
        cin >> d >> k;
        a.x += (int_type)d;
        a.y += (int_type)k * (int_type)d;
        pts[i + 1] = a;
        if (k != 1 && k != -1)
            kpmo = false;
//        cout << "!" << (int)pts[i + 1].x << " " << (int)pts[i + 1].y << endl;
    }
    if (n <= 3000)
    {
        for (int _ = 0; _ < q; _++)
        {
            int x, y;
            cin >> x >> y;
            point p; p.x = x; p.y = y;
            int _i = 0;
            while (pts[_i].x < p.x) _i++;
            int i = _i;
            if (pts[i].x != p.x)
                i--;
            while (i > 0 && cp(vect(p, pts[i]), vect(p, pts[i - 1])) <= 0)
                i--;
            int j = _i;
            while (j < n && cp(vect(p, pts[j]), vect(p, pts[j + 1])) >= 0)
                j++;
            cout << (int)pts[i].x << " " << (int)pts[j].x << endl;
        }
    }
    else
    {
        if (kpmo)
        {
            event* evs = new event[n + q];
            for (int i = 0; i < n; i++)
            {
                evs[i].i = i;
                evs[i].type = 0;
                evs[i].p = pts[i];   
            }
            for (int i = 0; i < q; i++)
            {
                int x, y;
                cin >> x >> y;
                evs[n + i].i = i;
                evs[n + i].type = 1;
                evs[n + i].p.x = x;
                evs[n + i].p.y = y;
            }
            sort(evs, evs + (n + q));
            int_type add = 0;
            set<pair<int_type, int> > s;
            map<int_type, int> mp;
            int_type* lans = new int_type[q];
            int_type* rans = new int_type[q];
            for (int i = 0; i < q + n; i++)
            {
                if (i > 0)
                    add += evs[i].p.x - evs[i - 1].p.x;
                if (evs[i].type == 0)
                {
                    s.insert(make_pair(evs[i].p.y - add, evs[i].i));
                    if (!mp.count(evs[i].p.x - evs[i].p.y))
                        mp[evs[i].p.x - evs[i].p.y] = evs[i].i;
                }
                else if (mp.count(evs[i].p.x - evs[i].p.y))
                {
                    lans[evs[i].i] = pts[mp[evs[i].p.x - evs[i].p.y]].x;
                }
                else
                {
                    auto it = s.upper_bound(make_pair(evs[i].p.y - add, -1));
                    it--;
                    lans[evs[i].i] = pts[(it->second)].x;
                }
            }

            for (int i = 0; i < n; i++)
                pts[i].x = -pts[i].x;
            s.clear();
            mp.clear();
            add = 0;
            for (int i = 0; i < n + q; i++)
                if (evs[i].type == 0)
                    evs[i].p.x = -evs[i].p.x;
            sort(evs, evs + (n + q));
            for (int i = 0; i < q + n; i++)
            {
                if (i > 0)
                    add += evs[i].p.x - evs[i - 1].p.x;
                if (evs[i].type == 0)
                {
                    s.insert(make_pair(evs[i].p.y - add, evs[i].i));
                    if (!mp.count(evs[i].p.x - evs[i].p.y))
                        mp[evs[i].p.x - evs[i].p.y] = evs[i].i;
                }
                else if (mp.count(evs[i].p.x - evs[i].p.y))
                {
                    rans[evs[i].i] = -pts[mp[evs[i].p.x - evs[i].p.y]].x;
                }
                else
                {
                    auto it = s.upper_bound(make_pair(evs[i].p.y - add, -1));
                    it--;
                    rans[evs[i].i] = -pts[(it->second)].x;
                }
            }
            for (int i = 0; i < q; i++)
            {
                cout << (int)lans[i] << " " << (int)rans[i] << endl;
            }
        }
        else
        {
            int_type* lans = new int_type[q];
            int_type* rans = new int_type[q];
            query* qs = new query[q];
            for (int i = 0; i < q; i++)
            {
                ll x, y;
                cin >> x >> y;
                qs[i].p.x = x;
                qs[i].p.y = y;
                qs[i].i = i;
            }
            sort(qs, qs + q);

            int i = 0;
            while (pts[i].x < qs[0].p.x) i++;
            if (pts[i].x != qs[0].p.x)
                i--;
            while (i > 0 && cp(vect(qs[0].p, pts[i]), vect(qs[0].p, pts[i - 1])) <= 0)
                i--;
            lans[qs[0].i] = pts[i].x;
            for (int j = 0; j < q; j++)
            {
                while (i > 0 && cp(vect(qs[j].p, pts[i]), vect(qs[j].p, pts[i - 1])) <= 0)
                    i--;
                lans[qs[j].i] = pts[i].x;
            }

            int j = 0;
            while (pts[j].x < qs[0].p.x) j++;
            while (j < n && cp(vect(qs[0].p, pts[j]), vect(qs[0].p, pts[j + 1])) >= 0)
                j++;
            rans[qs[0].i] = pts[j].x;
            for (i = 1; i < q; i++)
            {
                while (j < n && cp(vect(qs[i].p, pts[j]), vect(qs[i].p, pts[j + 1])) >= 0)
                    j++;
                rans[qs[i].i] = pts[j].x;   
            }

            for (i = 0; i < q; i++)
                cout << (int)lans[i] << " " << (int)rans[i] << endl;
        }
    }
    return 0;
}
