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
#include <stdio.h>

int main(){
  int testCount = 0;
  int worksCount = 0;
  bool found = false;

  // check data
  unsigned widthMin = 0;
  unsigned widthMax = 0;
  unsigned heightMin = 0;
  unsigned heightMax = 0;

  // input data
  unsigned wMin = 0;
  unsigned wMax = 0;
  unsigned hMin = 0;
  unsigned hMax = 0;

  scanf("%d", &testCount);
  for( int t = 0; t < testCount; ++t){
    
    scanf("%d", &worksCount);
    scanf("%u %u %u %u", &wMin, &wMax, &hMin, &hMax);
    found = true;

    widthMin = wMin;
    widthMax = wMax;
    heightMin = hMin;
    heightMax = hMax;
    
    for( int i = 1; i < worksCount; ++i ){
      
      scanf("%u %u %u %u", &wMin, &wMax, &hMin, &hMax);

      if( ( wMin <= widthMin ) && ( wMax >= widthMax ) && ( hMin <= heightMin ) && ( hMax >= heightMax ) ){
        found = true;
        widthMin = wMin;
        widthMax = wMax;
        heightMin = hMin;
        heightMax = hMax;
      } else {
        if( wMin < widthMin ){
          widthMin = wMin;
          found = false;
        }

        if( wMax > widthMax ){
          widthMax = wMax;
          found = false;
        }

        if( hMin < heightMin ){
          heightMin = hMin;
          found = false;
        }

        if( hMax > heightMax ){
          heightMax = hMax;
          found = false;
        }
     } ;
    };
    if( found )
      printf("TAK\n");
    else
      printf("NIE\n");
  };
  return 0;
};