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
/*	Arek Wróbel - skater
 *
 *	Zadanie: Lustra
 */
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define REP(I, N) for(int I=0; I<(N); ++I)
#define FOR(I, M, N) for(int I=(M); I<=(N); ++I)
#define FORD(I, M, N) for(int I=(M); I>=(N); --I)
#define FOREACH(IT, CON) for(__typeof(CON.begin()) IT=CON.begin(); IT!=CON.end(); ++IT)
#define ST first
#define ND second
#define MP make_pair
#define PB push_back
const int INF=1000000000;
const LL INFLL=1000000000000000000LL;

int n;
int t[100000][4];
int x[4];

bool check() {
	REP(i, n) {
		if (t[i][0]==x[0] && t[i][1]==x[1] && t[i][2]==x[2] && t[i][3]==x[3])
			return true;
	}
	return false;
}

int main()
{
	int T;
	scanf("%d", &T);
	while(T--) {
		//wej
		scanf("%d", &n);
		REP(i, n)
			REP(j, 4)
				scanf("%d", &t[i][j]);
		//prog
		x[0] = x[2] = INF;
		x[1] = x[3] = -INF;
		REP(i, n) {
			x[0] = min(x[0], t[i][0]);
			x[1] = max(x[1], t[i][1]);
			x[2] = min(x[2], t[i][2]);
			x[3] = max(x[3], t[i][3]);
		}
		//wyj
		printf(check() ? "TAK\n" : "NIE\n");
	}
	return 0;
}