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
65
66
67
68
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;

#define FOR(I,A,B) for(int I=(A);I<=(B);I++)
#define REP(I,N) for(int I=0;I<(N);I++)
#define ALL(X) (X).begin(),(X).end()
#define PB push_back
#define MP make_pair
#define f first
#define s second

typedef vector<int> VI;
typedef pair<int,int> PII;
typedef long long ll;
typedef vector<string> VS;

const int MAX = 100005;
const int inf = 1000000001;
		
int tab[MAX][4];
int a[4];

bool check(int i){
	REP(j,4)
		if(tab[i][j] != a[j]) return false;
	return true;
}

int main(){
	ios_base::sync_with_stdio(0);

	int t;
	cin >> t;

	FOR(i,1,t){
		int n;
		cin >> n;

		REP(j,n) REP(k,4) cin >> tab[j][k];

		a[0] = a[2] = inf;
		a[1] = a[3] = 0;

		REP(j,n){
			a[0] = min(a[0],tab[j][0]);
			a[1] = max(a[1],tab[j][1]);
			a[2] = min(a[2],tab[j][2]);
			a[3] = max(a[3],tab[j][3]);
		}

		bool ok = false;
		REP(j,n){
			if(check(j)) ok = true;
		}

		ok ? cout << "TAK\n" : cout << "NIE\n";
	}

	return 0;
}