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
52
53
#include <cstdlib>
#include <cstdio>
#include <algorithm>

using namespace std;

int lustra[100000][4];

int main() {

    int zestawy;
    scanf("%d", &zestawy);

    for (int i = 0; i < zestawy; ++i) {
        int n;
        scanf("%d", &n);

        int minW, minH, maxW, maxH;

        for (int j = 0; j < n; ++j) {
            int w1, w2, h1, h2;
            scanf("%d%d%d%d", &w1, &w2, &h1, &h2);

            lustra[j][0] = w1;
            lustra[j][1] = w2;
            lustra[j][2] = h1;
            lustra[j][3] = h2;

            if (j == 0) {
                minW = w1;
                maxW = w2;
                minH = h1;
                maxH = h2;
            } else {
                minW = std::min(minW, w1);
                minH = std::min(minH, h1);
                maxW = std::max(maxW, w2);
                maxH = std::max(maxH, h2);
            }
        }

        bool czyIstnieje = false;
        for (int j = 0; j < n; ++j) {
            if (lustra[j][0] <= minW && lustra[j][2] <= minH && lustra[j][1] >= maxW && lustra[j][3] >= maxH) {
                czyIstnieje = true;
                break;
            }
        }
        printf(czyIstnieje ? "TAK\n" : "NIE\n");
    }

    return 0;
}