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

int main()
{
    int minh, maxh, mina, maxa;
    int actminh, actmaxh, actmaxa, actmina;
    bool found = false;

    int t;
    scanf("%d", &t);
    for (int i=0; i<t; i++){
        found = false;
        int x;
        scanf("%d", &x);
        mina = 1000000001;
        minh = 1000000001;
        maxh = 0;
        maxa = 0;

        for (int i=0; i<x; i++){
            scanf("%d %d %d %d", &actmina, &actmaxa, &actminh, &actmaxh);

            if (actmina <= mina && actminh <= minh && actmaxa >= maxa && actmaxh >= maxh) found = true;
            else if (actmina < mina || actminh < minh || actmaxa > maxa || actmaxh > maxh) found = false;

            mina = min (mina, actmina);
            minh = min (minh, actminh);
            maxh = max (maxh, actmaxh);
            maxa = max (maxa, actmaxa);
        }

        if (found) printf("TAK\n");
        else printf("NIE\n");
    }
    return 0;
}