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
#include <algorithm>
#include <cstdio>
using namespace std;

struct mirror
{
    mirror()
    { 
    }
    
    mirror(int w1, int w2, int h1, int h2) :
        w1_(w1), w2_(w2), h1_(h1), h2_(h2)
    {
    }
    
    bool operator<= (const mirror& mir) const
    {
        return w1_ <= mir.w1_ and w2_ >= mir.w2_ 
                and h1_ <= mir.h1_ and h2_ >= mir.h2_;
    }
    
    mirror &operator |=(const mirror& mir)
    {
        w1_ = min(w1_, mir.w1_);
        w2_ = max(w2_, mir.w2_);
        h1_ = min(h1_, mir.h1_);
        h2_ = max(h2_, mir.h2_);
    }
    
private:
    int w1_, w2_, h1_, h2_;
};

mirror getMirror()
{
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    return mirror(a, b, c , d);
}

int main()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        int n;
        scanf("%d", &n);
        mirror base = getMirror();
        bool result = true;
        while (--n)
        {
            mirror next = getMirror();
            if ( not (next <= base) and not (base <= next))
            {
                result = false;
                base |= next;
            }
            if (next <= base)
            {
                base = next;
                result = true;
            }
        }
        printf("%s\n", result ? "TAK" : "NIE");
    }
}