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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* 
 * File:   lus.cpp
 * Author: wukat
 *
 * Created on 13 maj 2014, 10:08
 */

#include <cstdlib>
#include <iostream>

using namespace std;

struct lus {
    unsigned long int w1;
    unsigned long int w2;
    unsigned long int h1;
    unsigned long int h2;
};

bool compareTwoMirrors(struct lus first, struct lus second) {
    return (first.w1 <= second.w1 && first.w2 >= second.w2 && first.h1 <= second.h2 && first.h2 >= second.h2);
}

void testSingleInput(struct lus &toCover, bool &isCovered) {
    struct lus temp;
    cin >> temp.w1 >> temp.w2 >> temp.h1 >> temp.h2;
    
    if (temp.w1 < toCover.w1 || toCover.w1 == 0) {
        toCover.w1 = temp.w1;
        isCovered = false;
    }
    if (temp.w2 > toCover.w2 || toCover.w1 == 0) {
        toCover.w2 = temp.w2;
        isCovered = false;
    }
    if (temp.h1 < toCover.h1 || toCover.w1 == 0) {
        toCover.h1 = temp.h1;
        isCovered = false;
    }
    if (temp.h2 > toCover.h2 || toCover.w1 == 0) {
        toCover.h2 = temp.h2;
        isCovered = false;
    }
    
    if (!isCovered && compareTwoMirrors(temp, toCover)) {
        isCovered = true;
    }
}

void doTestCase() {
    unsigned long int n;
    cin >> n;
    struct lus toCover = {0, 0, 0, 0};
    bool isCovered = false;
    for (unsigned long int i = 0; i < n; i++) {
        testSingleInput(toCover, isCovered);
    }
    if (isCovered)
        cout << "TAK\n";
    else
        cout << "NIE\n";
}

int main(int argc, char** argv) {

    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        doTestCase();
    }
    return 0;
}