#define EJUDGE

#include "testlib.h"
#include <vector>
#include <algorithm>

using namespace std;

struct MinTree {
private:
	int kk;
	vector <int> tree;
	void update(int t)
	{
		tree[t] = min(tree[2 * t], tree[2 * t + 1]);
	}
public:
	static const int INF = 1 << 30;

	MinTree (int size)
	{
		size += 10;
		kk = 1;
		while (kk < size)
			kk *= 2;

		tree = vector<int>(kk * 2, INF);
	}
	void modify(int t, int value)
	{
		t += kk;
		tree[t] = value;
		while (t > 1)
		{
			t /= 2;
			update(t);
		}
	}
	int getMin(int l, int r)
	{
		int ans = INF;
		l += kk;
		r += kk;
		while (l <= r)
		{
			if (l % 2 == 1)
			{
				ans = min(ans, tree[l]);
				++l;
			}
			if (r % 2 == 0)
			{
				ans = min(ans, tree[r]);
				--r;
			}
			l /= 2;
			r /= 2;
		}
		return ans;
	}
};

struct Segment {
	int l, r;

	Segment(int _l, int _r) : l(_l), r(_r) {}

	bool operator <= (const Segment & s) const
	{
		return s.l <= l && r <= s.r;
	}
};

int n;
std::vector <Segment> seg;

struct Event {
	bool open;
	int num;
	int x;

	Event (bool _open, int _num, int _x) : open(_open), num(_num), x(_x) {}

	bool operator < (const Event & e) const
	{
		if (x != e.x)
			return x < e.x;

		if (open != e.open)
			return open > e.open;

		if (open)
			return seg[num].r > seg[e.num].r;
		else
			return seg[num].l > seg[e.num].l;
	}

	void print()
	{
		printf("x = %d num = %d open = %d\n", x, num, int(open));
	}
};

const int N = 128 * 1024;

int pans[N], jans[N];
bool pCorrect[N];

struct Answer {
	int * ans;
	bool * correct;

	Answer(int * ans, bool * correct)
	{
		this -> ans = ans;
		this -> correct = correct;
	}

	int getAns(int num)
	{
		return ans[num];
	}

	void setCorrect(int num, bool value)
	{
		correct[num] = value;
	}
};

struct List {
private:
	struct ListElement {
		int num;
		int prev, next;
	};


	vector <ListElement> list;
	int used;
	int fake;
	vector <int> numInList;

public:

	List (int size)
	{
		++size;
		list.resize(size);
		numInList.resize(size);

		used = 0;
		fake = used++;

		list[fake].next = list[fake].prev = fake;
	}

	void insertBehind(int next, int num)
	{
		int prev = list[next].prev;

		list[prev].next = num;
		list[next].prev = num;

		list[num].next = next;
		list[num].prev = prev;
	}

	void deleteElement(int num)
	{
		int prev = list[num].prev;
		int next = list[num].next;

		list[prev].next = next;
		list[next].prev = prev;
	}

	int newElement(int num)
	{
		int cur = used++;
		list[cur].num = num;
		numInList[num] = cur;
		list[cur].next = list[cur].prev = -1;
		return cur;
	}

	void insertAtEnd(int num)
	{
		insertBehind(fake, num);
	}

	int getPrev(int num) const
	{
		return list[num].prev;
	}

	int getNumInList(int num) const
	{
		return numInList[num];
	}

	int getFake() const
	{
		return fake;
	}
};

void solve()
{
	MinTree minTree(n);
	List list(n);

	vector <Answer> answers;
	answers.push_back(Answer(pans, pCorrect));

	vector <Event> events;

	for (int i = 0; i < n; ++i)
	{
		events.push_back(Event(true, i, seg[i].l));
		events.push_back(Event(false, i, seg[i].r));
	}

	sort(events.begin(), events.end());

	for (int i = 0; i < int(events.size()); ++i)
	{
		int num = events[i].num;

		if (events[i].open)
		{
			int curNum = list.newElement(num);
			minTree.modify(curNum, seg[num].r);
			list.insertAtEnd(curNum);
		}
		else
		{
			int cur, prev;
			cur = list.getNumInList(num);
			prev = list.getPrev(cur);

			for (int j = 0; j < int(answers.size()); ++j)
			{
				int ans = answers[j].getAns(num);

				if (prev == list.getFake())
					answers[j].setCorrect(num, ans == -1);
				else
				{
					if (ans == -1 || !(seg[num] <= seg[ans]) || ans == num)
						answers[j].setCorrect(num, false);
					else
					{
						int rightAns = seg[ans].r;
						int minRight = minTree.getMin(list.getNumInList(ans) + 1, cur - 1);

						answers[j].setCorrect(num, minRight > rightAns);
					}
				}
			}

			minTree.modify(cur, minTree.INF);
			list.deleteElement(cur);
		}
	}
}

void read()
{
	n = inf.readInt();

	seg.reserve(n);

	for (int i = 0; i < n; ++i)
	{
		int l = inf.readInt();
		int r = inf.readInt();

		seg.push_back(Segment(l, r));
	}

	for (int i = 0; i < n; ++i)
	{
		jans[i] = ans.readInt() - 1;
		pans[i] = ouf.readInt() - 1;

		if (jans[i] < -1 || jans[i] >= n)
			quitf(_fail, "ACHTUNG! Jury wrong! In line %d found: %d, but n = %d\n", i + 1, jans[i] + 1, n);

		if (pans[i] < -1 || pans[i] >= n)
			quitf(_wa, "In line %d found: %d, but n = %d\n", i + 1, pans[i] + 1, n);
	}
}

void write()
{
	for (int i = 0; i < n; ++i)
	{
		if (!pCorrect[i])
			quitf(_wa, "In line %d expected: %d, found: %d", i + 1, jans[i] + 1, pans[i] + 1);
	}

	quitf(_ok, "OK n = %d", n);
}

int main(int argc, char *argv[])
{
	registerTestlibCmd(argc, argv);

	read();
	solve();
	write();

	return 0;
}