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
#include <iostream>
#include<cstdio>
using namespace std;

int main() {
	int z;
	scanf("%d",&z);
	while(z--) {
		int n;
		scanf("%d",&n);
		int tmin0[100009],tmin1[100009];
		int tmax0[100009],tmax1[100009];
		long najD=-2,maxh=0,maxw=0,minh=100000000,minw=100000000,najM=-1;
		for (int i=0; i<n;i++) {
			scanf("%d%d%d%d",&tmin0[i],&tmax0[i],&tmin1[i],&tmax1[i]);
			if ((tmax0[i]>=maxw) && (tmax1[i]>=maxh) && (tmin0[i]<=minw) && (tmin1[i]<=minh)) {
				maxw = tmax0[i];
				maxh = tmax1[i];
				najD=i;
				minw = tmin0[i];
				minh = tmin1[i];
				najM=i;
			}
		}
		bool pom=true;
		if (najD!=najM) {
			printf("NIE\n");
			pom=false;
		} else {
			for (int i=0;i<n;i++) {
					if (pom==true)
					if ((minw>tmin0[i]) || (minh>tmin1[i]) || (maxw<tmax0[i]) || (maxh<tmax1[i])) {
						pom=false;
						printf("NIE\n");
						break;
					}

			}
		}
		if (pom==true) {
			printf("TAK\n");
		}
	}
	return 0;
}