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
76
/* 
 * File:   lus.cpp
 * Author: baca
 *
 * Created on 12 maj 2014, 20:24
 */

#include <cstdlib>
#include <iostream>

using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {
    
    cin.sync_with_stdio(false);
    
    int t, n;
    
    long long w1, w2, h1, h2;
    
    long long minw, maxw, minh, maxh;
    
    bool b;
    
//    cin >> t;
    scanf("%d", &t);
    
    while (t--) {
        b = true;
        
//        cin >> n;
        scanf("%d", &n);
        
//        cin >> minw >> maxw >> minh >> maxh;
        scanf("%lld %lld %lld %lld", &minw, &maxw, &minh, &maxh);
        
        n--;
        while (n--) {
//            cin >> w1 >> w2 >> h1 >> h2;
            scanf("%lld %lld %lld %lld", &w1, &w2, &h1, &h2);
            
            
            if (h1 < minh) {
                minh = h1;
                b = false;
            }
            
            if (h2 > maxh) {
                maxh = h2;
                b = false;
            }
            
            if (w1 < minw) {
                minw = w1;
                b = false;
            }
            
            if (w2 > maxw) {
                maxw = w2;
                b = false;
            }
            
            if (!b && minh == h1 && maxh == h2 && minw == w1 && maxw == w2) {
                b = true;
            }
        }
        
//        cout << (b ? "TAK" : "NIE") << endl;
        printf(b ? "TAK\n" : "NIE\n");
    }

    return 0;
}