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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);

    unsigned t;
    cin >> t;

    unsigned n;

    vector<unsigned> w, s;
    unsigned minw, mins, maxw, maxs, a, b;

    bool yes;

    while(t--)
    {
        yes = false;
        w.clear();
        s.clear();

        cin >> n;
        while(n--)
        {
            cin >> a >> b;
            w.push_back(a);
            w.push_back(b);

            cin >> a >> b;
            s.push_back(a);
            s.push_back(b);
        }

        minw=w[0]; maxw=w[0];
        for(int i=1; i<w.size(); ++i)
        {
            if(minw>w[i]) minw=w[i];
            if(maxw<w[i]) maxw=w[i];
        }

        mins=s[0]; maxs=s[0];
        for(int i=1; i<s.size(); ++i)
        {
            if(mins>s[i]) mins=s[i];
            if(maxs<s[i]) maxs=s[i];
        }

        for(int i=1; i<s.size(); ++i)
        {
            if(minw == w[i-1] && maxw == w[i] && mins == s[i-1] && maxs == s[i])
            {
                yes = true;
                cout << "TAK\n";
                break;
            }
        }

        if(!yes) cout << "NIE\n";

    }

    return 0;
}