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
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <cstdio>

#define MIN(a,b) ((a) < (b)) ? (a) : (b)
#define MAX(a,b) ((a) > (b)) ? (a) : (b)

int main(void) {
        int t;
        scanf("%d", &t);
        for (int i = 0; i < t; i++)
        {
                int n;
                bool p = false;
                uint32_t pw1 = 1000000001, pw2 = 0, ph1 = 1000000001, ph2 = 0;
                uint32_t rw1 = 1000000001, rw2 = 0, rh1 = 1000000001, rh2 = 0;
                scanf("%d", &n);
                for (int j = 0; j < n; j++)
                {
                    uint32_t w1, w2, h1, h2;
                    scanf("%" SCNu32 "%" SCNu32 "%" SCNu32 "%" SCNu32, &w1, &w2, &h1, &h2);
                    if (w1 < pw1 || h1 < ph1 || w2 > pw2 || h2 > ph2)
                    {
                        p = false;
                        if (w1 <= rw1 && h1 <= rh1 && w2 >= rw2 && h2 >= rh2)
                        {
                            p = true;
                            rw1 = pw1 = w1;
                            rh1 = ph1 = h1;
			    rw2 = pw2 = w2;
			    rh2 = ph2 = h2;
                        }
                        else
                        {
                            rw1 = MIN(w1, rw1);
                            rh1 = MIN(h1, rh1);
                            rw2 = MIN(w2, rw2);
                            rh2 = MIN(h2, rh2);
                        }
                    }
                }
                printf("%s\n", p ? "TAK" : "NIE");
        }
        return 0;
}