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
78
79
80
#include <algorithm>
#include <fstream>
#include <string>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <sstream>
#include <iostream>
#include <cmath>
using namespace std;

typedef unsigned int uint;
typedef long long int64;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pI;
typedef pair<string, int> pSI;
typedef pair<int, string> pIS;

#define FOR(i,n) for(int i=0, upTo##i=n; i<upTo##i; ++i)
#define REVFOR(i,n) for(int i=(n)-1; i>=0; --i)
#define FOR2(i,b,n) for(int i=b; i<(n); ++i)
#define REVFOR2(i,b,n) for(int i=(n)-1; i>=b; --i)
#define SC(i) scanf("%d", i)
#define ALL(C) (C).begin(), (C).end()
#define RALL(C) (C).rbegin(), (C).rend()
#define MIN(C) *min_element(ALL(C))
#define MAX(C) *max_element(ALL(C))
#define A first
#define B second

int d[100000][4];

void start() {
	int t;
	cin >> t;

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

		int wx1, wx2, hx1, hx2;
		FOR(j, n) {
			int w1, w2, h1, h2; cin >> w1 >> w2 >> h1 >> h2;
			if (j == 0) {
				wx1 = w1;
				wx2 = w2;
				hx1 = h1;
				hx2 = h2;
			}

			wx1 = min(wx1, w1);
			wx2 = max(wx2, w2);
			hx1 = min(hx1, h1);
			hx2 = max(hx2, h2);

			d[j][0] = w1;
			d[j][1] = w2;
			d[j][2] = h1;
			d[j][3] = h2;
		}


		bool res = false;
		FOR(j, n) {
			if (d[j][0] == wx1 && d[j][1] == wx2 && d[j][2] == hx1 && d[j][3] == hx2) {
				res = true;
				break;
			}
		}

		cout << (res ? "TAK" : "NIE") << endl;
	}
}

int main(void) {
	start();

	return 0;
}