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
// Nikodem "nixon" Kramarz
// zad. Lustra, PA 2014

#include <iostream>
#include <algorithm>
#define MAX_N 100009
#define INF 1000000009
using namespace std;

int t, n, w1[MAX_N], w2[MAX_N], h1[MAX_N], h2[MAX_N], max_w = 0, max_h = 0, min_w = INF, min_h = INF;

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> t;
    while(t--)
    {
        min_w = min_h = INF;
        max_w = max_h = 0;
        cin >> n;
        for(int i=0; i<n; i++)
        {
            cin >> w1[i] >> w2[i] >> h1[i] >> h2[i];

            min_w = min(min_w, w1[i]);
            max_w = max(max_w, w2[i]);
            min_h = min(min_h, h1[i]);
            max_h = max(max_h, h2[i]);
        }
        

        bool p = 0;
        for(int i=0; i<n; i++)
        {
            if(w1[i] <= min_w && w2[i] >= max_w && h1[i] <= min_h && h2[i] >= max_h)
            {
                p = 1;
                break;
            }
        }

        if(p)
        {
            cout << "TAK\n";
            continue;
        }

        cout << "NIE\n";
    }
}