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

 using namespace std;

 int main()
 {ios_base::sync_with_stdio(0);
long long int t, t2, x, x2, x1, y, y2, y1, y22, x22;
 cin >> t;
 bool a = false;
 for(int i = 0; i < t; i++)
 {
     cin >> t2;
     x = 999999999; x22 = 0; y = 999999999; y22 = 0;
     for(int i = 0; i < t2; i++)
     {
         cin >> x1 >> x2 >> y1 >> y2;
         if((x1 <=  x)&&(x2 >= x22)&&(y1 <=  y)&&(y2 >= y22)) a = true;
         else if(((x1 <  x)||(x2 > x22)||(y1 < y)||(y2 > y22))) a = false;
     x = x1 <= x? x1:x;
      x22 = x2 >= x22? x2:x22;
       y = y1 <= y? y1:y;
        y22 = y2 >= y22? y2:y22;


     }
  cout << (a!=true?"NIE\n":"TAK\n");
 }
 }