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
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <vector>

using namespace std;

int main(){
	int t,n,h,x1,y1,x2,y2;
	vector<pair<int,int> >p1,p2,p3,p4,d1,d2,d3,d4;
	bool tak=true;
	p1.resize(0);	p2.resize(0);	p3.resize(0);	p4.resize(0);
	d1.resize(0);	d2.resize(0);	d3.resize(0);	d4.resize(0);
	cin>>t;
	for(int o=0;o<n;o++){
		cin>>n,h;
		for(int i=0;i<n;i++){
			cin>>x1>>y1>>x2>>y2;
			if(x1<x2){
				if(y1<y2){
					p1.push_back(make_pair(x1,y1));
					p2.push_back(make_pair(x2,y1));
					p3.push_back(make_pair(x2,y2));
					p4.push_back(make_pair(x1,y2));
				}
				else{
					p1.push_back(make_pair(x1,y2));
					p2.push_back(make_pair(x2,y2));
					p3.push_back(make_pair(x2,y1));
					p4.push_back(make_pair(x1,y1));
				}
			}
			else{//x1>x2
				if(y1<y2){
					p1.push_back(make_pair(x2,y1));
					p2.push_back(make_pair(x1,y1));
					p3.push_back(make_pair(x1,y2));
					p4.push_back(make_pair(x2,y2));
				}
				else{
					p1.push_back(make_pair(x2,y2));
					p2.push_back(make_pair(x1,y2));
					p3.push_back(make_pair(x1,y1));
					p4.push_back(make_pair(x2,y1));
				}
			}
		}
		for(int i=0;i<n;i++){
			cin>>x1>>y1>>x2>>y2;
			if(x1<x2){
				if(y1<y2){
					d1.push_back(make_pair(x1,y1));
					d2.push_back(make_pair(x2,y1));
					d3.push_back(make_pair(x2,y2));
					d4.push_back(make_pair(x1,y2));
				}
				else{
					d1.push_back(make_pair(x1,y2));
					d2.push_back(make_pair(x2,y2));
					d3.push_back(make_pair(x2,y1));
					d4.push_back(make_pair(x1,y1));
				}
			}
			else{//x1>x
				if(y1<y2){
					d1.push_back(make_pair(x2,y1));
					d2.push_back(make_pair(x1,y1));
					d3.push_back(make_pair(x1,y2));
					d4.push_back(make_pair(x2,y2));
				}
				else{
					d1.push_back(make_pair(x2,y2));
					d2.push_back(make_pair(x1,y2));
					d3.push_back(make_pair(x1,y1));
					d4.push_back(make_pair(x2,y1));
				}
			}
		
		}
		for(int i=0;i<n;i++){
			if(p1[i]!=d1[i]){
				if(p1[i].first==d1[i].first)
					continue;
				else{
					if(p1[i].first>d1[i].first){
						for(int j=0;j<n;j++){
							if(i==j)
								continue;
							if(p1[i].first>p1[j].first)
								if(d1[i].first<d1[j].first){
									if(((p4[i].second-p1[i].second)+(p4[j].second-p1[j].second))>h){
										tak=false;
										break;
									}
								}
						}
					}
					else{
						for(int j=0;j<n;j++){
						
							if(i==j)
								continue;
							if(p1[i].first<p1[j].first)
								if(d1[i].first>d1[j].first){
									if(((p4[i].second-p1[i].second)+(p4[j].second-p1[j].second))>h){
										tak=false;
										break;
									}
								}}
					}
				}
			}
		if(!tak)
			break;
		}
	}
	if(tak)
		cout<<"TAK";
	else
		cout<<"NIE";
	
	
	return 0;
}