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


public class lus {
	// by asokoly
	private static int skipWhitespace(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) {
		final StringBuilder b = new StringBuilder();
		try {
			int val = skipWhitespace(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);
		}
	}
	// by asokoly */

	public static void run(final InputStream in, PrintStream out) {
		int t = readInt(in);
		for (int i = 0; i < t; i++) {
			int n = readInt(in);			
			int wmin = Integer.MAX_VALUE, wmax = 0, hmin = Integer.MAX_VALUE, hmax = 0;
			boolean res = false;
			for(int k = 0; k < n; k++)
			{
				int w1 = readInt(in);
				int w2 = readInt(in);
				int h1 = readInt(in);
				int h2 = readInt(in);
				if (w1<wmin) {
					wmin = w1;
					res = false;
				}
				if (w2>wmax) {
					wmax= w2;
					res = false;
				}
				if (h1<hmin) {
					hmin = h1;
					res = false;
				}
				if (h2>hmax) {
					hmax= h2;
					res = false;
				}
				if (w1<=wmin && w2>=wmax && h1<=hmin && h2>=hmax)
				{
					res = true;
				}				
			}
			out.println(res ? "TAK" : "NIE");
		}
	}

	public static void main(String[] args) {
		run(System.in, System.out);
	}
}