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
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long int ll;

bool comp(const pair<pair<int, int>, pair<int, int> > &a, const pair<pair<int, int>, pair<int, int> > &b)
{
	return ((ll) (a.first.second - a.first.first)) * (a.second.second - a.second.first) < ((ll) (b.first.second - b.first.first)) * (b.second.second - b.second.first);
}

bool wew(const pair<pair<int, int>, pair<int, int> > &a, const pair<pair<int, int>, pair<int, int> > &b)
{
	return b.first.first <= a.first.first && a.first.second <= b.first.second && b.second.first <= a.second.first && a.second.second <= b.second.second;
}

bool przyp()
{
	vector<pair<pair<int, int>, pair<int, int> > > v;
	int n;
	scanf("%d", &n);
	while(n--)
	{
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		v.push_back(make_pair(make_pair(a, b), make_pair(c, d)));
	}
	pair<pair<int, int>, pair<int, int> > naj = *max_element(v.begin(), v.end(), comp);
	for(int i = 0; i < (int) v.size(); i++)
		if(!wew(v[i], naj))
			return false;
	return true;
}

int main()
{
	int t;
	scanf("%d", &t);
	while(t--)
		printf(przyp() ? "TAK\n" : "NIE\n");
	return 0;
}