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

using namespace std;

int main(int argc, char **argv) {
    int t, n, w1, w2, h1, h2;
    int iminh, imaxh, iminw, imaxw;
    int wmin, wmax, hmin, hmax;
    cin >> t;
    for(int i=0;i<t;++i) {
        cin >> n;
        iminh = imaxh = iminw = imaxw = -1;
        wmin = hmin = 1000000001;
        wmax = hmax = 0;
        for(int j=0;j<n;++j) {
            //cerr << "j=" << j << endl;
            cin >> w1;
            cin >> w2;
            cin >> h1;
            cin >> h2;
            if(w1 < wmin) { wmin = w1; iminw = j; }
            if(w2 > wmax) { wmax = w2; imaxw = j; }
            if(h1 < hmin) { hmin = h1; iminh = j; }
            if(h2 > hmax) { hmax = h2; imaxh = j; }
        }
        if(iminh == imaxh == iminw == imaxw) {
            cout << "TAK" << endl;
        }
        else {
            cout << "NIE" << endl;
        }
    }
}