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
#include <iostream>
using namespace std;

bool test() {
    int n, w1, w2, h1, h2, wmin, wmax, hmin, hmax;
    bool res = 1;
    cin >> n;
    n--;
    cin >> wmin >> wmax >> hmin >> hmax;
    while( n-- ) {
        cin >> w1 >> w2 >> h1 >> h2;
        if( w1 <= wmin && w2 >= wmax && h1 <= hmin && h2 >= hmax ) {
            wmin = w1, wmax = w2, hmin = h1, hmax = h2;
            res = 1;
        }
        else if( w1 < wmin )
            wmin = w1, res = 0;
        else if( w2 > wmax )
            wmax = w2, res = 0;
        else if( h1 < hmin )
            hmin = h1, res = 0;
        else if( h2 > hmax )
            hmax = h2, res = 0;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(0);
    int t;
    cin >> t;
    while( t-- ) {
        if( test() )
            cout << "TAK\n";
        else
            cout << "NIE\n";
    }
    return 0;
}