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
#include <iostream>
#define REP(x, y) for(int x = 0; x < (y); ++x)

using namespace std;

int t, n, w0, w1, h0, h1, w0i, w1i, h0i, h1i, ex, inf = 1000000009;
bool flag;
bool up(int &a, int b) {
    if(a < b) {
        a = b;
        flag = 0;
        return 1;
    }
    if(a == b) return 1;
    return 0;
}

bool down(int &a, int b) {
    if(a > b) {
        a = b;
        flag = 0;
        return 1;
    }
    if(a == b) return 1;
    return 0;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> t;
    REP(tt, t) {
        cin >> n;
//         cout << "BUM " << n << "\n";
        w0 = h0 = inf;
        w1 = h1 = 0;
        flag = 0;
        REP(i, n) {
            cin >> w0i >> w1i >> h0i >> h1i;
            down(w0, w0i); down(h0, h0i); up(w1, w1i); up(h1, h1i);
            if(down(w0, w0i) && down(h0, h0i) && up(w1, w1i) && up(h1, h1i)) {
                flag = 1;
//                 cout << "Hello!!!\n";
            }
//             cout << w0 << " " << w1 << " " << h0 << " " << h1 << "\n";
//             cout << w0i << " " << w1i << " " << h0i << " " << h1i << "\n\n";
        }
        if(flag)
            cout << "TAK\n";
        else
            cout << "NIE\n";
    }
}