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

int main()
{
   int n, p, w1, w2, h1, h2, wb1, wb2, hb1, hb2;
   scanf("%d", &n);
   for(int i = 0; i < n; i++)
   {
      scanf("%d", &p);
      bool isMajor = true;
      scanf("%d", &wb1);
      scanf("%d", &wb2);
      scanf("%d", &hb1);
      scanf("%d", &hb2);
      for(int j = 1; j < p; j++)
      {
         scanf("%d", &w1);
         scanf("%d", &w2);
         scanf("%d", &h1);
         scanf("%d", &h2);

         if(w1 < wb1 || h1 < hb1 || w2 > wb2 || h2 > hb2)
            isMajor = false;

         if(w1 <= wb1 && h1 <= hb1 && w2 >= wb2 && h2 >= hb2)
            isMajor = true;

         if(w1 < wb1)
            wb1 = w1;
         if(h1 < hb1)
            hb1 = h1;
         if(w2 > wb2)
            wb2 = w2;
         if(h2 > hb2)
            hb2 = h2;
      }
      if(isMajor)
         printf("TAK\n");
      else
         printf("NIE\n");
   }
}