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
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;


public class lus {

	public static void main(String[] args) throws IOException {
		
		lus solver = new lus();
		solver.init();
		solver.solve();
	}
	
	private void init() {
		
	}
	
	private static class Mirror {
		int w1,w2,h1,h2;

		public Mirror(int w1, int w2, int h1, int h2) {
			super();
			this.w1 = w1;
			this.w2 = w2;
			this.h1 = h1;
			this.h2 = h2;
		}
		
	}
	
	private void solve() throws IOException { 
		Reader in = new Reader(System.in);
		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		
		for (int t = in.nextInt(); t > 0; t--) {
			int n = in.nextInt();
			Mirror[] ms = new Mirror[n];
			for (int i = 0; i < n; i++) ms[i] = new Mirror(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt());
			
			int w1 = Integer.MAX_VALUE;
			int w2 = 0;
			int h1 = Integer.MAX_VALUE;
			int h2 = 0;
			
			for (Mirror m : ms) {
				w1 = Math.min(w1, m.w1);
				w2 = Math.max(w2, m.w2);
				h1 = Math.min(h1, m.h1);
				h2 = Math.max(h2, m.h2);
			}
			boolean found = false;
			for (Mirror m : ms) {
				if (w1 == m.w1 && w2 == m.w2 && h1 == m.h1 && h2 == m.h2) {
					found = true;
				}
			}
			out.println(found ? "TAK" : "NIE");
		}
		
		out.flush();
		out.close();
	}
	
	private static class Reader {
	    BufferedReader reader;
	    StringTokenizer tokenizer;

	    /** call this method to initialize reader for InputStream */
	    Reader(InputStream input) {
	        reader = new BufferedReader(
	                     new InputStreamReader(input) );
	        tokenizer = new StringTokenizer("");
	    }

	    public void skipLine() throws IOException {
			reader.readLine();
		}

		/** get next word */
	    public String next() throws IOException {
	        while ( ! tokenizer.hasMoreTokens() ) {
	            //TODO add check for eof if necessary
	            tokenizer = new StringTokenizer(
	                   reader.readLine() );
	        }
	        return tokenizer.nextToken();
	    }

	    public int nextInt() throws IOException {
	        return Integer.parseInt( next() );
	    }
	    
	    public double nextDouble() throws IOException {
	        return Double.parseDouble( next() );
	    }
	    
	    public long nextLong() throws IOException {
	    	return Long.parseLong(next());
	    }
	}
}