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
#include <iostream>
#include <algorithm>
#include <cassert>

using namespace std;

int main()
{
	ios::sync_with_stdio( false );
	cin.tie( nullptr );

	unsigned t;
	cin >> t;

	while( t-- )
	{
		unsigned n;
		cin >> n;

		unsigned minWidth, maxWidth, minHeight, maxHeight;
		cin >> minWidth >> maxWidth >> minHeight >> maxHeight;
		
		bool result;
		bool wasRecordSet = true;

		while( --n )
		{
			unsigned w1, w2, h1, h2;
			cin >> w1 >> w2 >> h1 >> h2;

			assert( w2 >= w1 );
			assert( h2 >= h1 );

			result = ( w1 >= minWidth && w2 <= maxWidth && h1 >= minHeight && h2 <= maxHeight )
				||   ( w1 <= minWidth && w2 >= maxWidth && h1 <= minHeight && h2 >= maxHeight );
			if( result && ( w1 <= minWidth && w2 >= maxWidth && h1 <= minHeight && h2 >= maxHeight ) )
			{
				wasRecordSet = true;
			}
			else if( result == false )
			{
				wasRecordSet = false;
			}
	
			minWidth = std::min( w1, minWidth );
			maxWidth = std::max( w2, maxWidth );
			minHeight = std::min( h1, minHeight );
			maxHeight = std::max( h2, maxHeight );
		}
		cout << ( wasRecordSet && result ? "TAK\n" : "NIE\n" );
	}

	return 0;
}