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
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

int main() {
    int t;
    cin>>t;
    for(int i = 0; i < t; i++) {
	bool res = true;
	vector <pii> befA;
	vector <pii> befB;
	vector <pii> aftA;
	vector <pii> aftB;
	int n,w;
	cin>>n>>w;
	for(int j = 0; j < n; j++) {
	    int x1,x2,y1,y2;
	    cin>>x1>>x2>>y1>>y2;
	    befA.push_back(pii(x1,x2));
	    befB.push_back(pii(y1,y2));
	}
	for(int j = 0; j < n; j++) {
	    int x1,x2,y1,y2;
	    cin>>x1>>x2>>y1>>y2;
	    aftA.push_back(pii(x1,x2));
	    aftB.push_back(pii(y1,y2));
	}
	
	for(int j = 0; j < n; j++) {
// 	    cout<<j<<"!"<<endl;
// 	    cout<<w-abs(befA[j].second-befB[j].second)<<endl;
	    if(!res) break;
	    for(int k = j+1; k < n; k++) {
		if(befB[j].first <= befA[k].first && aftA[j].first >= aftB[k].first) {
		    if( w-abs(befA[j].second-befB[j].second) < abs(befA[k].second-befB[k].second) ) {
			res = false;
			break;
		    }
		} else if(befA[j].first >= befB[k].first && aftB[j].first <= aftA[k].first) {
		    if( w-abs(befA[j].second-befB[j].second) < abs(befA[k].second-befB[k].second) ) {
			res = false;
			break;
		    }
		}
	    }
	}
	if(res) cout<<"TAK"<<endl;
	else cout<<"NIE"<<endl;
	
    }
    
    
}