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
#include<stdio.h>

int main()
{
    int t, n, i, minh, minw, maxh, maxw,
        winner, minwc, maxwc, minhc, maxhc;

    scanf("%d", &t);

    while(t--)
    {
        scanf("%d", &n);

        scanf("%d%d%d%d", &minw, &maxw, &minh, &maxh);
        winner = 1;

        for(i = 2; i <= n; ++i)
        {
            scanf("%d%d%d%d", &minwc, &maxwc, &minhc, &maxhc);
            if(minwc < minw || minhc < minh || maxwc > maxw || maxhc > maxh)
            {
                winner = 0;
                minw = minwc < minw ? minwc : minw;
                minh = minhc < minh ? minhc : minh;
                maxw = maxwc > maxw ? maxwc : maxw;
                maxh = maxhc > maxh ? maxhc : maxh;
            }
            if(minwc == minw && minhc == minh && maxwc == maxw && maxhc == maxh)
                winner = i;
        }

        if(winner == 0)
            printf("NIE\n");
        else
            printf("TAK\n");
    }

    return 0;
}