#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>

using namespace std;

vector<int> x, y;

vector<pair<pair<int, int>, int> > s;

int ansl[100000], ansr[100000];

long long vect(long long a, long long b, int c, int d, int xx, int yy) {
    return (a - xx) * (d - yy) - (c - xx) * (b - yy);
}

int main() {
    freopen("mountain.in", "r", stdin);
    freopen("mountain.out", "w", stdout);
    int n, m;
    cin >> n >> m;
    x.push_back(0);
    y.push_back(0);
    for (int i = 0; i < n; i++) {
        int d, k;
        cin >> d >> k;
        x.push_back(x[i] + d);
        y.push_back(y[i] + d * k);
        //cout << x[i + 1] << ' ' << y[i + 1] << '\n';
    }
    if (m <= 3000) {
    for (int i = 0; i < m; i++) {
        long long a, b;
        cin >> a >> b;
        int t = 0;
        while (x[t] < a && t < n) {
            t++;
        }
        int l = max(0, t - 1);
        while (l > 0 && vect(a, b, x[l - 1], y[l - 1], x[l], y[l]) >= 0) {
            l--;
        }
        int r = t;
        while (r < n && vect(x[r + 1], y[r + 1], a, b, x[r], y[r]) >= 0) {
            r++;
        }
        cout << x[l] << ' ' << x[r] << '\n';
    }
    return 0;
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        s.push_back({{a, b}, i});
    }
    sort(s.begin(), s.end());
    if (s[0].first.first == s[1].first.first) {
        int j = 0;
        for (int i = n; i > 0; i--) {
            if (x[i] > s[0].first.first) {
                continue;
            }
            while (j < m && vect(s[j].first.first, s[j].first.second, x[i - 1], y[i - 1], x[i], y[i]) < 0) {
                ansl[s[j].second] = x[i];
                j++;
            }
            if (j == m) {
                break;
            }
        }
        while (j < m) {
            ansl[s[j].second] = 0;
            j++;
        }
        j = 0;
        for (int i = 0; i < n; i++) {
            if (x[i] < s[0].first.first) {
                continue;
            }
            while (j < m && vect(x[i + 1], y[i + 1], s[j].first.first, s[j].first.second, x[i], y[i]) < 0) {
                ansr[s[j].second] = x[i];
                j++;
            }
            if (j == m) {
                break;
            }
        }
        while (j < m) {
            ansr[s[j].second] = x[n];
            j++;
        }
    }
    else {
        int j = m - 1;
        for (int i = n; i > 0; i--) {
            if (x[i] > s[j].first.first) {
                continue;
            }
            //cout << i << ' ';
            while (j >= 0 && vect(s[j].first.first, s[j].first.second, x[i - 1], y[i - 1], x[i], y[i]) < 0) {
                //cout << s[j].second << ' ' << i << '\n';
                ansl[s[j].second] = x[i];
                j--;
            }
            if (j == -1) {
                break;
            }
        }
        while (j >= 0) {
            ansl[s[j].second] = 0;
            j--;
        }
        j = 0;
        for (int i = 0; i < n; i++) {
            if (x[i] < s[j].first.first) {
                continue;
            }
            while (j < m && vect(x[i + 1], y[i + 1], s[j].first.first, s[j].first.second, x[i], y[i]) < 0) {
                ansr[s[j].second] = x[i];
                j++;
            }
            if (j == m) {
                break;
            }
        }
        while (j < m) {
            ansr[s[j].second] = x[n];
            j++;
        }
    }
    for (int i = 0; i < m; i++) {
        cout << ansl[i] << ' ' << ansr[i] << '\n';
    }
}
