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

int n, p, tx[100007], ty[100007], ux[100007], uy[100007], cand;

int main () {
	scanf ("%d", &n);
	for (int i=0; i<n; ++i) {
		scanf ("%d", &p);
		for (int j=0; j<p; ++j) {
			scanf ("%d%d%d%d", &tx[j], &ux[j], &ty[j], &uy[j]);
		}
		cand = 0;
		for (int j=0; j<p; ++j) {
			if (tx[cand]>=tx[j] && ty[cand]>=ty[j] && ux[cand]<=ux[j] && uy[cand]<=uy[j]) cand=j;
			//printf ("%d - %d; %d - %d; %d - %d; %d - %d;\n", tx[cand], tx[j] ,  ty[cand], ty[j] ,  ux[cand], ux[j] ,  uy[cand]<=uy[j]);
		}
		//printf ("%d\n", cand);
		for (int j=0; j<p; ++j) {
			if (tx[cand]>tx[j] || ty[cand]>ty[j] || ux[cand]<ux[j] || uy[cand]<uy[j]) {
				printf ("NIE\n");
				break;
			}
			if (j==p-1) printf ("TAK\n");
		}
	}
	return 0;
}