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
#include <iostream>
#include <string>

std::string solve()
{
   int w1, w2, h1, h2;
   int minw, maxw, minh, maxh;
   int bestw1, bestw2, besth1, besth2;

   int n;
   std::cin >> n;
   std::cin >> w1 >> w2 >> h1 >> h2;

   bestw1 = minw = w1;
   bestw2 = maxw = w2;
   besth1 = minh = h1;
   besth2 = maxh = h2;

   for(int i = 1; i < n; ++i ) {
      std::cin >> w1 >> w2 >> h1 >> h2;
      minw = std::min(minw, w1);
      maxw = std::max(maxw, w2);
      minh = std::min(minh, h1);
      maxh = std::max(maxh, h2);

      if( w1 <= bestw1 && bestw2 <= w2 && h1 <= besth1 && besth2 <= h2 ) {
         bestw1 = w1;
         bestw2 = w2;
         besth1 = h1;
         besth2 = h2;
      } 
   }

   if( bestw1 <= minw && maxw <= bestw2 && besth1 <= minh && maxh <= besth2 ) {
      return "TAK";
   }
   return "NIE";
}

int main()
{
   std::cin.sync_with_stdio(false);

   int t;
   std::cin >> t;
   while( --t >= 0 ) {
      std::cout << solve() << std::endl;
   }
   return 0;
}