/* D_Mountain */

#pragma comment(linker, "/STACK:268435456")

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

using namespace std;

#define FOR(i, s, f) for (int i = (s); i < (f); ++i)
#define ROF(i, f, s) for (int i = (f) - 1; i >= (s); --i)
#define forn(i, f) for (int i = 0; i < (f); ++i)
#define rofn(i, f) for (int i = (f) - 1; i >= 0; --i)
#define forit(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())

typedef long long ll;
typedef long double ld;
typedef const int cint;
typedef const ll cll;
#define vi vector < int >
#define pll pair < ll, ll >

#define TASK "mountain"

cint N = 4e5 + 3;

ll d[N], k[N];
ll x[N], y[N];

struct coords
{
	int u, v, id;

	coords(ll a, ll b, int c = 0) : u(a), v(b), id(c) {}

	coords() {}

	bool operator < (coords a) const
	{
		return v < a.v;
	}
};

bool cmp(const coords a, const coords b)
{
	return a.u < b.u;
}

coords ask[N];
coords answers[N];

int n, q;

pll find_ans(ll u, ll v);

int main()
{
	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);

	cin >> n >> q;

	bool group_4 = true;

	x[0] = y[0] = 0;
	FOR(i, 1, n + 1)
	{
		cin >> d[i] >> k[i];
		x[i] = x[i - 1] + d[i];
		y[i] = y[i - 1] + k[i] * d[i];

		if (!(k[i] == 1 || k[i] == -1))
			group_4 = false;
	}

	bool group_5 = true;
	forn(i, q)
	{
		ll u, v;
		cin >> u >> v;

		ask[i] = coords(u, v, i);

		if (i > 0)
		{
			if (ask[i - 1].u != u)
				group_5 = false;
		}
	}


	if (group_5)
	{
		sort(ask, ask + q);

		ll u = ask[0].u;

		ll l, r;

		FOR(i, 0, n)
		{
			if (x[i] <= u && u <= x[i + 1])
			{
				l = i;
				r = i + 1;
				break;
			}
		}
		++r;

		forn(tt, q)
		{
			ll v = ask[tt].v;
			
			for (; l >= 1; --l)
			{
				if (!(k[l] * (u - x[l - 1]) <= (v - y[l - 1])))
					break;
			}

			for (; r <= n; ++r)
			{
				if (!(k[r] * (x[r] - u) >= (y[r] - v)))
					break;
			}


			answers[ask[tt].id] = coords(x[l], x[r - 1], ask[tt].id);
		}

		forn(i, q)
			cout << answers[i].u << ' ' << answers[i].v << endl;
	}
/*	else if (group_4)
	{
		sort(ask, ask + q, cmp);

		ll v = ask[0].v;
		ll u = ask[0].u;

		pll ret = find_ans(u, v);
		ll l = ret.first;
		ll r = ret.second;

		forn(tt, q)
		{
			u = ask[tt].u;

			for (; r <= n; ++r)
			{
				if (x[r] <= u)
					continue;
				if (!(k[r] * (x[r] - u) >= (y[r] - v)))
					break;
			}

			answers[ask[tt].id].v = x[r - 1];// = coords(x[l], x[r - 1], ask[tt].id);
		}

		ret = find_ans(ask[q - 1].u, ask[q - 1].v);
		l = ret.first;
		r = ret.second;
		++r;

		rofn(tt, q)
		{
			u = ask[tt].u;

			for (; l >= 1; --l)
			{
				if (x[l] >= u)
					continue;
				if (!(k[l] * (u - x[l - 1]) <= (v - y[l - 1])))
					break;
			}

			answers[ask[tt].id].u = x[l];
		}

		forn(i, q)
			cout << answers[i].u << ' ' << answers[i].v << endl;
	}*/
	else
	{
		forn(tt, q)
		{
			ll u, v;
			u = ask[tt].u;
			v = ask[tt].v;

			pll ret = find_ans(u, v);
			ll l = ret.first, r = ret.second;

			cout << x[l] << ' ' << x[r - 1] << endl;
		}
	}

	fclose(stdin);
	fclose(stdout);
	return 0;
}

pll find_ans(ll u, ll v)
{
	ll l, r;

	FOR(i, 0, n)
	{
		if (x[i] <= u && u <= x[i + 1])
		{
			l = i;
			r = i + 1;
			break;
		}
	}

	for (; l >= 1; --l)
	{
		if (!(k[l] * (u - x[l - 1]) <= (v - y[l - 1])))
			break;
	}

	++r;
	for (; r <= n; ++r)
	{
		if (!(k[r] * (x[r] - u) >= (y[r] - v)))
			break;
	}

	return pll(l, r);
}
