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
program lustra;

uses
	Math;

var
	i, numtc, tc, na: LongInt;
	w_big_range: array [1..2] of LongInt;
	h_big_range: array [1..2] of LongInt;
	big_area: Int64 = 0;
	w_total_range: array [1..2] of LongInt;
	h_total_range: array [1..2] of LongInt;
	w1, w2, h1, h2: LongInt;
	area: Int64;
	res: Boolean;
	res_str: String;

begin
	Read(numtc);
	for tc := 1 to numtc do
	begin
		Read(na);

		big_area := 0;
		w_total_range[1] := 2000000000;
		w_total_range[2] := 0;
		h_total_range[1] := 2000000000;
		h_total_range[2] := 0;

		for i := 0 to na-1 do
		begin
			Read(w1, w2, h1, h2);

			w_total_range[1] := min(w_total_range[1], w1);
			w_total_range[2] := max(w_total_range[2], w2);
			h_total_range[1] := min(h_total_range[1], h1);
			h_total_range[2] := max(h_total_range[2], h2);

			area := (w2 - w1) * (h2 - h1);
			if big_area < area then
			begin
				big_area := area;
				w_big_range[1] := w1;
				w_big_range[2] := w2;
				h_big_range[1] := h1;
				h_big_range[2] := h2;
			end;
		end;

		res := True;
		for i := 1 to 2 do
			res := res and (w_big_range[i] = w_total_range[i]) and (h_big_range[i] = h_total_range[i]);
		if res then
			Writeln('TAK')
		else
			Writeln('NIE');
	end;
end.