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 <cstdio>

struct window
{
    int w1, w2, h1, h2;
} *gwh;

void testcase()
{
    int k;
    scanf("%i", &k);

    for (int j = 0; j < k; ++j)
        scanf("%i%i%i%i", &gwh[j].w1, &gwh[j].w2, &gwh[j].h1, &gwh[j].h2);

    int mw1 = gwh[0].w1, mw2 = gwh[0].w2, mh1 = gwh[0].h1, mh2 = gwh[0].h2;

    for (int j = 0; j < k; ++j)
    {
        if (gwh[j].w1 <= mw1 && gwh[j].w2 >= mw2 && gwh[j].h1 <= mh1 && gwh[j].h2 >= mh2)
        {
            mw1 = gwh[j].w1;
            mw2 = gwh[j].w2;
            mh1 = gwh[j].h1;
            mh2 = gwh[j].h2;
        }
    }

    bool ok = true;

    for (int j = 0; j < k; ++j)
    {
        if (gwh[j].w1 < mw1 || gwh[j].w2 > mw2 || gwh[j].h1 < mh1 || gwh[j].h2 > mh2)
        {
            ok = false;
            break;
        }
    }

    printf(ok ? "TAK\n" : "NIE\n");
}

int main()
{
    gwh = new window[100000];

    int n;
    scanf("%i", &n);

    for (int i = 0; i < n; ++i)
        testcase();

    return 0;
}