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
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <mutex>
#include <thread>
using namespace std;

int main()
{
	int n, p;
	scanf("%d", &n);
	while (n--)
	{
		scanf("%d", &p);
		bool found = true;
		int w1, w2, h1, h2;
		int minw = 0, maxw = 0, minh = 0, maxh = 0;
		scanf("%d %d %d %d", &minw, &maxw, &minh, &maxh);
		p--;
		while (p--)
		{
			scanf("%d %d %d %d", &w1, &w2, &h1, &h2);
			if (w1 < minw || w2 > maxw || h1 < minh || h2 > maxh)
			{
				found = false;
				minw = min(minw, w1);
				maxw = max(maxw, w2);
				minh = min(minh, h1);
				maxh = max(maxh, h2);

				if (minw == w1 && maxw == w2 && minh == h1 && maxh == h2)
					found = true;
			}
		}
		if (found)
			puts("TAK");
		else
			puts("NIE");
	}

	return 0;
}