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
#include <cstdlib>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <climits>
#include <cstdio>
#include <algorithm>

using namespace std;

struct Offer {
  int minW, maxW, minH, maxH;
  Offer() : minW(0), maxW(0), minH(0), maxH(0) { }
  Offer(int const &minW, int const &maxW, int const &minH, int const &maxH)
       : minW(minW), maxW(maxW), minH(minH), maxH(maxH) { }
  ~Offer() { }
  
  void scan(void) {
    scanf("%d %d %d %d", &minW, &maxW, &minH, &maxH);
  }
  
  bool operator==(Offer const &o) const {
    return (minW == o.minW and maxW == o.maxW
         and minH == o.minH and maxH == o.maxH);
  }
};


void test(void) {
  static Offer offers[131072];
  int n;
  
  scanf("%d", &n);
  
  Offer majorant(INT_MAX, 0, INT_MAX, 0);
  
  for(int i = 0; i < n; ++i) {
    Offer &o = offers[i];
    o.scan();
    majorant.minW = min(majorant.minW, o.minW);
    majorant.maxW = max(majorant.maxW, o.maxW);
    majorant.minH = min(majorant.minH, o.minH);
    majorant.maxH = max(majorant.maxH, o.maxH);
  }
  
  bool majorantExists = false;
  
  for(int i = 0; i < n and (not majorantExists); ++i) {
    if(offers[i] == majorant) {
      majorantExists = true;
    }
  }
  
  printf(majorantExists ? "TAK\n" : "NIE\n");
}


int main(int const /*argc*/, char const * const * const /*argv*/) {
  int t;
  
  scanf("%d", &t);
  
  while(t --> 0) {
    test();
  }
  
  return EXIT_SUCCESS;
}