#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;

#pragma warning (disable:4996)

#define ll long long int
#define mlp make_pair
#define x1 first
#define y1 second
#define point pair<double,double>

int n, q;
point a[400007];

pair<ll, ll> anss[100007];
vector<pair<ll, ll> > v;

double orpl(point x, point y) {
	return x.x1*y.y1 - x.y1*y.x1;
}

void sol() {
	int i, j, d, k;
	point b;
	cin >> n >> q;
	a[0].x1 = 0;
	a[0].y1 = 0;
	for (i = 0; i < n; i++) {
		cin >> d >> k;
		a[i + 1].x1 = a[i].x1 + d;
		a[i + 1].y1 = a[i].y1 + (double)d*k;
	}
	n++;
	if (n > 3000 || q > 3000) {

		pair<int, int> qq;
		for (i = 0; i < q; i++) {
			cin >> b.x1 >> b.y1;
			v.push_back(mlp((int)b.y1, i));
		}
		sort(v.begin(), v.end());
		for (i = 0; i < q; i++) {
			b.y1 = v[i].x1;
			int ind = 0, l, r;
			pair<ll, ll> ans;
			if (i == 0) {
				for (j = 0; j < n; j++) {
					if (a[j].x1 < b.x1)ind = j;
				}
			}
			if (i == 0) {
				l = ind;
				r = ind + 1;
			}
			else {
				l = qq.x1;
				r = qq.y1;
			}
			for (j = l; j >= 0; j -= 1) {
				if (j != l) {
					if (orpl(a[j], a[j + 1]) + orpl(a[j + 1], b) + orpl(b, a[j]) >= 0) {
						anss[v[i].y1].x1 = min(anss[v[i].y1].x1, (ll)a[j].x1);
						qq.x1 = j;
					}
					else {
						j = -1e9;
					}
				}
				else {
					anss[v[i].y1].x1 = a[j].x1;
					qq.x1 = j;
				}
			}
			for (j = r; j < n; j++) {
				if (j != r) {
					if (orpl(a[j], a[j - 1]) + orpl(a[j - 1], b) + orpl(b, a[j]) <= 0) {
						anss[v[i].y1].y1 = max(anss[v[i].y1].y1, (ll)a[j].x1);
						qq.y1 = j;
					}
					else {
						j = 1e9;
					}
				}
				else {
					anss[v[i].y1].y1 = a[j].x1;
					qq.y1 = j;
				}
			}
		}
		for (i = 0; i < q; i++) {
			cout << anss[i].x1 << " " << anss[i].y1 << endl;
		}
		return;
	}
	for (i = 0; i < q; i++) {
		cin >> b.x1 >> b.y1;
		int ind = 0;
		pair<ll, ll> ans;
		for (j = 0; j < n; j++) {
			if (a[j].x1 < b.x1)ind = j;
		}
		for (j = ind; j >= 0; j -= 1) {
			if (j != ind) {
				if (orpl(a[j], a[j + 1]) + orpl(a[j + 1], b) + orpl(b, a[j]) >= 0) {
					ans.x1 = min(ans.x1, (ll)a[j].x1);
				}
				else {
					j = -1e9;
				}
			}
			else {
				ans.x1 = a[j].x1;
			}
		}
		for (j = ind + 1; j < n; j++) {
			if (j != ind + 1) {
				if (orpl(a[j], a[j - 1]) + orpl(a[j - 1], b) + orpl(b, a[j]) <= 0) {
					ans.y1 = max(ans.y1, (ll)a[j].x1);
				}
				else {
					j = 1e9;
				}
			}
			else {
				ans.y1 = a[j].x1;
			}
		}
		cout << ans.x1 << " " << ans.y1 << endl;
	}
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	freopen("mountain.in", "r", stdin);
	freopen("mountain.out", "w", stdout);
#endif

	sol();
	return 0;
}