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

using namespace std;

int main(){
    int t, n;
    int w1, w2, h1, h2;
    int wMin, wMax, hMin, hMax;
    bool exist, changing;
    
    scanf("%d\n", &t);
    while(t--) {
        scanf("%d\n", &n);
        wMax = 1; wMin = 1000000000;
        hMax = 1; hMin = 1000000000;
        exist = true;
        
        while(n--) {
            scanf("%d %d %d %d\n", &w1, &w2, &h1, &h2);
            changing = false;
            
            if(w1 < wMin) {
                wMin = w1;
                changing = true;
            }
            if(w2 > wMax) {
                wMax = w2;
                changing = true;
            }
            if(h1 < hMin) {
                hMin = h1;
                changing = true;
            }
            if(h2 > hMax) {
                hMax = h2;
                changing = true;
            }
            
            if(changing) {
                if(w1==wMin && w2==wMax && h1==hMin && h2==hMax) {
                    exist = true;
                }
                else {
                    exist = false;
                }
            }
        }
        
        if(exist) {
            printf("TAK\n");
        }
        else {
            printf("NIE\n");
        }
    }
}