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

int main()
{
    int t,n;
    int w1,w2,h1,h2;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        int ga,gb,gc,gd;
        scanf("%d%d%d%d",&ga,&gb,&gc,&gd);
        int ok = 1;
        for(int i=1;i<n;++i)
        {
            scanf("%d%d%d%d",&w1,&w2,&h1,&h2);
            if (w1<=ga && w2>=gb && h1<=gc && h2>=gd)
            {
                ok = 1;
                ga=w1;
                gb=w2;
                gc=h1;
                gd=h2;
            }
            else if(w1<ga || w2>gb || h1<gc || h2>gd)
            {
                ok = 0;
                ga=min(ga,w1);
                gb=max(gb,w2);
                gc=min(gc,h1);
                gd=max(gd,h2);
            }
        }
        printf("%s\n",ok ? "TAK" : "NIE");

    }

    return 0;
}