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
64
65
66
67
68
69
70
#include <cstdio>
#include <algorithm>

using namespace std;

#define FOR(v,p,k) for(int v=p;v<=k;++v)
#define FORD(v,p,k) for(int v=p;v>=k;--v)
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(x) memset(x,0,sizeof(x))

typedef long long LL;
typedef unsigned long long ULL;

const int INF = 1000000000;

const int MAX = 100000;
int L[MAX][4];

int main(int argc, char **args)
{
	int t, n;

	scanf("%d", &t);

	REP(i, t)
	{
		scanf("%d", &n);

		int wMin = 1000000000;
		int wMax = 0;
		int hMin = 1000000000;
		int hMax = 0;

		int w1, w2, h1, h2;

		REP(j, n)
		{
			scanf("%d %d %d %d", &w1, &w2, &h1, &h2);

			wMin = min(wMin, w1);
			wMax = max(wMax, w2);
			hMin = min(hMin, h1);
			hMax = max(hMax, h2);

			L[j][0] = w1;
			L[j][1] = w2;
			L[j][2] = h1;
			L[j][3] = h2;
		}

		bool found = false;

		REP(j, n)
		{
			if (L[j][0] == wMin && L[j][1] == wMax && L[j][2] == hMin && L[j][3] == hMax)
			{
				found = true;
				break;
			}
		}

		if (found)
			printf("TAK\n");
		else
			printf("NIE\n");
	}

	return 0;
}