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 <stdlib.h>
#include <stdio.h>
#include <string.h>

#define ARR_SIZE 16

using namespace std;


void test_case() {
	int n;
	int dim[4], extremes[4][4], major[4];
	
	scanf("%d", &n);
	scanf("%d%d%d%d", dim, dim+1, dim+2, dim+3);
	for (int i = 0; i < 4; i++) {
		memcpy(extremes[i], dim, ARR_SIZE);
	}
	memcpy(major, dim, ARR_SIZE);
	for (int i = 1; i < n; i++) {
		scanf("%d%d%d%d", dim, dim+1, dim+2, dim+3);
//		printf("dim=%d %d %d %d\n", dim[0], dim[1], dim[2], dim[3]);
//		for (int j = 0; j < 4; j++) {
//			printf("ex%d=%d %d %d %d\n", j, extremes[j][0], extremes[j][1], extremes[j][2], extremes[j][3]);
//		}
		bool is_major = true;
		for (int j = 0; j < 4; j++) {
			if (j == 0 || j == 2) {
				if (extremes[j][j] > dim[j]) {
//					printf("%d. is extreme #%d\n", i, j);
					memcpy(extremes[j], dim, ARR_SIZE);
				}
			} else if (extremes[j][j] < dim[j]) {
//				printf("%d. is extreme #%d\n", i, j);
				memcpy(extremes[j], dim, ARR_SIZE);
			}
			is_major = is_major && (((j == 0 || j == 2) && dim[j] <= major[j]) || ((j == 1 || j == 3) && dim[j] >= major[j]));
		}
		if (is_major) {
//			printf("%d. is major\n", i);
			memcpy(major, dim, ARR_SIZE);
		}
	}
	bool major_exists = true;
	for (int j = 0; j < 4; j++) {
		if (j == 0 || j == 2) {
			if (extremes[j][j] < major[j]) {
				major_exists = false;
			}
		} else if (extremes[j][j] > major[j]) {
			major_exists = false;
		}
	}
	printf(major_exists ? "TAK\n" : "NIE\n");
}

int main() {
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++) {
		test_case();
	}
}