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.InputStreamReader;
import java.util.StringTokenizer;


public class lus {

	public static void main(String[] args) {
		try{
			BufferedReader buffReader = new BufferedReader(new InputStreamReader(System.in));
			int t = Integer.parseInt(buffReader.readLine());
			for(int i=0; i<t; i++){
				int n = Integer.parseInt(buffReader.readLine());
				int minW = Integer.MAX_VALUE;
				int maxW = Integer.MIN_VALUE;
				int minH = Integer.MAX_VALUE;
				int maxH = Integer.MIN_VALUE;
				long maxRange = 0;
				for(int j=0; j<n; j++){
					StringTokenizer tokenizer = new StringTokenizer(buffReader.readLine());
					int plantMinW = Integer.parseInt(tokenizer.nextToken());
					int plantMaxW = Integer.parseInt(tokenizer.nextToken());
					int plantMinH = Integer.parseInt(tokenizer.nextToken());
					int plantMaxH = Integer.parseInt(tokenizer.nextToken());
					minW = plantMinW < minW ? plantMinW : minW;
					maxW = plantMaxW > maxW ? plantMaxW : maxW;
					minH = plantMinH < minH ? plantMinH : minH;
					maxH = plantMaxH > maxH ? plantMaxH : maxH;
					long plantRange = (long)(plantMaxW - plantMinW + 1)*(plantMaxH - plantMinH + 1);
					maxRange = plantRange > maxRange ? plantRange : maxRange; 
				}
				long range = (long)(maxW - minW + 1)*(maxH - minH + 1);
				if(maxRange < range)
					System.out.println("NIE");
				else
					System.out.println("TAK");
			}
		}catch(Exception e){
			e.printStackTrace();
		}

	}

}