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
import java.util.Scanner;

public class lus {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        String[] output = new String[t];
        int n;
        int w1, w2, h1, h2;
        boolean answ;
        int leftW;
        int rightW;
        int bottomH;
        int topH;
        int i;
       for(i=0;i<t;i++){
            n = sc.nextInt();
           answ = false;
           leftW = 1000000000;
           rightW = 0;
           bottomH = 1000000000;
           topH = 0;
            while(n>0){
                w1 = sc.nextInt();
                w2 = sc.nextInt();
                h1 = sc.nextInt();
                h2 = sc.nextInt();
                if (w1<=leftW && w2>=rightW && h1<=bottomH && h2>=topH){
                    answ = true;
                } else if(!(w1>=leftW && w2<=rightW && h1>=bottomH && h2<=topH)){
                    answ = false;
                }
                leftW = Math.min(leftW, w1);
                rightW = Math.max(rightW, w2);
                bottomH = Math.min(bottomH, h1);
                topH = Math.max(topH, h2);
                n--;
            }
            if (answ){
                output[i] = "TAK";
            } else{
                output[i] = "NIE";
            }

        }

        for(i=0;i<t;i++){
            System.out.println(output[i]);
        }


    }


}