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


public class lus {
	
    public static void main(String[] args) throws IOException {
    	BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer tokenizer;
    	
    	tokenizer = new StringTokenizer(reader.readLine());
    	int t = Integer.parseInt(tokenizer.nextToken());
    	
    	for(int num = 0; num < t; num++) {
    		boolean isMajorized = false;
    		int minw = Integer.MAX_VALUE;
    		int maxw = Integer.MIN_VALUE;
    		int minh = Integer.MAX_VALUE;
    		int maxh = Integer.MIN_VALUE;
    		tokenizer = new StringTokenizer(reader.readLine());
        	int n = Integer.parseInt(tokenizer.nextToken());
    		for(int i = 0; i < n; i++) {
    			tokenizer = new StringTokenizer(reader.readLine());
    			int w1 = Integer.parseInt(tokenizer.nextToken());
    			int w2 = Integer.parseInt(tokenizer.nextToken());
    			int h1 = Integer.parseInt(tokenizer.nextToken());
    			int h2 = Integer.parseInt(tokenizer.nextToken());
    			if(w1 <= minw && maxw <= w2 && h1 <= minh && maxh <= h2) {
    				isMajorized = true;
    			} else if(w1 < minw || maxw < w2 || h1 < minh || maxh < h2){
    				isMajorized = false;
    			}
    			minw = Math.min(minw, w1);
    			maxw = Math.max(maxw, w2);
    			minh = Math.min(minh, h1);
    			maxh = Math.max(maxh, h2);
    		}
    		System.out.println(isMajorized ? "TAK" : "NIE");
    	}
    }
}