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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>

#define FOR(ii, ll, uu)  for(int ii##lim = (uu), ii = (ll); ii < ii##lim; ++ii)
#define REP(ii, nn) FOR(ii, 0, nn)

// from stackoverflow
#define getcx getchar_unlocked

inline int giu()
{
	int n = 0;
	int ch=getcx();
	while (ch < '0' || ch > '9')
	{
		ch = getcx();
	}
	while (ch >= '0' && ch <= '9')
		n = (n<<3)+(n<<1) + ch-'0', ch = getcx();
	return n;
}
#define GI (giu())

#include <algorithm>
using std::min;
using std::max;

int main()
{
	REP(t, GI)
	{
		int n = GI;
		int min_w = GI, max_w = GI, min_h = GI, max_h = GI;
		bool dominator = true;
		REP(i, n-1)
		{
			int w1 = GI, w2 = GI, h1 = GI, h2 = GI;
			if (w1 <= min_w && w2 >= max_w && h1 <= min_h && h2 >= max_h)
			{
				min_w = w1;
				max_w = w2;
				min_h = h1;
				max_h = h2;
				dominator = true;
				continue;
			}
			if (w1 >= min_w && w2 <= max_w && h1 >= min_h && h2 <= max_h)
				continue;
			dominator = false;
			min_w = min(w1, min_w);
			max_w = max(w2, max_w);
			min_h = min(h1, min_h);
			max_h = max(h2, max_h);
		}
		puts(dominator?"TAK":"NIE");
	}
	return 0;
}