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

using namespace std;

int main()
{
    int h1, h2, w1, w2;
    int t;
    cin >> t;

    for(int k=0; k<t; k++)
    {
        bool lider = false;
        int w1_min=1000000000;
        int w2_max=0;
        int h1_min=1000000000;
        int h2_max=0;

        int n;
        cin >> n;

        for(int i=0; i<n; i++)
        {
            cin >> h1 >> h2 >> w1 >> w2;

            if(h1 < h1_min)
            {
                h1_min = h1;
                lider = false;
            }
            if(w1 < w1_min)
            {
                w1_min = w1;
                lider = false;
            }
            if(h2 > h2_max)
            {
                h2_max = h2;
                lider = false;
            }
            if(w2 > w2_max)
            {
                w2_max = w2;
                lider = false;
            }

            if(h1_min == h1 && w1_min == w1 && h2_max == h2 && w2_max == w2)
                lider = true;
        }

        if(lider == true)
            cout << "TAK" << endl;
        else
            cout << "NIE" << endl;
    }

    return 0;

}