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

using namespace std;

int main()
{
    int t;
    scanf("%i", &t);
    for(int zzz=0; zzz<t; zzz++) {
        int n, w1=1000000000, w2=1, h1=1000000000, h2=1;
        bool stan = false;
        scanf("%i", &n);
        for(int i=0; i<n; i++) {
            int wb1, wb2, hb1, hb2;
            bool b1[4];
            bool b2[4];
            b1[0] = false;
            b1[1] = false;
            b1[2] = false;
            b1[3] = false;
            b2[0] = false;
            b2[1] = false;
            b2[2] = false;
            b2[3] = false;
            scanf("%i %i %i %i", &wb1, &wb2, &hb1, &hb2);
            if(wb1<w1) b1[0] = true;
            if(wb2>w2) b1[1] = true;
            if(hb1<h1) b1[2] = true;
            if(hb2>h2) b1[3] = true;

            if(wb1<=w1) b2[0] = true;
            if(wb2>=w2) b2[1] = true;
            if(hb1<=h1) b2[2] = true;
            if(hb2>=h2) b2[3] = true;

            if(b2[0] && b2[1] && b2[2] && b2[3]) {
                w1 = wb1;
                w2 = wb2;
                h1 = hb1;
                h2 = hb2;
                stan = true;

            }
            else if(b1[0] || b1[1] || b1[2] || b1[3]) {
                if(b1[0]) w1 = wb1;
                if(b1[1]) w2 = wb2;
                if(b1[2]) h1 = hb1;
                if(b1[3]) h2 = hb2;
                stan = false;
            }
        }
        if(stan) printf("TAK\n");
        else printf("NIE\n");
    }
    return 0;
}