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
58
59
60
61
62
63
#include <cstdio>
#include <vector>
#include <algorithm>

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define MP make_pair
#define FI first
#define SE second
#define PII pair<int, int>
#define PB push_back

using namespace std;

struct Mirror
{
	int ws, we, hs, he;
};

int t;
int n;
vector<Mirror> m;

int main()
{
	scanf("%d", &t);
	REP(tt, t)
	{
		scanf("%d", &n);
		m.clear();
		Mirror minmax;
		minmax.ws = 1000*1000*1000 + 1;
		minmax.we = 0;
		minmax.hs = 1000*1000*1000 + 1;
		minmax.he = 0;
		REP(i, n)
		{
			Mirror mirror;
			scanf("%d%d%d%d", &mirror.ws, &mirror.we, &mirror.hs, &mirror.he);
			if (mirror.ws < minmax.ws)
				minmax.ws = mirror.ws;
			if (mirror.we > minmax.we)
				minmax.we = mirror.we;
			if (mirror.hs < minmax.hs)
				minmax.hs = mirror.hs;
			if (mirror.he > minmax.he)
				minmax.he = mirror.he;
			m.PB(mirror);
		}
		bool result = false;
		REP(i, n)
			if (m[i].ws == minmax.ws
				&& m[i].we == minmax.we
				&& m[i].hs == minmax.hs
				&& m[i].he == minmax.he)
			{
				result = true;
				break;
			}
		printf("%s\n", result ? "TAK" : "NIE");
	}
	return 0;
}