1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>

using namespace std;

int main(void)
{
	cin.sync_with_stdio(false);
	unsigned int t, n, w1, w2, h1, h2, bw1, bw2, bh1, bh2;
	bool f;
	for (cin >> t; t > 0; --t)
	{
		f = false;
		bh1 = bw1 = 0xffffffff;
		bh2 = bw2 = 0;
		for (cin >> n; n > 0; --n)
		{
			cin >> w1;
			cin >> w2;
			cin >> h1;
			cin >> h2;
			if (w1 <= bw1 && w2 >= bw2 && h1 <= bh1 && h2 >= bh2) f = true;
			else if (w1 < bw1 || w2 > bw2 || h1 < bh1 || h2 > bh2) f = false;
			bw1 = w1 < bw1 ? w1 : bw1;
			bw2 = w2 > bw2 ? w2 : bw2;
			bh1 = h1 < bh1 ? h1 : bh1;
			bh2 = h2 > bh2 ? h2 : bh2;
		}
		cout << (f ? "TAK" : "NIE") << endl;
	}
}