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
program lus(input,output);

const
    maxdim = 1000000000;

var
   nt, it :integer;
   nof, iof :longint;
   minw, maxw, minh, maxh :longint;
   loww, highw, lowh, highh : longint;
   major : boolean;

begin
   readln(nt);

   for it := 1 to nt do
     begin
       minw := maxdim;
       maxw := 0;
       minh := maxdim;
       maxh := 0;
       readln(nof);
       for iof := 1 to nof do
         begin
           readln(loww, highw, lowh, highh);
           if (loww < minw) then
             begin
               minw := loww;
               major := false
             end;
           if (highw > maxw) then
             begin
               maxw := highw;
               major := false
             end;
           if (lowh < minh) then
             begin
               minh := lowh;
               major := false
             end;
           if (highh > maxh) then
             begin
               maxh := highh;
               major := false
             end;
           if ((loww = minw) and (highw = maxw) and
               (lowh = minh) and (highh = maxh)) then major := true;


         end;

         if (major) then writeln('TAK')
                    else writeln('NIE');

     end

end.