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
73
74
75
76
77
78
#include <climits>
#include <cstdio>
#include <vector>
#include <iostream>
#include <tr1/tuple>
#include <cstdlib>
#include <string>
#include <algorithm>

using namespace std;
using namespace std::tr1;


struct algorithm {

    size_t n;
    size_t min_x, min_y, max_x, max_y;
    bool result;
    void read_data()
    {
        min_x = INT_MAX;
        min_y = INT_MAX;
        max_x = 0;
        max_y = 0;
        result = false;
        cin >> n;
        for (size_t x1, y1, x2, y2, i = 1; i < n; ++i)
        {
            cin >> x1 >> x2 >> y1 >> y2;
            if (x1 < min_x)
            {
                result = false;
                x1 = min_x;
            }
            if (x2 > max_x)
            {
                result = false;
                x2 = max_x;
            }
            if (y1 < min_y)
            {
                result = false;
                y1 = min_y;
            }
            if (y2 > max_y)
            {
                result = false;
                y2 = max_y;
            }
            if (x1 == min_x && x2 == max_x && y1 == min_y && y2 == max_y)
            {
                result = true;
            }
        }
    }


    int doit()
    {
        cout << (result ? "TAK" : "NIE") << endl;
    }
};


int main(void)
{
    //freopen("input", "r", stdin);
    size_t n_of_testcases;
    algorithm a;
    cin >> n_of_testcases;
    for (size_t test_idx = 1; test_idx <= n_of_testcases; ++test_idx)
    {
        a.read_data();
        a.doit();
    }

    return 0;
}