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
#include <cstdio>


using namespace std;


int w1[100000];
int w2[100000];
int h1[100000];
int h2[100000];


int main()
{
    int n, t;
    int wmin, wmax, hmin, hmax;
    bool czy;
    
    
    scanf("%d", &t);
    
    
    for(int i = 0; i < t; i++)
      {
            scanf("%d", &n);
            
            wmin = hmin = 1000000000;
            hmax = wmax = 0;
            
            for(int i = 0; i < n; i++)
              {
                    scanf("%d %d %d %d", &w1[i], &w2[i], &h1[i], &h2[i]);
                    
                    if(w1[i] < wmin)
                      wmin = w1[i];
                    
                    if(w2[i] > wmax)
                      wmax = w2[i];
                    
                    if(h1[i] < hmin)
                      hmin = h1[i];
                    
                    if(h2[i] > hmax)
                      hmax = h2[i];
              }
            
            czy = false;
            
            for(int i = 0; i < n; i++)
              {
                  if((w1[i] <= wmin) && (w2[i] >= wmax) && (h1[i] <= hmin) && (h2[i] >= hmax))
                    {
                        czy = true;
                        break;
                    }
              }
            
            if(czy)
              printf("TAK\n");
            
            else
              printf("NIE\n");
      }
    
    
    

    return 0;
}