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
76
77
// Michał Łazowik
// Potyczki Algorytmiczne 2014
// Runda 1 - Lustra [B]

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <utility>

using namespace std;

typedef long long LL;

#define REP(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, b, e) for (int x = b; x <= (e); ++x)
#define FORD(x, b, e) for (int x = b; x >= (e); --x)
#define FOREACH(it, cont) for (__typeof(cont.begin()) it = cont.begin(); it != cont.end(); ++it)

#define F first
#define S second
#define MP make_pair
#define PB push_back

const int BARZYLION = 2e9;
const int MAX = 1e5+10;

int sz[MAX][4], maxx[4], n;

bool equals(int *t1, int *t2) {
	REP(i, 4) {
		if (t1[i] != t2[i]) {
			return false;
		}
	}

	return true;
}

bool ok() {
	REP(i, n) {
		if (equals(maxx, sz[i])) {
			return true;
		}
	}

	return false;
}

int main() {
	int t;

	scanf("%d", &t);

	FOR(q, 1, t) {
		maxx[0] = BARZYLION;
		maxx[1] = -1;
		maxx[2] = BARZYLION;
		maxx[3] = -1;

		scanf("%d", &n);
		REP(i, n) {
			REP(j, 4) {
				scanf("%d", &sz[i][j]);	
				maxx[j] = (j % 2) ? max(maxx[j], sz[i][j]) : min(maxx[j], sz[i][j]);
			}
		}

		printf("%s\n", (ok()) ? "TAK" : "NIE");
	}

	return 0;
}