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
var
  w1,w2,h1,h2,
  w1m,w2m,h1m,h2m,
  t,n,i,j,k: longint;
  r: boolean;
begin
  read(t);
  repeat
    r:=true;
    read(n);
    read(w1m,w2m,h1m,h2m);
    for i:= 2 to n do
    begin
      read(w1,w2,h1,h2);
      if (w1<w1m)or(w2>w2m)or(h1<h1m)or(h2>h2m)then
        r:=(w1<=w1m)and(w2>=w2m)and(h1<=h1m)and(h2>=h2m);
      //r:=not(((w1<w1m)or(w2>w2m))xor((h1<h1m)or(h2>h2m)));
      if w1<w1m then w1m:=w1;
      if w2>w2m then w2m:=w2;
      if h1<h1m then h1m:=h1;
      if h2>h2m then h2m:=h2;
    end;
    if r then writeln('TAK') else writeln('NIE');
    t-=1;
  until t=0;
end.