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

using namespace std;

int main() {
    int T;
    scanf("%i", &T);

    for (int t=0; t<T; ++t) {
        int N;
        scanf("%i", &N);

        int W1[N], W2[N], H1[N], H2[N];
        for (int n=0; n<N; ++n) {
            int w1,w2,h1,h2;
            scanf("%i%i%i%i", &w1, &w2, &h1, &h2);   
            W1[n] = w1;
            W2[n] = w2;
            H1[n] = h1;
            H2[n] = h2;
        }

        int minw1 = *min_element(W1, W1 + N);
        int maxw2 = *max_element(W2, W2 + N);
        int minh1 = *min_element(H1, H1 + N);
        int maxh2 = *max_element(H2, H2 + N);
        
        int best[N]; for (int i=0; i<N; ++i) best[i]=0;
        for (int i=0; i<N; ++i) {
            if (W1[i]==minw1) best[i] += 1;
            if (W2[i]==maxw2) best[i] += 1;
            if (H1[i]==minh1) best[i] += 1;
            if (H2[i]==maxh2) best[i] += 1;
        }

        bool isbest=false;
        for (int i=0; i<N; ++i) if (best[i]==4) isbest=true; 

        if (isbest) {
            printf("TAK\n");            
        } else {
            printf("NIE\n");
        }
    }

    return 0;
}