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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <cctype>
#include <cmath>
#include <iostream>
#include <set>
#include <map>
#include <sstream>
#include <typeinfo>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<string> vs;
 
#define SIZE(x) ((int)(x.size()))
#define LET(var, val) typeof(val) var = (val)
#define FOR(k, a, b) for(typeof(a) k = (a); k < (b); ++k)
#define FORR(k, a, b) for(typeof(a) k = (a); k >= (b); --k)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for(LET(i, (c).begin()); i != (c).end(); ++i)
#define PB push_back
#define PF push_front
 
const int INF = 1000000001;
const double EPS = 10e-9;
const double PI = acos(-1.0);
 
ostringstream out;

vi min_width;
vi max_width;
vi min_height;
vi max_height;

int dane[100000][4];

int main()
{
	ios_base::sync_with_stdio(0);
	int t;
	cin >> t;
	while(t--)
	{
		min_height.clear();
		max_height.clear();
		min_width.clear();
		max_width.clear();
		int n;
		cin >> n;
		int min_w = INF, min_h = INF, max_w = 0, max_h = 0;
		REP(i, n)
		{
			cin >> dane[i][0] >> dane[i][1] >> dane[i][2] >> dane[i][3];
			if (dane[i][0] < min_w) min_w = dane[i][0];
			if (dane[i][1] > max_w) max_w = dane[i][1];
			if (dane[i][2] < min_h) min_h = dane[i][2];
			if (dane[i][3] > max_h) max_h = dane[i][3];
		}
		REP(i, n)
		{
			if (dane[i][0] == min_w) min_width.PB(i); 
			if (dane[i][1] == max_w) max_width.PB(i);
			if (dane[i][2] == min_h) min_height.PB(i);
			if (dane[i][3] == max_h) max_height.PB(i);
		}
		bool was = false;
		LET(i, min_width.begin());
		LET(j, max_width.begin());
		LET(k, min_height.begin());
		LET(l, max_height.begin());
		while (i != min_width.end() && j != max_width.end() && k != min_height.end() && l != max_height.end())
		{
			int minimum = min(min(*i, *j), min(*k, *l));
			if (*i == *j && *k == *l && *i == *k)
			{
				was = true;
				break;
			}
			if (*i == minimum) ++i;
			if (*j == minimum) ++j;
			if (*k == minimum) ++k;
			if (*l == minimum) ++l;
		}
		out << (was ? "TAK\n" : "NIE\n");
	}
	cout << out.str();
	return 0;
}