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
/* 2014
 * Maciej Szeptuch
 * II UWr
 */
#include <cstdio>
#include <algorithm>

using namespace std;

int tests,
    companies,
    wMin, wMax,
    hMin, hMax,
    ws[131072], we[131072],
    hs[131072], he[131072];

bool check(void);

int main(void)
{
    scanf("%d", &tests);
    for(int t = 0; t < tests; ++ t)
    {
        scanf("%d", &companies);
        wMin = hMin = 1000000001;
        wMax = hMax = 0;
        for(int c = 0; c < companies; ++ c)
        {
            scanf("%d %d %d %d", &ws[c], &we[c], &hs[c], &he[c]);
            wMin = min(ws[c], wMin);
            wMax = max(we[c], wMax);
            hMin = min(hs[c], hMin);
            hMax = max(he[c], hMax);
        }

        puts(check() ? "TAK" : "NIE");
    }
}

inline
bool check(void)
{
    for(int c = 0; c < companies; ++ c)
        if( ws[c] == wMin
        &&  we[c] == wMax
        &&  hs[c] == hMin
        &&  he[c] == hMax)
            return true;

    return false;
}