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
#include <cstdio>

struct Mirror
{
    int h1, h2, w1, w2;
    
    Mirror (int a = 0, int b = 0, int c = 0, int d = 0)
    {
        h1 = a;
        h2 = b;
        w1 = c;
        w2 = d;
    }
    
    bool operator== (const Mirror &other)   const
    {
        return ((h1 == other.h1) and (h2 == other.h2) and (w1 == other.w1) and (w2 == other.w2));
    }
    
    void load()
    {
        scanf ("%d%d%d%d", &h1, &h2, &w1, &w2);
    }
};

Mirror T[100000];

int main()
{
    int t;
    
    scanf ("%d", &t);
    
    while (t--)
    {
        int n;
        
        scanf ("%d", &n);
        
        Mirror majorant (1000000001, 0, 1000000001, 0);
        
        for (int i=0; i<n; i++)
        {
            T[i].load();
            
            if (majorant.h1 > T[i].h1)
                majorant.h1 = T[i].h1;
                
            if (majorant.h2 < T[i].h2)
                majorant.h2 = T[i].h2;
                
            if (majorant.w1 > T[i].w1)
                majorant.w1 = T[i].w1;
                
            if (majorant.w2 < T[i].w2)
                majorant.w2 = T[i].w2;
        }
        
        bool res = 0;
        
        for (int i=0; i<n; i++)
        {
            if (T[i] == majorant)
            {
                res = 1;
                break;
            }
        }
        
        res ? printf("TAK\n") : printf("NIE\n");
    }
    
    return 0;
}