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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class lus
{

    public static boolean isBest(int[] maxes, int[] candidate)
    {
        if (candidate == null) return false;
        return Arrays.equals(maxes, candidate);
    }

    public static boolean solveCase(BufferedReader br) throws IOException
    {
        int n = Integer.parseInt(br.readLine());
        int[] best = null;
        int[] maxes = new int[]{Integer.MAX_VALUE, 0, Integer.MAX_VALUE, 0};
        while (n-- > 0)
        {
            String[] l = br.readLine().split(" ");
            int[] news = new int[l.length];
            for (int i=0;i<news.length;i++) {
                news[i] = Integer.parseInt(l[i]);
            }
            maxes[0] = Math.min(news[0], maxes[0]);
            maxes[1] = Math.max(news[1], maxes[1]);
            maxes[2] = Math.min(news[2], maxes[2]);
            maxes[3] = Math.max(news[3], maxes[3]);
            if (isBest(maxes, news)) best = news;
            else if (!isBest(maxes, best)) best = null;
        }
        return best != null;
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        while (t-- > 0) {
            if (solveCase(br)) {
                System.out.println("TAK");
            } else {
                System.out.println("NIE");
            }
        }
        System.out.flush();
    }
}