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

var	minW,maxW,minH,maxH,a,b,c,d,n,j : longint;
	t,i : integer;
	maj : boolean;

begin
	readln(t);
	for i:=1 to t do begin
		readln(n);
		maj:=false;
		minW:=1000000001;
		maxW:=0;
		minH:=1000000001;
		maxH:=0;
		for j:=1 to n do begin
			read(a);
			read(b);
			read(c);
			readln(d);
			if (a<=minW)and(b>=maxW)and(c<=minH)and(d>=maxH) then begin
				maj:=true;
				minW:=a;
				maxW:=b;
				minH:=c;
				maxH:=d;
			end
			else if (a<minW)or(b>maxW)or(c<minH)or(d>maxH) then begin
				maj:=false;
				if a<minW then
					minW:=a;
				if b>maxW then
					maxW:=b;
				if c<minH then
					minH:=c;
				if d>maxH then
					maxH:=d;
			end;
		end;
		if (maj)and(i<t) then writeln('TAK')
		else if (i<t) then writeln('NIE')
		else if (maj) then write('TAK')
		else write('NIE');
	end;
end.