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
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>

bool x;
unsigned char t;
unsigned int n, a, b, c, d, e, f;

int main()
{
    scanf( "%d", &t );
    for( unsigned char i( 0 ); i < t; ++i )
    {
        scanf( "%d%d%d%d%d", &n, &a, &b, &c, &d );
        x = 0;
        for( unsigned int j( 1 ); j < n; ++j )
        {
            scanf( "%d%d", &e, &f );
            if( e <= a && f >= b )
            {
                a = e;
                b = f;
                scanf( "%d%d", &e, &f );
                if( e <= c && f >= d )
                {
                    c = e;
                    d = f;
                    x = true;
                }
                else
                {
                    if( e < c ) c = e;
                    else if( f > d ) d = f;
                    x = false;
                }
            }
            else if( e >= a && f <= b )
            {
                scanf( "%d%d", &e, &f );
                if( e >= c && f <= d ) x = x;
                else
                {
                    if( e < c ) c = e;
                    else if( f > d ) d = f;
                    x = false;
                }
            }
            else if( e < a )
            {
                a = e;
                scanf( "%d%d", &e, &f );
                if( e < c ) c = e;
                else if( f > d ) d = f;
                x = false;
            }
            else if( f > b )
            {
                b = f;
                scanf( "%d%d", &e, &f );
                if( e < c ) c = e;
                else if( f > d ) d = f;
                x = false;
            }
        }
        if( x ) printf( "TAK\n" );
        else printf( "NIE\n" );
    }
    return 0;
}