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
#include <cstdio>
#include <vector>
#include <set>
#define REP(i,b) for(int i=0; i<(b); ++i)
#define PB push_back

using namespace std;
typedef vector<int> VI;
typedef long long LL;

const int MAXN = 100000;
int w1[MAXN],w2[MAXN];
int h1[MAXN],h2[MAXN];
int t;

int main() {
	scanf("%d", &t);

	REP(i,t) {
		int n;
		scanf("%d", &n);
		int mx_w = -1, mx_h = 1;
		REP(i,n) {
			int a,b,c,d;
			scanf("%d%d%d%d", &a,&b,&c,&d);
			w1[i] = min(a,b); w2[i] = max(a,b);
			h1[i] = min(c,d); h2[i] = max(c,d);
			mx_w = max(mx_w,w2[i]-w1[i]);
			mx_h = max(mx_h,h2[i]-h1[i]);
		}
		int max_x = -1, max_y = -1;
		int v1 = 0, v2 = 0;
		set<int> verticles;
		REP(i,n) {
			if (w2[i]-w1[i]==mx_w) {
				if (h2[i]-h1[i]>max_y) {
					v1 = i;
					max_y = h2[i]-h1[i];
				}
			}
			if (h2[i]-h1[i]==mx_h) {
				if (w2[i]-w1[i]>max_x) {
					v2 = i;
					max_x = w2[i]-w1[i];
				}
			}
		}
		bool valid = false;
		verticles.insert(v1);
		verticles.insert(v2);
		for(auto x: verticles) {
			bool val = true;
			REP(i,n) {
				if(!(w1[i]>=w1[x] && w2[i]<=w2[x] && h1[i]>=h1[x] && h2[i]<=h2[x])) val = false;
			}
			if (val) valid = true;

		}
		if (valid) printf("TAK\n");
		else printf("NIE\n");
		//printf(" %d:%d\n", hm1, hm2);
		//printf("%d %d\n", hm_in_mx_w, hm_in_mx_h);
	}

	return 0;
}