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
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;


public class lus {
	
	int testNumber;
	
	int testFactoryNumber[] = new int[11];
	
	int testDimensions[][][] = new int[11][100001][5];
	
	boolean testResults[] = new boolean[11];
	
	void process() {
		for (int i = 1; i <= testNumber; i++) {
			int dimensions[][] = testDimensions[i];
			int factoryNumber = testFactoryNumber[i];
			
			boolean result = processTest(dimensions, factoryNumber);
			testResults[i] = result;
		}
	}
	
	boolean processTest(int dimensions[][], int factoryNumber) {
		int wmin = dimensions[1][1];
		int wmax = dimensions[1][2];
		int hmin = dimensions[1][3];
		int hmax = dimensions[1][4];
		
		boolean dominatorExists = true;
		
		for (int i = 2; i <= factoryNumber; i++) {
			int w1 = dimensions[i][1];
			int w2 = dimensions[i][2];
			int h1 = dimensions[i][3];
			int h2 = dimensions[i][4];
		
			int equalOrOverRange = 0;
			int overRange = 0;
			
			if (w1 <= wmin) {
				equalOrOverRange++;
				if (w1 < wmin) {
					wmin = w1;
					overRange++;
				}
			}

			if (w2 >= wmax) {
				equalOrOverRange++;
				if (w2 > wmax) {
					wmax = w2;
					overRange++;
				}
			}

			if (h1 <= hmin) {
				equalOrOverRange++;
				if (h1 < hmin) {
					hmin = h1;
					overRange++;
				}
			}

			if (h2 >= hmax) {
				equalOrOverRange++;
				if (h2 > hmax) {
					hmax = h2;
					overRange++;
				}
			}
		
			if (equalOrOverRange == 4) {
				dominatorExists = true;
			} else if (overRange > 0 && overRange < 4) {
				dominatorExists = false;
			}
		}
		
		return dominatorExists;
	}
	
	public static void main(String[] args) {
		new lus();
	}
	
	public lus() {
		read();
		process();
		print();
	}
	
	void read() {
		InputStream is = System.in;
//		if (Boolean.getBoolean("test")) {
//			is = lus.class.getResourceAsStream("lus.in.txt");
//		}
		
		BufferedInputStream bis = new BufferedInputStream(is);

		try {
			testNumber = readInt(bis);
			
			for (int i = 1; i <= testNumber; i++) {
				int factoryNumber = readInt(bis);
				testFactoryNumber[i] = factoryNumber;	
				
				for (int j = 1; j <= factoryNumber; j++) {
					testDimensions[i][j][1] = readInt(bis);
					testDimensions[i][j][2] = readInt(bis);
					testDimensions[i][j][3] = readInt(bis);
					testDimensions[i][j][4] = readInt(bis);
				}
			}
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
	
	private int readInt(InputStream in) throws IOException {
		int ret = 0;
		boolean dig = false;

		for (int c = 0; (c = in.read()) != -1;) {
			if (c >= '0' && c <= '9') {
				dig = true;
				ret = ret * 10 + c - '0';
			} else if (dig) {
				break;
			}
		}

		return ret;
	}
	
	void print() {
		for (int i = 1; i <= testNumber; i++) {
			boolean result = testResults[i];
			String resultText = (result)?"TAK":"NIE";
			System.out.println(resultText);
		}
	}
}