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
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <set>
#include <math.h>
#include <queue>

#define INF 1000000007
#define MAXN 100002

using namespace std;



int main()
{
  
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  
  int T;
  cin >> T;
  
  int* w1 = new int[MAXN];
  int* w2 = new int[MAXN];
  int* h1 = new int[MAXN];
  int* h2 = new int[MAXN];
  
  for(int test = 0; test < T; test++)
  {
    int N;
    cin >> N; 
    
    int minWidth = INF;
    int maxWidth = -1;
    int minHeight = INF;
    int maxHeight = -1;
    
    for(int i = 0; i < N; i++)
    {
      cin >> w1[i] >> w2[i] >> h1[i] >> h2[i];
      
      minWidth = min(minWidth, w1[i]);
      maxWidth = max(maxWidth, w2[i]);
      minHeight = min(minHeight, h1[i]);
      maxHeight = max(maxHeight, h2[i]);
    }
    
    bool isOk = false;
    for(int i = 0; i < N; i++)
    {
      if(w1[i] <= minWidth && maxWidth <= w2[i] &&
         h1[i] <= minHeight && maxHeight <= h2[i])
      {
        isOk = true;
      }
    }    
    
    if(isOk)
      cout << "TAK";
    else
      cout << "NIE";
    
    if(test != T - 1)
      cout << "\n";
    
  }
  
  return 0;
}