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

#define INF 1000000005

int main()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        int n;
        scanf("%d", &n);
        int minw = INF, minh = INF, maxw = 0, maxh = 0;
        bool b = true;
        for (int i=0; i<n; i++)
        {
            int w1, w2, h1, h2;
            scanf("%d%d%d%d", &w1, &w2, &h1, &h2);
            if ((w1 < minw) || (w2 > maxw) || (h1 < minh) || (h2 > maxh))
                b = ((w1 <= minw) && (w2 >= maxw) && (h1 <= minh) && (h2 >= maxh));
            else if ((w1 == minw) && (w2 == maxw) && (h1 == minh) && (h2 == maxh))
                b = true;
            minw = min(minw, w1);
            maxw = max(maxw, w2);
            minh = min(minh, h1);
            maxh = max(maxh, h2);
        }
        printf(b ? "TAK\n" : "NIE\n");
    }
    return 0;
}