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
#include <stdio.h>


bool processTestCase(int n)
{
    int maj_w1, maj_w2, maj_h1, maj_h2;

    scanf("%d %d %d %d", &maj_w1, &maj_w2, &maj_h1, &maj_h2);

    int min_w1 = maj_w1, max_w2 = maj_w2, min_h1 = maj_h1, max_h2 = maj_h2;
    int w1, w2, h1, h2;

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

        if (w1 <= maj_w1 && w2 >= maj_w2 && h1 <= maj_h1 && h2 >= maj_h2){
            // wariant dominujący
            maj_w1 = w1;
            maj_w2 = w2;
            maj_h1 = h1;
            maj_h2 = h2;
        }

        if (w1 < min_w1)
            min_w1 = w1;
        if (w2 > max_w2)
            max_w2 = w2;
        if (h1 < min_h1)
            min_h1 = h1;
        if (h2 > max_h2)
            max_h2 = h2;
    }

    if (min_w1 >= maj_w1 && max_w2 <= maj_w2 && min_h1 >= maj_h1 && max_h2 <= maj_h2)
        return true;
    else
        return false;
}


int main()
{
    int t, n;

    scanf("%d", &t);
    for (int i=0; i<t; ++i){
        scanf("%d", &n);
        if (processTestCase(n))
            printf("TAK\n");
        else
            printf("NIE\n");
    }

}