#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn = 4e5 + 10;

const double inf = 1e18, eps = 1e-9;

struct point{
    double x, y;
};

double dot_product(point a, point b){
    return a.x * b.x + a.y * b.y;
}

double cross_product(point a, point b){
    return a.x * b.y - a.y * b.x;
}

double ang(point a, point b){
    return atan2(cross_product(a, b), dot_product(a, b));
}

point make_point(double X, double Y){
    point ret;
    ret.x = X;
    ret.y = Y;
    return ret;
}

int n, zap;

struct seg_tree{
    double val;
    int i;
};

seg_tree q[maxn * 4];

point def = make_point(1, 0);

point a[maxn];

void build(int v, int l, int r){
    if (l == r){
        q[v].i = l;
        q[v].val = ang(def, a[l]);
        return;
    }
    int m = (l + r) / 2;
    build(2 * v, l, m);
    build(2 * v + 1, m + 1, r);
    if (q[2 * v].val > q[2 * v + 1].val)
        q[v] = q[2 * v];
    else
        q[v] = q[2 * v + 1];
}

pair<double, int> mx(int v, int tl, int tr, int l, int r){
    if (l > r)
        return make_pair(-inf, -1);
    if (tl == l && tr == r)
        return make_pair(q[v].val, q[v].i);
    int m = (tl + tr) / 2;
    pair<double, int> a = mx(2 * v, tl, m, l, min(r, m)), b = mx(2 * v + 1, m + 1, tr, max(l, m + 1), r);
    if (a.first > b.first)
        return a;
    return b;
}

struct line{
    ll a, b, c;
};

line make_line(int A, int B, int C){
    line ret;
    ret.a = A;
    ret.b = B;
    ret.c = C;
    return ret;
}

line make_line(point a, point b){
    line ret;
    ret.a = a.y - b.y;
    ret.b = b.x - a.x;
    ret.c = -ret.a * a.x - ret.b * a.y;
    return ret;
}

pair<int, int> y[maxn];

int xv;

pair<ll, ll> p[maxn];

pair<ll, ll> answer[maxn];

int main()
{
    ifstream cin("mountain.in");
    ofstream cout("mountain.out");
    ios::sync_with_stdio(0);
    cin >> n >> zap;
    a[0] = make_point(0, 0);
    for (int i = 1; i <= n; i++){
        int d, k;
        cin >> d >> k;
        a[i] = make_point(a[i - 1].x + d, a[i - 1].y + k * d);
    }
    if (n <= 3e3){
        for (int iter = 0; iter < zap; iter++){
            double xv, yv;
            cin >> xv >> yv;
            int l = 0, r = n + 1;
            while (r - l > 1){
                int m = (l + r) / 2;
                if (a[m].x <= xv)
                    l = m;
                else
                    r = m;
            }
            int ind = l;
            pair<ll, ll> ans = make_pair(inf, -inf);
            for (int i = ind - 1; i >= 0; i--){
                line nw = make_line(a[i], a[i + 1]);
                double yn = -(nw.c + nw.a * xv) / nw.b;
                if (yn - yv > eps){
                    ans.first = a[i + 1].x;
                    break;
                }
            }
            if (ans.first == inf)
                ans.first = a[0].x;
            for (int i = ind + 1; i < n; i++){
                line nw = make_line(a[i], a[i + 1]);
                double yn = -(nw.c + nw.a * xv) / nw.b;
                if (yn - yv > eps){
                    ans.second = a[i].x;
                    break;
                }
            }
            if (ans.second == -inf)
                ans.second = a[n].x;
            cout << ans.first << ' ' << ans.second << '\n';
        }
        return 0;
    }
    for (int i = 0; i < zap; i++)
        cin >> xv >> y[i].first, y[i].second = i;
    sort(y, y + zap);
    int l = 0, r = n + 1;
    while (r - l > 1){
        int m = (l + r) / 2;
        if (a[m].x <= xv)
            l = m;
        else
            r = m;
    }
    int ind = l;
    int len = 0;
    p[0].first = a[ind].x;
    for (int i = ind - 1; i >= 0; i--){
        line nw = make_line(a[i], a[i + 1]);
        double yn = -(nw.c + nw.a * xv) / nw.b;
        l = len - 1, r = zap;
        while (r - l > 1){
            int m = (l + r) / 2;
            if ((double)y[m].first - yn >= -eps)
                r = m;
            else
                l = m;
        }
        len = r;
        p[len].first = a[i].x;
    }
    len = 0;
    p[0].second = a[ind + 1].x;
    for (int i = ind + 1; i < n; i++){
        line nw = make_line(a[i], a[i + 1]);
        double yn = -(nw.c + nw.a * xv) / nw.b;
        l = len - 1, r = zap;
        while (r - l > 1){
            int m = (l + r) / 2;
            if (y[m].first - yn >= -eps)
                r = m;
            else
                l = m;
        }
        len = r;
        p[len].second = a[i + 1].x;
    }
    ll now = inf;
    for (int i = 0; i < zap; i++)
        now = min(now, p[i].first), answer[y[i].second].first = now;
    now = -inf;
    for (int i = 0; i < zap; i++)
        now = max(now, p[i].second), answer[y[i].second].second = now;
    for (int i = 0; i < zap; i++)
        cout << answer[i].first << ' ' << answer[i].second << '\n';
}
