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
#include <iostream>

using namespace std;

main()
{
    int t, n;
    cin >> t;
    for( int l(0); l < t; ++l )
    {
        bool v(1);
        int x(0), y(0), w1, w2, w3, w4, h1, h2, h3, h4;
        cin >> n >> w1 >> w2 >> h1 >> h2;
        --n;
        for( n; n > 0; --n )
        {
            cin >> w3 >> w4 >> h3 >> h4;
            if( w1 > w3 )
            {
                w1 = w3;
                ++x;
            }
            else if( w1 == w3 ) ++y;
            if( h1 > h3 )
            {
                h1 = h3;
                ++x;
            }
            else if( h1 == h3 ) ++y;
            if( w2 < w4 )
            {
                w2 = w4;
                ++x;
            }
            else if( w2 == w4 ) ++y;
            if( h2 < h4 )
            {
                h2 = h4;
                ++x;
            }
            else if( h2 == h4 ) ++y;
            if( x != 0 )
            {
                if( y + x == 4 ) v = 1;
                else v = 0;
            }
            x = 0;
            y = 0;
        }
        if( v ) cout << "TAK" << endl;
        else cout << "NIE" << endl;
    }
    return 0;
}