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
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define ld long double
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define mini(a,b) a=min(a,(b))
#define maxi(a,b) a=max(a,(b))
#define RE(i,n) for(int i=0,_n=(n);i<_n;++i)
#define RI(i,n) for(int i=1,_n=(n);i<=_n;++i)
const int inf=1e9+5, nax=1e5+5;

ll t[nax][4];
bool ok;

void f(ll a, ll b, ll c) {
	if(a > b || b > c) ok = false;
}

int main()
{
	ios_base::sync_with_stdio(0);
	
	int ilet;
	cin >> ilet;
	while(ilet--) {
		int n;
		cin >> n;
		ll pole = 0;
		int best = 0;
		RE(i, n) {
			RE(j, 4) cin >> t[i][j];
			ll tmp = (t[i][1] - t[i][0]) * (t[i][3] - t[i][2]);
			if(tmp > pole) {
				best = i;
				pole = tmp;
			}
		}
		ok = true;
		RE(i, n) {
			RE(iteratorek, 2)
				f(t[best][0], t[i][iteratorek], t[best][1]);
			RE(iteratorek, 2)
				f(t[best][2], t[i][2 + iteratorek], t[best][3]);
		}
		if(ok) cout << "TAK\n";
		else cout << "NIE\n";
				
	}
	return 0;
}