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
/* 
 * File:   lustra.cpp
 * Author: Kamila
 *
 * Created on 12 maj 2014, 21:05
 */

#include <iostream>
#include <algorithm>

using namespace std;

/*
 * 
 */
int main() {
    int t, n;
    int min_w, min_h, max_w, max_h;
    int min_szer, min_wys, max_szer, max_wys;
    bool faworyt;
    
    ios_base::sync_with_stdio(0);
    cin >> t;
    while (t--){
        cin >> n;
        cin >> min_w >> max_w >> min_h >> max_h;
        min_szer = min_w;
        max_szer = max_w;
        min_wys = min_h;
        max_wys = max_h;
        faworyt = true;
        while (--n){
          cin   >> min_w >> max_w >> min_h >> max_h;
          if (min_w <= min_szer && max_w >= max_szer && min_h <= min_wys && max_h >= max_wys){
             min_szer = min_w;
             max_szer = max_w;
             min_wys = min_h;
             max_wys = max_h; 
             faworyt = true;
		  }
          else if (min_w < min_szer || max_w > max_szer || min_h < min_wys || max_h > max_wys){
              min_szer = min(min_w, min_szer);
              min_wys = min(min_h, min_wys);
              max_szer = max(max_w, max_szer);
              max_wys = max(max_h, max_wys);
              faworyt = false;
          }
              
        }
        if (faworyt){
            cout << "TAK" << endl;
        } else{
            cout << "NIE" << endl;
        }
   }
}