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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Author: Dominik Wójt */
/* Problem: Lustra, Potyczki Algorytmiczne 2014 */

#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>

#define MY_ASSERT( condition ) \
    do \
    { \
        if( !( condition ) ) \
        { \
            std::cerr << "assert failed: " << #condition << std::endl; \
            std::abort(); \
        } \
    } \
    while(false)

typedef long int lint;
//------------------------------------------------------------------------------
template<typename T>
T checked_read( const T min, const T max )
{
    T n;
    std::cin >> n;
    MY_ASSERT( std::cin );
    MY_ASSERT( min<=n && n<=max );
    return n;
}
//------------------------------------------------------------------------------
int main()
{
    const int t = checked_read<int>( 1, 10 );

    for( int i=0; i<t; i++ )
    {
        const lint n = checked_read<lint>( 1, 100000 );

        int min_w = 1000000000;
        int max_W = 1;
        int min_h = 1000000000;
        int max_H = 1;

        int major_w = 1000000000;
        int major_W = 1;
        int major_h = 1000000000;
        int major_H = 1;

        for( lint j=0; j<n; j++ )
        {
            const int w = checked_read<lint>( 1, 1000000000 );
            const int W = checked_read<lint>( 1, 1000000000 );
            const int h = checked_read<lint>( 1, 1000000000 );
            const int H = checked_read<lint>( 1, 1000000000 );
            MY_ASSERT( w <= W );
            MY_ASSERT( h <= H );

            min_w = std::min( w, min_w );
            max_W = std::max( W, max_W );
            min_h = std::min( h, min_h );
            max_H = std::max( H, max_H );

            if( w == min_w && max_W == W && h == min_h && max_H == H )
            {
                major_w = w;
                major_W = W;
                major_h = h;
                major_H = H;
            }
        }

        if( major_w == min_w && max_W == major_W &&
            major_h == min_h && max_H == major_H )
        {
            std::cout << "TAK\n";
        }
        else
        {
            std::cout << "NIE\n";
        }
    }

    return 0;
}