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

using namespace std;

int main()
{
    long int t, n, w1, w2, h1, h2;
    cin >> t;
    for (int i=0; i<t; i++){
        cin >> n;
        int wmin=0, wmax=0, hmin=0, hmax=0;
        string out="NIE";
        cin >> w1 >> w2 >> h1 >> h2;
        wmin = w1;
        wmax = w2;
        hmin = h1;
        hmax = h2;
        for (int j=1; j<n; j++){
            cin >> w1 >> w2 >> h1 >> h2;
            if (w1<=wmin && w2>=wmax && h1<=hmin && h2>=hmax){
                out="TAK";
                wmin = w1;
                wmax = w2;
                hmin = h1;
                hmax = h2;
            }
            else {
                if(w1<wmin){
                    wmin=w1;
                    out="NIE";
                }
                if(w2>wmax){
                    wmax=w2;
                    out="NIE";
                }
                if(h1<hmin){
                    hmin=h1;
                    out="NIE";
                }
                if(h2>hmax){
                    hmax=h2;
                    out="NIE";
                }
            }

        }
        cout << out << '\n';
    }
    return 0;
}