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
#include "stdio.h"

int w0, w1, h0, h1;
int mw0, mw1, mh0, mh1;
int n, k, v;
int main()
{
	scanf("%d", &n);
	while(n--)
	{
		scanf("%d %d %d %d %d", &k, &mw0, &mw1, &mh0, &mh1);
		v = 1;
		while(--k)
		{
			scanf("%d %d %d %d", &w0, &w1, &h0, &h1);
			if(mw0 >= w0 && mw1 <= w1 && mh0 >= h0 && mh1 <= h1)
			{
				mw0 = w0;
				mw1 = w1;
				mh0 = h0;
				mh1 = h1;
				v = 1;
			}
			else
			{
				if(mw0 <= w0 && mw1 >= w1 && mh0 <= h0 && mh1 >= h1)
				{

				}
				else
				{
					mw0 = mw0 <= w0 ? mw0 : w0;
					mw1 = mw1 >= w1 ? mw1 : w1;
					mh0 = mh0 <= h0 ? mh0 : h0;
					mh1 = mh1 >= h1 ? mh1 : h1;
					v = 0;
				}
			}
		}
		puts(v ? "TAK" : "NIE");
	}
	return 0;
}