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
79
80
81
82
#include <cstdio>

using namespace std;

int main()
{
    int w_lowest, w_highest, h_lowest, h_highest;
    int a,          b,          c,         d;
    int t, n;
    bool czy;
    scanf("%d", &t);
    for(int j=0; j<t; ++j)
    {
        scanf("%d", &n);
        scanf("%d%d%d%d", &w_lowest, &w_highest, &h_lowest, &h_highest);
        czy=true;
        for(int i=1; i<n; ++i)
        {
            scanf("%d%d%d%d", &a, &b, &c, &d);
            if(a<w_lowest)
            {
                if(b<w_highest)
                    czy=false;
                else if(c>h_lowest)
                    czy=false;
                else if(d<h_highest)
                    czy=false;
                else czy=true;
            }
            else if(b>w_highest)
            {
                if(a>w_lowest)
                    czy=false;
                else if(c>h_lowest)
                    czy=false;
                else if(d<h_highest)
                    czy=false;
                else czy=true;
            }
            else if(c<h_lowest)
            {
                 if(a>w_lowest)
                    czy=false;
                else if(b<w_highest)
                    czy=false;
                else if(d<h_highest)
                    czy=false;
                else czy=true;
            }
            else if(d>h_highest)
            {
                 if(a>w_lowest)
                    czy=false;
                else if(b<w_highest)
                    czy=false;
                else if(c>h_lowest)
                    czy=false;
                else czy=true;
            }


            else if(a==w_lowest&&b==w_highest&&c==h_lowest&&d==h_highest)
                czy=true;



            if(a<w_lowest)
                w_lowest=a;
            if(b>w_highest)
                w_highest=b;
            if(c<h_lowest)
                h_lowest=c;
            if(d>h_highest)
                h_highest=d;
        }

        if(czy)
            printf("TAK\n");
        else printf("NIE\n");

    }
}