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
//: Piotr Skotnicki
// Potyczki Algorytmiczne 2014
// LUS
#include <algorithm>
#include <cstdio>
#include <utility>

using namespace std;

#define X first
#define Y second

typedef pair<int, int> PI;

int main()
{
    int t, n;
    PI w, h, rw, rh, bw, bh;

    scanf("%d", &t);
    while (t--)
    {
        scanf("%d", &n);
        scanf("%d %d %d %d", &bw.X, &bw.Y, &bh.X, &bh.Y);
        rw = bw;
        rh = bh;
        bool ok{true};
        while (--n)
        {
            scanf("%d %d %d %d", &w.X, &w.Y, &h.X, &h.Y);
            rw = make_pair(min(rw.X, w.X), max(rw.Y, w.Y));
            rh = make_pair(min(rh.X, h.X), max(rh.Y, h.Y));

            if (w.X <= rw.X && rw.Y <= w.Y && h.X <= rh.X && rh.Y <= h.Y)
            {
                ok = true;
                bw = w;
                bh = h;
            }
            else
            {
                if (rw.X < bw.X || rw.Y > bw.Y || rh.X < bh.X || rh.Y > bh.Y)
                {
                    ok = false;
                }
            }
        }
        printf("%s\n", ok ? "TAK" : "NIE");
    }

    return 0;
}