#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>

#define rep(i, n) for (decltype(n) i = 0; i < n; i++)
#define dep(i, n) for (decltype(n) i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (decltype(b) i = a; i <= b; i++)
#define FORD(i, a, b) for (decltype(a) i = a; i >= b; i--)
#define len(a) (int)a.size()
#define all(a) a.begin(), a.end()
typedef long long int64;
typedef long double ld;
using namespace std;

const int maxn = 5e5 + 10;
const ld eps = 1e-8;
struct pt
{
	ld x, y;
};
struct line
{
	ld a, b, c;
	line(const pt &s, const pt &t)
	{
		a = t.y - s.y;
		b = s.x - t.x;
		c = -(a * s.x + b * s.y);
	}
	ld y(ld x)
	{
		return -(c + a * x) / b;
	}
};
struct seg
{
	pt a, b;
};
vector<seg> s;
ld d[maxn], k[maxn];

bool check(const pt &a, const pt &b)
{
	line l = line(a, b);
	for (auto &x : s)
	{
		if (x.a.x >= min(a.x, b.x) && x.a.x <= max(a.x, b.x) && x.a.y > l.y(x.a.x) || x.b.x >= min(a.x, b.x) && x.b.x <= max(a.x, b.x) && x.b.y > l.y(x.b.x))
			return true;
	}
	return false;
}

int main()
{
//	freopen("fisher.in", "r", stdin);
//	freopen("fisher.out", "w", stdout);
	int n, q;
	cin >> n >> q;
	pt p = { 0, 0 };
	rep(i, n)
	{
		cin >> d[i] >> k[i];
		s.push_back({ p, {p.x += d[i], p.y += k[i] * d[i]} });
	}
	if (n <= 3000 && q <= 3000)
	{
		rep(i, q)
		{
			pt cur;
			cin >> cur.x >> cur.y;
			int l = 0, r = len(s);
			while (r > l + 1)
			{
				int m = (l + r) >> 1;
				if (cur.x >= s[m].a.x)
					l = m;
				else
					r = m;
			}
			int idx = l;
			ld rans = s.back().b.x;
			FOR(x, idx + 1, len(s) - 1)
			{
				if (check(cur, s[x].a))
				{
					rans = s[x].a.x;
					break;
				}
				else if (check(cur, s[x].b))
				{
					line L = line(s[x].a, s[x].b);
					ld l = s[x].a.x, r = s[x].b.x;
					rep(i, 500)
					{
						ld m = (l + r) / 2;
						if (check(cur, { m, L.y(m) }))
							r = m;
						else
							l = m;
					}
					rans = r;
					break;
				}
			}
			ld lans = 0;
			FORD(x, idx - 1, 0)
			{
				if (check(cur, s[x].b))
				{
					lans = s[x].b.x;
					break;
				}
				else if (check(cur, s[x].a))
				{
					line L = line(s[x].a, s[x].b);
					ld l = s[x].a.x, r = s[x].b.x;
					rep(i, 500)
					{
						ld m = (l + r) / 2;
						if (check(cur, { m, L.y(m) }))
							l = m;
						else
							r = m;
					}
					lans = l;
					break;
				}
			}
			cout << (int64)round(lans) << ' ' << (int64)round(rans) << endl;
		}
	}
	return 0;
}