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
/* PIOTR NOSEK
PA 2014 */
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#define MAXN 100000

using namespace std;

int n;
int w1[MAXN+7], w2[MAXN+7], h1[MAXN+7], h2[MAXN+7];
bool bw1[MAXN+7], bw2[MAXN+7], bh1[MAXN+7], bh2[MAXN+7];

void read()
{
	scanf("%d", &n);
	for(int i=0; i<n; i++)
		scanf("%d %d %d %d", &w1[i], &w2[i], &h1[i], &h2[i]);
}

bool answer()
{
	int maxw1 = *min_element(w1, w1+n), maxw2 = *max_element(w2, w2+n), maxh1 = *min_element(h1, h1+n), maxh2 = *max_element(h2, h2+n);
	for(int i=0; i<n; i++)
	{
		if(w1[i] == maxw1)
			bw1[i] = 1;
		if(w2[i] == maxw2)
			bw2[i] = 1;
		if(h1[i] == maxh1)
			bh1[i] = 1;
		if(h2[i] == maxh2)
			bh2[i] = 1;
	}
	for(int i=0; i<n; i++)
		if(bw1[i] && bw2[i] && bh1[i] && bh2[i])
			return 1;
	return 0;
}

void clean()
{
	for(int i=0; i<n; i++)
	{
		w1[i] = w2[i] = h1[i] = h2[i] = 0;
		bw1[i] = bw2[i] = bh1[i] = bh2[i] = 0;
	}
}


int main()
{
	int t;
	scanf("%d", &t);
	while(t--)
	{
		read();
		answer() ? printf("TAK") : printf("NIE");
		printf("\n");
		clean();
	}
	return 0;
}