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
74
program MajorateProgram;

{$mode objfpc}{$H+}

uses
   {$IFDEF UNIX}{$IFDEF UseCThreads}
   cthreads,
   {$ENDIF}{$ENDIF}
   Classes
   { you can add units after this };

Type TLength=Record
       Hi,Lo:Longint;
     End;

     TTab=Array[0..100001] of TLength;

var H,W:TTab;


Function Min(Const A,B:Longint):Longint;
Begin
   If  A<B Then Result:=A Else Result:=B;
End;

Function Max(Const A,B:Longint):Longint;
Begin
   If  A>B Then Result:=A Else Result:=B;
End;

Operator =(A,B:TLength):Boolean;
Begin
   If (A.Lo=B.Lo) And (A.Hi=B.Hi) Then Result:=True Else Result:=False;
End;

Procedure ReadTest;
var Count, Loop:Longint;
    Len, Weg:TLength;

    Procedure ReadRecord;
    Begin
       ReadLn(H[Loop].Lo,H[Loop].Hi, W[Loop].Lo, W[Loop].Hi);
       Len.Lo:=Min(H[Loop].Lo,Len.Lo);
       Len.Hi:=Max(H[Loop].Hi,Len.Hi);
       Weg.Lo:=Min(W[Loop].Lo,Weg.Lo);
       Weg.Hi:=Max(W[Loop].Hi,Weg.Hi);
    End;


    Function Majorate:Boolean;
    var Loop:Longint;
    Begin
       Result:=False;
       For Loop:=1 to Count do
          If (Len=H[Loop]) And (Weg=W[Loop]) Then Begin
             Result:=True;
             Break;
          End;
    End;

Begin
   Len.Lo:=MaxLongInt;   Len.Hi:=0;
   Weg.Lo:=MaxLongInt;   Weg.Hi:=0;
   ReadLn(Count);
   For Loop:=1 to Count do ReadRecord;
   If Majorate  Then WriteLn('TAK') Else WriteLn('NIE');
End;

Var Count,Loop:Longint;
begin
  ReadLn(Count);
  For Loop:=1 to Count do ReadTest;
//  ReadLn;
end.