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
#include <cstdio>
#include <algorithm>
using namespace std;
#define LOG(args...) 
//#define LOG(args...) fprintf(stderr, args)

int w1, w2, h1, h2;
int W1, W2, H1,H2; 

void copyDims() {
	w1 = W1; w2 = W2; h1 = H1; h2 = H2;
}

void mergeDims() {
	w1 = min(w1, W1);
	w2 = max(w2, W2);
	h1 = min(h1, H1);
	h2 = max(h2, W2);
}


int main() {
	int t; scanf("%d", &t);
	for(int t1 = 0; t1<t; t1++){
		int n; scanf("%d", &n);
		
		bool maj = true;
		for (int i = 0; i<n; i++) {
			scanf("%d%d%d%d", &W1, &W2, &H1, &H2);
			
			if(i) {

				LOG("%d, %d, %d, %d\n",w1, w2, h1, h2);
				LOG("%d, %d, %d, %d\n", W1 <= w1, W2 >= w2, H1 <= h1, H2 >= h2);
				if(W1 <= w1 && W2 >= w2 && H1 <= h1 && H2 >= h2) {
					maj = true;
					copyDims();
					LOG("copy\n");
				} else if(W1 >= w1 && W2 <= w2 && H1 >= h1 && H2 <= h2) {

					LOG("nada\n");
				} else {
					mergeDims();
					LOG("merge\n");
					maj = false;
				}
				
			} else {
				copyDims();
			}
			
		}
		if(maj) printf("TAK\n");
		else printf("NIE\n");
		
		
	}
	return 0;
}