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
#include <iostream>
#include <math.h>
#include <fstream>
#include <stdio.h>

using namespace std;
int main(int argc, char *argv[])
{

	int iloscPetli=0;
	scanf("%d", &iloscPetli);

	for (int i = 0; i < iloscPetli; ++i)
	{
		int iloscFirm=0;
		scanf("%d", &iloscFirm);
		int w1best=0, w1index=0;
		int w2best=0, w2index=0;
		int h1best=0, h1index=0;
		int h2best=0, h2index=0;
		bool indexRowny = false;
		bool isMajor = false;
		int w1=0, w2=0, h1=0, h2=0;
		
		
		for (int firma = 0; firma < iloscFirm; firma++)
		{
			if (firma == 0)
			{
				scanf("%d %d %d %d", &w1best, &w2best, &h1best, &h2best);
			}
			else
			{
				scanf("%d %d %d %d", &w1, &w2, &h1, &h2);
				if (w1 < w1best)
				{
					w1best = w1;
					w1index = firma;
				}
				if (w2best < w2)
				{
					w2best = w2;
					w2index = firma;
				}
				if (h1 < h1best)
				{
					h1best = h1;
					h1index = firma;
				}
				if (h2best < h2)
				{
					h2best = h2;
					h2index = firma;
				}
			}
			if ((w1index == w2index) && (w2index == h1index) && (h1index == h2index))
			{
				isMajor = true;
			}
			else isMajor = false;
			if (w1 == w1best && w2 == w2best && h1 == h1best && h2 == h2best)
			{
				indexRowny = true;
			}
		}

		if (isMajor || indexRowny) 
		cout << "TAK" << endl;
		else cout << "NIE" << endl;
	}
	return 0;
}