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
// Krzysztof Mędrela; potyczki algorytmiczne 2014; Lustra [B]

#include <iostream>
#include <cstdlib>
#include <cstdio>

#define INF 2000000000
#define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) > (y) ? (x) : (y))

using namespace std;

int main() {
        int z; scanf("%d", &z);

        for (int i = 0; i < z; ++i)
        {
                int n; scanf("%d", &n);
                int w1 = INF;
                int w2 = -INF;
                int h1 = INF;
                int h2 = -INF;
                bool majoryzuje = false;

                int w1t, w2t, h1t, h2t;
                for (int j = 0; j < n; ++j)
                {
                        scanf("%d %d %d %d", &w1t, &w2t, &h1t, &h2t);
                        if (w1t < w1 || w2t > w2 || h1t < h1 || h2t > h2) {
                                w1 = min(w1, w1t);
                                w2 = max(w2, w2t);
                                h1 = min(h1, h1t);
                                h2 = max(h2, h2t);
                                majoryzuje = (w1 == w1t && w2 == w2t && h1 == h1t && h2 == h2t);
                        }
                }

                printf(majoryzuje ? "TAK\n" : "NIE\n");
        }
        return 0;
}