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

using namespace std;

const int INF = 1000000001;

int main() {
	freopen("mountain.in", "r", stdin);
	freopen("mountain.out", "w", stdout);
	int n, q;
	cin >> n >> q;
	vector<int> lk;
	vector<int> rk;
	lk.push_back(-INF);
	rk.push_back(-INF);
	int b = 0;
	int h = 0;
	for (int i = 0; i < n; i++) {
		int a, k;
		cin >> a >> k;
		if (k == 1) { lk.push_back(b - h); h += a; }
		else { h -= a; rk.push_back(b + a + h); }
		b += a;
	}
	lk.push_back(INF);
	rk.push_back(INF);
	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		int l1 = x - y, r1 = x + y;
		int l = 0, r = lk.size() - 1;
		while (l != r) {
			int m = (l + r) / 2;
			if (lk[m] < l1) { l = m + 1; }
			else { r = m; }
		}
		int lans = (lk[l - 1] + rk[l - 1]) / 2;
		l = 0, r = rk.size() - 1;
		while (l != r) {
			int m = (l + r) / 2;
			if (rk[m] <= r1) { l = m + 1; }
			else { r = m; }
		}
		int rans = (rk[l] + lk[l]) / 2;
		if (lans < 0) { lans = 0; }
		if (lans > x) { lans = x; }
		if (rans > max(rk[rk.size() - 2], lk[lk.size() - 2])) { rans = max(rk[rk.size() - 2], lk[lk.size() - 2]); }
		if (rans < x) { rans = x; }
		cout << lans << ' ' << rans << '\n';
	}


	return 0;
}