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

using namespace std;

struct Point
{
    long long x;
    long long y;
    long long no;
    long long prevk = -1000000000000000000;
    long long nextk = 1000000000000000000;
    long long closestL;
    long long closestR;
    Point(long long a, long long b)
    {
        x = a;
        y = b;
    }
};

vector<Point> points;

vector<Point> tops;

bool byx(Point a, Point b)
{
    return a.x < b.x;
}

bool byy(Point a, Point b)
{
    return a.y < b.y;
}

bool byno(Point a, Point b)
{
    return a.no < b.no;
}

bool bydiff(Point a, Point b)
{
    return a.x - a.y <= b.x - b.y;
}

bool bysum(Point a, Point b)
{
    return a.x + a.y < b.x + b.y;
}

int main()
{
    freopen("mountain.in", "r", stdin);
    freopen("mountain.out", "w", stdout);
    int n, q;
    cin >> n >> q;
    points.push_back(Point(0, 0));
    points[0].no = 0;
    bool SUB_4_OPTIMIZATION = true;
    for (int i = 0; i < n; i++)
    {
        long long xpr, k;
        cin >> xpr >> k;
        if (SUB_4_OPTIMIZATION && k != 1 && k != -1)
        {
            SUB_4_OPTIMIZATION = false;
        }
        points[i].nextk = k;
        points.push_back(Point(points[i].x + xpr, points[i].y + xpr * k));
        points[i + 1].prevk = k;
        points[i + 1].no = i + 1;
    }
    int firsttx = -1;
    bool SUB_5_OPTIMIZATION = true;
    for (int tow = 0; tow < q; tow++)
    {
        long long topx, topy;
        cin >> topx >> topy;
        if (firsttx == -1)
        {
            firsttx = topx;
        }
        else if (firsttx != topx)
        {
            SUB_5_OPTIMIZATION = false;
        }
        tops.push_back(Point(topx, topy));
        tops[tow].no = tow;
    }
    long long closestL = -1;
    long long closestR = -1;
    if (SUB_5_OPTIMIZATION)
    {
        sort(tops.begin(), tops.end(), byy);
    }
    for (int i = 0; i < q; i++)
    {
        if (!SUB_5_OPTIMIZATION || closestL == -1 || SUB_4_OPTIMIZATION)
        {
            if (SUB_4_OPTIMIZATION)
            {
                tops[i].closestL = lower_bound(points.begin(), points.end(), Point(tops[i].x, tops[i].y), bydiff)->no;
                tops[i].closestL = max(0LL, tops[i].closestL - 1);
                tops[i].closestR = upper_bound(points.begin(), points.end(), Point(tops[i].x, tops[i].y), bysum)->no;
                if (points[0].x - points[0].y >= tops[i].x - tops[i].y)
                {
                    tops[i].closestL = 0LL;
                }
                if (points[n].x + points[n].y <= tops[i].x + tops[i].y)
                {
                    tops[i].closestR = n;
                }
                continue;
            }
            else
            {
                closestL = lower_bound(points.begin(), points.end(), Point(tops[i].x, tops[i].y), byx)->no;
                if (points[closestL].x > tops[i].x)
                {
                    closestL--;
                }
                closestR = lower_bound(points.begin(), points.end(), Point(tops[i].x, tops[i].y), byx)->no;
            }
            closestL = lower_bound(points.begin(), points.end(), Point(tops[i].x, tops[i].y), byx)->no;
            if (points[closestL].x > tops[i].x)
            {
                closestL--;
            }
            closestR = lower_bound(points.begin(), points.end(), Point(tops[i].x, tops[i].y), byx)->no;
        }
        bool going = true;
        while (going && closestL > 0)
        {
            if (SUB_4_OPTIMIZATION)
            {
                if ((points[closestL].prevk < 0) || (tops[i].x - points[closestL].x <= tops[i].y - points[closestL].y))
                {
                    closestL--;
                }
                else
                {
                    going = false;
                }
            }
            else
            {
                if (points[closestL].prevk * (tops[i].x - points[closestL].x) <= tops[i].y - points[closestL].y)
                {
                    closestL--;
                }
                else
                {
                    going = false;
                }
            }
        }
        going = true;
        while (going && closestR < n)
        {
            if (SUB_4_OPTIMIZATION)
            {
                if ((points[closestR].nextk > 0) || ((points[closestR].x - tops[i].x) <= tops[i].y - points[closestR].y))
                {
                    closestR++;
                }
                else
                {
                    going = false;
                }
            }
            else
            {
                if (points[closestR].nextk * (tops[i].x - points[closestR].x) <= tops[i].y - points[closestR].y)
                {
                    closestR++;
                }
                else
                {
                    going = false;
                }
            }
        }
        tops[i].closestL = closestL;
        tops[i].closestR = closestR;
    }

    if (SUB_5_OPTIMIZATION)
    {
        sort(tops.begin(), tops.end(), byno);
    }
    for (int i = 0; i < tops.size(); i++)
    {
        cout << points[tops[i].closestL].x << " " << points[tops[i].closestR].x << endl;
    }
    return 0;
}
