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
69
70
71
72
73
74
75
#include<bits/stdc++.h>
#define ALL(X)      X.begin(),X.end()
#define FOR(I,A,B)  for(int (I) = (A); (I) <= (B); (I)++)
#define FORW(I,A,B) for(int (I) = (A); (I) < (B);  (I)++)
#define FORD(I,A,B) for(int (I) = (A); (I) >= (B); (I)--)
#define CLEAR(X)    memset(X,0,sizeof(X))
#define PB          push_back
#define MP          make_pair
#define X           first
#define Y           second
using namespace std;
typedef signed long long slong;
typedef long double ldouble;
const slong Infinity = 1000000100;
const ldouble Epsilon = 1e-9;
template<typename T, typename U> ostream& operator << (ostream& os, const pair<T,U>&p) {return os << "(" << p.X << "," << p.Y << ")"; }
template<typename T> ostream& operator << (ostream &os, const vector<T>& V) { os << "["; FORW(i,0,size(V)) os << V[i] << ((i==size(V)-1) ? "" : ","); return os << "]"; }
template<typename T> ostream& operator << (ostream &os, const set<T>& S) {os << "("; for(auto i: S) os << i << (i==*S.rbegin()?"":","); return os << ")"; }
template<typename T, typename U> ostream& operator << (ostream &os, const map<T, U>& M){os << "{"; for(auto i: M) os << i << (i.X==M.rbegin()->X?"":","); return os << "}"; }
template<typename T, typename F> T lbound(T p, T q, F f) { static_assert(is_integral<T>::value, "integral type required"); while(p < q) { T r = p+(q-p)/2; if(f(r)) q = r; else p = r+1; } return p; }
template<typename T, typename F> T lboundl(T p, T q, F f) { static_assert(is_floating_point<T>::value, "floating point type required"); FOR(i,1,70) { T r = (p+q)/2; if(f(r)) q = r; else p = r; } return p; }
template<typename T, typename U> bool contain(T t, U u) { return t.find(u) != t.end(); }
template<typename T> int size(T t) { return t.size(); }

const int MAXN = 1000100;
int A[MAXN];
int B[MAXN];
int P[MAXN];
int Q[MAXN];
int N;

void read_data()
{
	scanf("%d", &N);
	FOR(i,1,N) scanf("%d %d %d %d", A+i, B+i, P+i, Q+i);	
}

bool X[MAXN];
bool Y[MAXN];

void solve()
{
	CLEAR(X); CLEAR(Y);
	int a = Infinity;
	int b = -Infinity;
	FOR(i,1,N)
	{
		a = min(a,A[i]);
		b = max(b,B[i]);
	}	
	FOR(i,1,N) if(A[i] == a and B[i] == b) X[i] = true;
	a = Infinity;
	b = -Infinity;
	FOR(i,1,N)
	{
		a = min(a,P[i]);
		b = max(b,Q[i]);
	}
	FOR(i,1,N) if(P[i] == a and Q[i] == b) Y[i] = true;
	bool result = false;
	FOR(i,1,N) if(X[i] and Y[i]) result = true;
	printf(result ? "TAK\n" : "NIE\n");
}

int main() 
{
	int z;
	scanf("%d", &z);
	FOR(_,1,z)
	{
		read_data();
		solve();
	}
	return 0;
}