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
import java.io.IOException;
import java.io.InputStream;

public class lus {
    private static int skipWS(final InputStream in) throws IOException {
		int val = -1;
		while ((val = in.read()) != -1) {
			if (!Character.isWhitespace((char) val)) break;
		}
		return val;
	}

	private static int readInt(final InputStream in) {
		try {
			final StringBuilder b = new StringBuilder();
			int val = skipWS(in);
			b.append((char) val);
			while ((val = in.read()) != -1) {
				if (Character.isWhitespace((char) val))
					break;
				b.append((char) val);
			}
			return Integer.parseInt(b.toString());
		} catch (final IOException e) {
			throw new RuntimeException(e);
		}
	}

	public static void main(String[] args) throws Exception {
    	final int t = readInt(System.in);
    	int n;
    	for (int i = 0; i < t; i++) {
    		n = readInt(System.in);
    		doCase(n);
    	}
	}

	private static void doCase(int n) {
		int wMin = Integer.MAX_VALUE, wMax = 0, hMin = Integer.MAX_VALUE, hMax = 0;
		int reqwMin = Integer.MAX_VALUE, reqwMax = 0, reqhMin = Integer.MAX_VALUE, reqhMax = 0;
		int majorIdx = -1;
		int cwMin, cwMax, chMin, chMax;
		for (int i = 0; i < n; i++) {
			cwMin = readInt(System.in);
			cwMax = readInt(System.in);
			chMin = readInt(System.in);
			chMax = readInt(System.in);
			if (reqwMin > cwMin) reqwMin = cwMin;
			if (reqwMax < cwMax) reqwMax = cwMax;
			if (reqhMin > chMin) reqhMin = chMin;
			if (reqhMax < chMax) reqhMax = chMax;
			if (wMin > reqwMin || wMax < reqwMax || hMin > reqhMin || hMax < reqhMax) majorIdx = -1;
			if (cwMin <= reqwMin && cwMax >= reqwMax && chMin <= reqhMin && chMax >= reqhMax) {
				wMin = cwMin;
				wMax = cwMax;
				hMin = chMin;
				hMax = chMax;
				majorIdx = i;
			}
		}
	    if (majorIdx >= 0) System.out.println("TAK");
	    else System.out.println("NIE");
	}
}