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
47
48
49
50
51
52
53
54
55
56
#include <cstdio>
#include <assert.h>

using namespace std;


int i, j, cnt, cnt2 = 0;
long int maxSurf, maxSurfh1, maxSurfh2, maxSurfw1, maxSurfw2, maxh1, maxh2, maxw1, maxw2 = 0;
long int h1, h2, w1, w2 = 0;

int main() {
    assert(1 == scanf ("%d", &cnt));

    for (i = 0; i < cnt; i++)
    {
	assert(1 == scanf ("%d", &cnt2));
	maxh1 = 1000000000;
	maxh2 = 0;
	maxw1 = 1000000000;
	maxw2 = 0;
	maxSurf = 0; maxSurfh1 = 0; maxSurfh2 = 0; maxSurfw1 = 0; maxSurfw2 = 0;
	
	for (j = 0; j < cnt2; j++)
	{
	    assert(1 == scanf ("%ld", &h1));
	    assert(1 == scanf ("%ld", &h2));
	    assert(1 == scanf ("%ld", &w1));
	    assert(1 == scanf ("%ld", &w2));

	    if (h1 < maxh1) maxh1 = h1;
	    if (h2 > maxh2) maxh2 = h2;
	    if (w1 < maxw1) maxw1 = w1;
	    if (w2 > maxw2) maxw2 = w2;
	    
	    if (((h2-h1+1) * (w2-w1+1)) > maxSurf)
	    {
		maxSurf = (h2-h1+1) * (w2-w1+1);
		maxSurfh1 = h1;
		maxSurfh2 = h2;
		maxSurfw1 = w1;
		maxSurfw2 = w2;
	    }
	}

	if ((maxh1 < maxSurfh1) || (maxh2 > maxSurfh2) || (maxw1 < maxSurfw1) || (maxw2 > maxSurfw2))
	{
	    printf("NIE\n");
	}
	else
	{
	    printf("TAK\n");
	}
    }

    return 0;
}