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

bool process_data_set(){
    int ndata;
    std::cin>>ndata;
    register bool found = false;
    register unsigned min_width = 0;
    min_width = ~min_width;
    register unsigned max_width = 0;
    register unsigned min_height = 0;
    min_height = ~min_height;
    register unsigned max_height = 0;
    unsigned w1,w2,h1,h2;
    for(int i=0; i<ndata; i++){
        std::cin>>w1;
        std::cin>>w2;
        std::cin>>h1;
        std::cin>>h2;
        if( w1 <= min_width && w2 >= max_width && h1 <= min_height && h2 >= max_height ){
            found = true;
            min_width = w1;
            max_width = w2;
            min_height = h1;
            max_height = h2;
        }else{
            if( w1 < min_width ){
                min_width = w1;
                found = false;
            }
            if( w2 > max_width ){
                max_width = w2;
                found = false;
            }
            if( h1 < min_height ){
                min_height = h1;
                found = false;
            }
            if( h2 > max_height ){
                max_height = h2;
                found = false;
            }
        }
    }
    return found;
}

void process_data(){
    int n_data_sets;
    std::cin>>n_data_sets;
    for(int i=0; i<n_data_sets; i++)
        if( process_data_set() )
            std::cout<<"TAK\n";
        else
            std::cout<<"NIE\n";
}

int main()
{
    process_data();
    return 0;
}