#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <stdio.h>
#include <list>
#include <algorithm>
#pragma warning(disable: 4996)
typedef long long ll;
typedef long double ld;
using namespace std;

const ll SZ = 1e3 + 10;
const ll INF = 1e9;

map<ll, ll> a; // { x, y }
vector<pair<pair<ll, ll>, ll>> rq;
map<ll, vector<ll>> da, db;
vector<pair<ll, ll>> rd, rrd;

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
	srand(753424635);
	ios::sync_with_stdio(false);

	bool g4 = true;
	ll n, q;
	cin >> n >> q;
	ll x = 0, y = 0;
	for (ll i = 0; i < n; i++) {
		ll d, k;
		cin >> d >> k;
		if (k != -1 && k != 1)
			g4 = false;
		rd.push_back({ d, k });
	}

	if (g4) {
		da[0].push_back(0);
		db[0].push_back(0);
		for (auto i : rd)
			if (!rrd.size() || rrd.back().second != i.second)
				rrd.push_back(i);
			else
				rrd.back().first++;
		for (auto i : rrd) {
			ll d = i.first, k = i.second;
			x += d;
			y += d * k;
			da[x + y].push_back(x);
			db[x - y].push_back(x);
		}
		ll s = x;

		while (q--) {
			ll x, y;
			cin >> x >> y;
			auto e = db.lower_bound(x - y);
			cout << (e == db.begin() ? 0 : (--e)->second.back()) << " ";
			e = da.upper_bound(x + y);
			cout << (e == da.end() ? s : e->second.front()) << "\n";
		}

		return 0;
	}

	for (auto i : rd) {
		ll d = i.first, k = i.second;
		x += d;
		y += d * k;
		a[x] = y;
	}
	a[0] = 0;

	for (ll i = 0; i < q; i++) {
		ll x, y;
		cin >> x >> y;
		rq.push_back({ { x, y }, i });
	}
	bool g5 = true; ll z = rq[0].first.first;
	for (auto i : rq)
		if (z != i.first.first)
			g5 = false;

	if (g5) {
		sort(rq.begin(), rq.end());
		vector<pair<ll, pair<ll, ll>>> pr;

		auto e = a.lower_bound(rq[0].first.first);
		auto f = a.upper_bound(rq[0].first.first);
		f--;

		for (auto i : rq) {
			x = i.first.first;
			y = i.first.second;
			ll xlast = e->first, ylast = e->second;
			while (true) {
				e++;
				if (e == a.end()) {
					e--;
					break;
				}
				if (e->first * ylast - e->second * xlast + xlast * y - ylast * x + x * e->second - y * e->first > 0) {
					e--;
					break;
				}
				xlast = e->first, ylast = e->second;
			}

			xlast = f->first, ylast = f->second;
			while (true) {
				if (f == a.begin())
					break;
				f--;
				if (f->first * ylast - f->second * xlast + xlast * y - ylast * x + x * f->second - y * f->first < 0) {
					f++;
					break;
				}
				xlast = f->first, ylast = f->second;
			}
			pr.push_back({ i.second,{ f->first, e->first } });
		}

		sort(pr.begin(), pr.end());
		for (auto i : pr)
			cout << i.second.first << " " << i.second.second << "\n";

		return 0;
	}

	for (auto i : rq) {
		pair<ll, ll> ans;
		ll x = i.first.first, y = i.first.second;
		auto e = a.lower_bound(x);
		ll xlast = e->first, ylast = e->second;
		while (true) {
			e++;
			if (e == a.end())
				break;
			if (e->first * ylast - e->second * xlast + xlast * y - ylast * x + x * e->second - y * e->first > 0)
				break;
			xlast = e->first, ylast = e->second;
		}
		ans.second = xlast;

		e = a.upper_bound(x);
		e--;
		xlast = e->first, ylast = e->second;
		while (true) {
			if (e == a.begin())
				break;
			e--;
			if (e->first * ylast - e->second * xlast + xlast * y - ylast * x + x * e->second - y * e->first < 0)
				break;
			xlast = e->first, ylast = e->second;
		}
		ans.first = xlast;

		cout << ans.first << " " << ans.second << "\n";
	}

	return 0;
}