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
#include <iostream>
#include <list>
using namespace std;

typedef struct car_struct {
	int leftBefore;
	int leftAfter;
	int height;
} car;

bool initial_compare(const car& c1, const car& c2) {
	return c1.leftBefore <= c2.leftBefore;
}

void sort_after(list<car>::iterator begin, list<car>::iterator end, int height) {
	list<car>::iterator i, k;
	for (i = begin; i != end; i++) {
		for (k = begin; k != i; k++) {
			if (i->leftAfter < k->leftAfter) {
				if (i->height + k->height > height) {
					throw 1;
				} else {
					iter_swap(i, k);
				}
			}
		}
	}
}

int main() {
	int tests;
	cin >> tests;
	while (tests-- > 0) {
		int cars, height;
		cin >> cars >> height;
		list<car> carList;
		for (int i = 0; i < cars; i++) {
			int x1, y1, x2, y2;
			cin >> x1 >> y1 >> x2 >> y2;
			car c;
			c.leftBefore = x1;
			c.height = y2 - y1;
			carList.push_back(c);
		}
		for (list<car>::iterator it = carList.begin(); it != carList.end(); ++it) {
			int x1, y1, x2, y2;
			cin >> x1 >> y1 >> x2 >> y2;
			it->leftAfter = x1;
		}
		carList.sort(initial_compare);
		try {
			sort_after(carList.begin(), carList.end(), height);
			cout << "TAK" << endl;
		} catch (int i) {
			cout << "NIE" << endl;
		}
	}
}