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

const unsigned int tmax = 10;
const unsigned int nmax = 100000;

unsigned int contestants[tmax];
long long unsigned int contest[tmax][4][nmax];

long long unsigned int findmax(long long unsigned int*,unsigned int);
long long unsigned int findmin(long long unsigned int*,unsigned int);

int main() {
    unsigned int t;
    long long unsigned int wmin;
    long long unsigned int wmax;
    long long unsigned int hmin;
    long long unsigned int hmax;
    scanf("%d",&t);
    
    for(unsigned int i=0; i<t; i++) {
                 scanf("%d",&contestants[i]);
                 for(unsigned int j=0; j<contestants[i]; j++) {
                              scanf("%llu %llu %llu %llu",&contest[i][0][j],&contest[i][1][j],&contest[i][2][j],&contest[i][3][j]);
                 }
    }
    
    for(unsigned int i=0; i<t; i++) {
                 wmin = findmin(contest[i][0],contestants[i]);
                 wmax = findmax(contest[i][1],contestants[i]);
                 hmin = findmin(contest[i][2],contestants[i]);
                 hmax = findmax(contest[i][3],contestants[i]);
                 bool iswinning=false;
                 for(unsigned int j=0; j<contestants[i]; j++) {
                              if ((contest[i][0][j]==wmin) && (contest[i][1][j]==wmax) && (contest[i][2][j]==hmin) && (contest[i][3][j]==hmax)) {
                                 printf("TAK\n");
                                 iswinning = true;
                                 break;
                              }
                 }
                 if (!iswinning) printf("NIE\n");
    }
    return 0;
}

long long unsigned int findmax(long long unsigned int* tab, unsigned int n) {
     long long unsigned int current = tab[0];
     for (unsigned int i=1; i<n; i++) if (current<tab[i]) current=tab[i];
     return current; 
}

long long unsigned int findmin(long long unsigned int* tab, unsigned int n) {
     long long unsigned int current = tab[0];
     for (unsigned int i=1; i<n; i++) if (current>tab[i]) current=tab[i];
     return current;
}