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
#include<cstdio>
#include<vector>
#include<cstring>
#include<cmath>

using namespace std;

vector<int> v1,v2,v3,v4;
int tab[100003];
int inf = 1000000007;

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		scanf("%d",&n);
		int a=0,b=0,c=0,d=0;
		int m1=inf,m2=0,m3=inf,m4=0;
		for (int i = 0; i < n; i++)
		{
			scanf("%d%d%d%d",&a,&b,&c,&d);
			if (a == m1) v1.push_back(i);
			else if (a < m1) v1.clear(), v1.push_back(i), m1 = a;
			if (b == m2) v2.push_back(i);
			else if (b > m2) v2.clear(), v2.push_back(i), m2 = b;
			if (c == m3) v3.push_back(i);
			else if (c < m3) v3.clear(), v3.push_back(i), m3 = c;
			if (d == m4) v4.push_back(i);
			else if (d > m4) v4.clear(), v4.push_back(i), m4 = d;
		}
		int ans = 0;
				
		
		int q = max(max(v1.size(),v2.size()),max(v3.size(),v4.size()));
		
		for (int i = 0; i < q; i++)
		{
			if (i < v1.size()) tab[v1[i]]++;
			if (i < v2.size()) tab[v2[i]]++;
			if (i < v3.size()) tab[v3[i]]++;
			if (i < v4.size()) tab[v4[i]]++;
		}
		for (int i = 0; i < n; i++) if (tab[i] == 4) {ans = true; break;}
		if (ans) puts("TAK");
		else puts("NIE");
		v1.clear(), v2.clear(), v3.clear(), v4.clear();
		memset(tab,0,4*n+4);
	}
	
    return 0;
}