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
57
58
59
60
61
62
63
64
65
66
67
68
#include<iostream>
#include<algorithm>

using namespace std;

struct Oferta
{
    int a;
    int b;
    int c;
    int d;
};

bool cmp(Oferta o1,Oferta o2)
{
    return (o1.a <= o2.a && o1.b >= o2.b && o1.c <= o2.c && o1.d >= o2.d);
}

int main()
{
    Oferta *o;
    int t, n, ma = 1500000000, mb = 0, mc = 1500000000, md = 0;
    cin>>t;

    while(t--)
    {
        scanf("%d", &n);

        o = new Oferta[100000];

        ma = 1500000000;
        mb = 0;
        mc = 1500000000;
        md = 0;

        for(int i = 0;i < n;i++)
        {
            cin>>o[i].a>>o[i].b>>o[i].c>>o[i].d;
        }

        sort(o, o+n, cmp);

        for(int i = 0;i < n;i++)
        {
            if(o[i].a < ma)
                ma = o[i].a;
            if(o[i].b > mb)
                mb = o[i].b;
            if(o[i].c < mc)
                mc = o[i].c;
            if(o[i].d > md)
                md = o[i].d;
        }

        if(o[0].a == ma && o[0].b == mb && o[0].c == mc && o[0].d == md)
            puts("TAK");
        else
            puts("NIE");



        printf("%d %d %d %d", o[0].a, o[0].b, o[0].c, o[0].d);
        delete [] o;


    }
    return 0;
}