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
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define MP make_pair
#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 VAR(v,i) __typeof(i) v=(i)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define PB push_back
#define ST first
#define ND second
#define SIZE(x) (int)x.size()
#define ALL(c) c.begin(),c.end()

#define MAX_N 100000

int tests, n;

int main() {
	scanf("%d",&tests);
	for (int test = 1; test <= tests; test++) {
		scanf("%d",&n);
		int ba, bb, bc, bd;
		int a, b, c, d;
		int isReal = 1;
		scanf("%d %d %d %d",&ba, &bb, &bc, &bd);
		for (int i = 1; i < n; i++) {
			scanf("%d %d %d %d",&a,&b,&c,&d);
			if (a == ba && b == bb && c == bc && d == bd) isReal = 1;
			if (a >= ba && b <= bb && c >= bc && d <= bd) continue;
			if (a <= ba && b >= bb && c <= bc && d >= bd) {
				ba = a; bb = b; bc = c; bd = d;
				isReal = 1;
			}
			else {
				ba = min(a, ba); bb = max(b, bb); bc = min(c, bc); bd = max(d, bd);
				isReal = 0;
			}
		}
		
		if (isReal) printf("TAK\n");
		else printf("NIE\n");
	}
	return 0;
}