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


int main()
{
	int testy; scanf("%d",&testy);

	while( testy -- )
	{
		bool winner = false;

		int winnerX1 = INT_MAX;
		int winnerX2 = 0;
		int winnerY1 = INT_MAX;
		int winnerY2 = 0;

		int n; scanf("%d",&n);

		while( n -- ) {
			int x1,x2,y1,y2;
			scanf("%d%d%d%d",&x1,&x2,&y1,&y2);

			if( x1 <= winnerX1 && x2 >= winnerX2 && y1 <= winnerY1 && y2 >= winnerY2 ) {
				//puts("OK");
				winner = true;
			}
			else if( x1 < winnerX1 || x2 > winnerX2 || y1 < winnerY1 || y2 > winnerY2 ) {
				//puts("NOK");
				winner = false;
			}

			winnerX1 = std::min(winnerX1,x1);
			winnerX2 = std::max(winnerX2,x2);
			winnerY1 = std::min(winnerY1,y1);
			winnerY2 = std::max(winnerY2,y2);

			//printf("%d--%d %d--%d\n",winnerX1,winnerX2,winnerY1,winnerY2);
		}

		puts( (winner) ? "TAK" : "NIE");
	}

	return 0;
}