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


public class lus {

	
	
	private static InputStream in;


	public static void main(String[] args) throws IOException {
		
		in = new BufferedInputStream(System.in);
		
		int t = nextInt();
		
		final int maxN = 100_000;
		
		for (int i = 0; i < t; i++) {
			
			int n = nextInt(); // number of factories
			
			int w1min, w2max, h1min, h2max;
			boolean[] idxw1min, idxw2max, idxh1min, idxh2max;
			
			w1min = h1min = Integer.MAX_VALUE;
			w2max = h2max = -1;
			
			idxw1min = new boolean[maxN]; idxw2max = new boolean[maxN];
			idxh1min = new boolean[maxN]; idxh2max = new boolean[maxN];
			
			int w1, w2, h1, h2;
			
			int idx = 0;
			
			for (int j = 0; j < n; j++) {
				
				w1 = nextInt();
				w2 = nextInt();
				h1 = nextInt();
				h2 = nextInt();
				
				if (w1 < w1min) {
					w1min = w1;
					Arrays.fill(idxw1min, 0, idx, false);
					idxw1min[idx] = true;
				} else if (w1 == w1min) {
					idxw1min[idx] = true;
				}
				
				if (w2 > w2max) {
					w2max = w2;
					Arrays.fill(idxw2max, 0, idx, false);
					idxw2max[idx] = true;
				} else if (w2 == w2max) {
					idxw2max[idx] = true;
				}
				
				if (h1 < h1min) {
					h1min = h1;
					Arrays.fill(idxh1min, 0, idx, false);
					idxh1min[idx] = true;
				} else if (h1 == h1min) {
					idxh1min[idx] = true;
				}
				
				if (h2 > h2max) {
					h2max = h2;
					Arrays.fill(idxh2max, 0, idx, false);
					idxh2max[idx] = true;
				} else if (h2 == h2max) {
					idxh2max[idx] = true;
				}
				
				idx++;
			}
			
			// if there is at least one index which exists in all lists, it is
			// the majoring factory:
			
			boolean found = false;
			
			for (int j = 0; j < n; j++) {
				if (idxw1min[j] && idxw2max[j] && idxh1min[j] && idxh2max[j]) {
					found = true;
					break;
				}
			}
			
			System.out.println(found ? "TAK" : "NIE");
			
		}
		
		in.close();
		
	}
	
	
	private static int nextInt() throws IOException {
	    int ret = 0;
	    boolean dig = false;

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