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
//Autor: Mateusz Wasylkiewicz
//Zawody: Potyczki Algorytmiczne 2014
//Strona: http://potyczki.mimuw.edu.pl/
//Zadanie: Lustra, runda 1B
//Czas: Theta(t*n)
#include <iostream>
using namespace std;

#define REP(x, n) for (int x = 0; x < (n); x++)

struct Lustro
{
	int w1, w2, h1, h2;
	
	inline friend istream& operator >> (istream& wejscie, Lustro& dane)
	{
		wejscie >> dane.w1 >> dane.w2 >> dane.h1 >> dane.h2;
		return wejscie;
	}
};

const int MAX = 100010, INF = 1500000000;
int n;
Lustro lus[MAX];

void wczytaj_dane()
{
	cin >> n;
	REP(i, n)
		cin >> lus[i];
}

void znajdz_maksima(int& min_w, int& max_w, int& min_h, int& max_h)
{
	min_w = lus[0].w1;
	max_w = lus[0].w2;
	min_h = lus[0].h1;
	max_h = lus[0].h2;
	
	REP(i, n)
	{
		min_w = min(min_w, lus[i].w1);
		max_w = max(max_w, lus[i].w2);
		min_h = min(min_h, lus[i].h1);
		max_h = max(max_h, lus[i].h2);
	}
}

inline bool szafa_gra(const Lustro& pom, int min_w, int max_w, int min_h, int max_h)
{
	return pom.w1 == min_w && pom.w2 == max_w && pom.h1 == min_h && pom.h2 == max_h;
}

bool zrob_test()
{
	wczytaj_dane();
	int min_w, max_w, min_h, max_h;
	znajdz_maksima(min_w, max_w, min_h, max_h);
	REP(i, n)
		if (szafa_gra(lus[i], min_w, max_w, min_h, max_h))
			return true;
	return false;
}

int main()
{
	ios_base::sync_with_stdio(0);
	int t;
	cin >> t;
	while (t--)
		cout << (zrob_test() ? "TAK\n" : "NIE\n");
	return 0;
}