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

public class lus {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int t = s.nextInt();
		for (int i = 0; i < t; i++) {
			int n = s.nextInt() - 1;
			int wm1 = s.nextInt(), wm2 = s.nextInt(), hm1 = s.nextInt(), hm2 = s
					.nextInt();
			boolean is = true;

			while (n-- > 0) {
				int w1 = s.nextInt(), w2 = s.nextInt(), h1 = s.nextInt(), h2 = s
						.nextInt();
				if (w1 >= wm1 && w2 <= wm2 && h1 >= hm1 && h2 <= hm2) {
					continue;
				}
				if (w1 <= wm1 && w2 >= wm2 && h1 <= hm1 && h2 >= hm2) {
					wm1 = w1;
					wm2 = w2;
					hm1 = h1;
					hm2 = h2;
				} else {
					is = false;
				}
			}
			System.out.println(is ? "TAK" : "NIE");
		}
	}

}