#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

int MODE = 0;

struct Point
{
	int ind;
	long long x, y;
	Point(long long x = 0, long long y = 0) : x(x), y(y) {}
	Point operator -(Point p)
	{
		return Point(x - p.x, y - p.y);
	}
	long long operator %(Point p)
	{
		return x * p.y - p.x * y;
	}
	bool operator <(Point p)
	{
		if (MODE == 0)
		{
			if (x == p.x)
				return y < p.y;
			return x < p.x;
		}
		if (MODE == 1)
			return p.y - y < p.x - x;
		if (MODE == 2)
			return p.y - y > p.x - x;
	}
};

vector<Point> arr;
vector<Point> qs;
vector<Point> ans;

int main()
{
	ifstream fin("mountain.in");
	ofstream fout("mountain.out");
	long long n, q;
	fin >> n >> q;
	Point cur;
	arr.push_back(cur);

	bool K1 = true;

	int lk = 0;

	for (int i = 0; i < n; i++)
	{
		long long d, k;
		fin >> d >> k;
		cur.x += d;
		cur.y += k * d;
		if (k != -1 && k != 1)
			K1 = false;
		if (i > 0 && k == lk)
		{
			arr[i] = cur;
			i--;
			n--;
		}
		else
			arr.push_back(cur);
		lk = k;
	}


	for (int i = 0; i < q; i++)
	{
		Point Pnt;
		Pnt.ind = i;
		fin >> Pnt.x >> Pnt.y;
		qs.push_back(Pnt);
	}
	bool Equal = true;
	for (int i = 1; i < qs.size(); i++)
		if (qs[i - 1].x != qs[i].x)
			Equal = false;

	if (Equal)
	{
		ans.resize(q);
		int stl, str;
		sort(qs.begin(), qs.end());
		int pos = lower_bound(arr.begin(), arr.end(), qs[0].x) - arr.begin();
		if (arr[pos].x == qs[0].x)
			stl = str = pos;
		else
		{
			str = pos;
			stl = pos - 1;
		}
		for (Point Pnt : qs)
		{
			for (; str < arr.size(); str++)
			{
				if (str == arr.size() - 1)
					break;
				if ((arr[str] - Pnt) % ((arr[str + 1] - Pnt)) < 0)
					break;
			}
			for (; stl > 0; stl--)
			{
				if (stl == 0)
					break;
				if ((arr[stl - 1] - Pnt) % ((arr[stl] - Pnt)) < 0)
					break;
			}
			ans[Pnt.ind] = Point(arr[stl].x, arr[str].x);
		}
		for (Point p : ans)
			fout << p.x << " " << p.y << endl;
		return 0;
	}



	for (Point Pnt : qs)
	{
		if (K1)
		{
			int stl, str;
			MODE = 1;
			stl = lower_bound(arr.begin(), arr.end(), Pnt) - arr.begin();
			if (stl == 0)
				fout << arr[0].x << " ";
			else
				fout << arr[stl - 1].x << " ";
			MODE = 2;
			str = lower_bound(arr.begin(), arr.end(), Pnt) - arr.begin();
			if (str == n - 1)
				fout << arr[n - 1].x << " ";
			else
				fout << arr[str + 1].x << " ";
		}
		else
		{
			int stl, str;
			int pos = lower_bound(arr.begin(), arr.end(), Pnt) - arr.begin();
			if (arr[pos].x == Pnt.x)
				stl = str = pos;
			else
			{
				str = pos;
				stl = pos - 1;
			}
			for (; str < arr.size(); str++)
			{
				if (str == arr.size() - 1)
					break;
				if ((arr[str] - Pnt) % ((arr[str + 1] - Pnt)) < 0)
					break;
			}
			for (; stl > 0; stl--)
			{
				if (stl == 0)
					break;
				if ((arr[stl - 1] - Pnt) % ((arr[stl] - Pnt)) < 0)
					break;
			}
			fout << arr[stl].x << " " << arr[str].x << endl;
		}
	}
	return 0;
}
