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
#include <cstdio>
#include <algorithm>

using namespace std;

int getMin(int *beg, int *end)
{
	int result = *beg;
	for(int *i = beg; i != end ; i++)
		result = min(result, *i);
	return result;
}

int getMax(int *beg, int *end)
{
	int result = *beg;
	for(int *i = beg; i != end ; i++)
		result = max(result, *i);
	return result;	
}

const int MAXN = 100005;
int n;
int minW[MAXN], maxW[MAXN], minH[MAXN], maxH[MAXN];

void read()
{
	scanf("%d", &n);
	for(int i = 0;i<n;i++)
		scanf("%d%d%d%d", minW + i, maxW + i, minH + i, maxH + i);
}

void solve()
{
	int minminW = getMin(minW, minW + n);
	int maxmaxW = getMax(maxW, maxW + n);
	int minminH = getMin(minH, minH + n);
	int maxmaxH = getMax(maxH, maxH + n);
	for(int i = 0; i < n ; i++)
	{
		if(minW[i] == minminW && maxW[i] == maxmaxW && minH[i] == minminH && 
			maxH[i] == maxmaxH)
		{
			printf("TAK\n");
			return;
		}
	}
	printf("NIE\n");
}

int main()
{
	int t;
	scanf("%d", &t);
	while(t--)
	{
		read();
		solve();
	}
	return 0;
}