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 <stdio.h>

const int MAX_VALUE = 2 * 1000 * 1000 * 1000;

void porownaj(int a, int &b, bool &c, bool &d)
{
    if(a < b)
    {
        b = a;
        d = false;
    }
    else if(a > b)
    {
        c = false;
    }
}

void porownaj2(int a, int &b, bool &c, bool &d)
{
    if(a > b)
    {
        b = a;
        d = false;
    }
    else if(a < b)
    {
        c = false;
    }
}

int main()
{
    int t;
    scanf("%i", &t);
    for(int i = 0; i < t; ++i)
    {
        int n;
        int x1 = MAX_VALUE, x2 = 0, y1 = MAX_VALUE, y2 = 0;
        bool major = true;
        scanf("%i", &n);
        for(int j = 0; j < n; ++j)
        {
            bool major2 = true;
            int a, b, c, d;
            scanf("%i %i %i %i", &a, &b, &c, &d);
            porownaj(a, x1, major2, major);
            porownaj2(b, x2, major2, major);
            porownaj(c, y1, major2, major);
            porownaj2(d, y2, major2, major);
            if(major2) major = true;
        }
        if(major) printf("TAK\n");
        else printf("NIE\n");
    }
    return 0;
}