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
//Aleksander "kaalex" Kramarz

#include <cstdio>
#include <algorithm>
using namespace std;

int t, n, w1, w2, h1, h2;

int main()
{
	scanf("%d", &t);
	while(t--)
	{
		int minw=1e9+1, minh=1e9+1, maxw=-1e9-1, maxh=-1e9-1;
		bool res=false;
		scanf("%d", &n);
		while(n--)
		{
			scanf("%d%d%d%d", &w1, &w2, &h1, &h2);
			if(w1 <= minw && w2 >= maxw && h1 <= minh && h2 >= maxh)
				res = true;
			else if(!(w1 >= minw && w2 <= maxw && h1 >= minh && h2 <= maxh))
				res = false;
			minw = min(w1,minw);
			minh = min(h1,minh);
			maxw = max(w2,maxw);
			maxh = max(h2,maxh);
		}
		printf(res ? "TAK\n" : "NIE\n");
	}
}