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
68
69
70
71
72
73
74
75
#include <cstdio>

int main(void){
    int jjj;
    scanf("%d", &jjj);
    while (jjj--)
    {
        int n, i;
        scanf("%d", &n);
        int *a = new int [n];
        int *b = new int [n];
        int *c = new int [n];
        int *d = new int [n];
        for (i = 0; i<n; i++)
            scanf("%d %d %d %d", a+i, b+i, c+i, d+i);
        bool *major = new bool [n];
        
        int min = a[0];
        for (i=0; i<n; i++)
            if (a[i]<min)
                min = a[i];
        for (i=0; i<n; i++)
            if (a[i]==min)
                major[i]=true;
            else
                major[i]=false;
        
        min = c[0];
        for (i=0; i<n; i++)
            if (c[i]<min)
                min = c[i];
        for (i=0; i<n; i++)
            if (c[i]==min && major[i]==true)
                major[i]=true;
            else
                major[i]=false;
        
        int max = b[0];
        for (i=0; i<n; i++)
            if (b[i]>max)
                max = b[i];
        for (i=0; i<n; i++)
            if (b[i]==max && major[i]==true)
                major[i]=true;
            else
                major[i]=false;
        
        max = d[0];
        for (i=0; i<n; i++)
            if (d[i]>max)
                max = d[i];
        for (i=0; i<n; i++)
            if (d[i]==max && major[i]==true)
                major[i]=true;
            else
                major[i]=false;
        max = 0;
        for (i=0; i<n; i++)
            if (major[i])
                max = 1;
        if (max ==1)
            printf("TAK\n");
        else
            printf("NIE\n");

        

        delete [] major;
        delete [] a;
        delete [] b;
        delete [] c;
        delete [] d;
    }
    return 0;
}