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

using namespace std;

void lus(void)
{
    ios_base::sync_with_stdio(0);
    unsigned int tests;
    unsigned int factories;
    cin >> tests;
    for(int i=0; i < tests; ++i)
    {
        bool b = true;
        unsigned int w1, w2, h1, h2;
        unsigned int iw1, iw2, ih1, ih2;
        cin >> factories;
        cin >> w1 >> w2 >> h1 >> h2;
        --factories;
        while (factories--)
        {
            cin >> iw1 >> iw2 >> ih1 >> ih2;
            if(iw1 >= w1 && iw2 <=w2 && ih1 >= h1 && ih2 <= h2)
                continue;
            if(iw1 <= w1 && iw2 >= w2 && ih1 <= h1 && ih2 >= h2)
            {
                w1 = iw1;
                w2 = iw2;
                h1 = ih1;
                h2 = ih2;
                continue;
            }
            b = false;
            break;
        }
        cout << (b ? "TAK" : "NIE") << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    lus();
    return 0;
}