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

int main(int argc,char *argv[]) {
   int t;
   scanf("%d",&t);

   while (t--) {
     int n;
     int w1,w2,h1,h2;
     int mw1,mw2,mh1,mh2;
     bool sat = true;

     scanf("%d",&n);
     scanf("%d %d %d %d",&mw1,&mw2,&mh1,&mh2);

     while (--n) {
       scanf("%d %d %d %d",&w1,&w2,&h1,&h2);

       if (w1 <= mw1 && w2 >= mw2 && h1 <= mh1 && h2 >= mh2) {
         sat = true;
         mw1= w1;
         mw2= w2;
         mh1 = h1;
         mh2 = h2;
         continue;
       }

       if (w1 >= mw1 && w2 <= mw2 && h1 >= mh1 && h2 <= mh2) {
         continue;
       }

       sat = false;
       if (w1 < mw1) {
         mw1 = w1;
       }
       if (w2 > mw2) {
         mw2 = w2;
       }
       if (h1 < mh1) {
         mh1 = h1;
       }
       if (h2 > mh2) {
         mh2 = h2;
       }
     }
     printf("%s\n",sat?"TAK":"NIE");
   }

   return 0;
}