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
#include <cstdio>
#include <algorithm>
#include <vector>
#define fru(j,n) for(int j=0;j<n;++j)
#define tr(it,x) for(typeof(x.begin())it=x.begin();it!=x.end();++it)
#define x first
#define y second

using namespace std;
typedef pair<int,int> pii;
typedef long long LL;
const int MAXN = 100005,inf=1<<30;
int T[MAXN][4];
int ANS[4];
void solve()
{
	int n;
	scanf("%d",&n);
	fru(i,n) fru(j,4) scanf("%d",&T[i][j]);
	ANS[0]=inf;
	ANS[2]=inf;
	ANS[1]=0;
	ANS[3]=0;
	fru(i,n)
	{
		ANS[0]=min(ANS[0],T[i][0]);
		ANS[2]=min(ANS[2],T[i][2]);
		ANS[1]=max(ANS[1],T[i][1]);
		ANS[3]=max(ANS[3],T[i][3]);
	}
	fru(i,n)
	{
		bool ok=1;
		fru(j,4) if(ANS[j]!=T[i][j]) ok=0;
		if(ok)
		{
			printf("TAK\n");
			return;
		}
	}
	printf("NIE\n");
}

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