#P1728. [PA 2014] Parking

[PA 2014] Parking

Description

Your boss orders you to move the cars in the parking lot into the arrangement he wants.

The parking lot is a long rectangular strip with width ww. We take its lower-left corner as the origin, and build a Cartesian coordinate system with axes parallel to the sides of the rectangle. The parking lot is very long, so we can assume it extends infinitely far to the right.

Each car is an axis-aligned rectangle, and cars may have different sizes. You may translate the cars arbitrarily (but you may not rotate them), as long as they do not go out of the parking lot and do not collide with each other. Touching is allowed (that is, at any moment, the overlap area of any two cars is 00).

You know the current positions of all cars and the positions desired by your boss. You need to determine whether your boss’s task can be completed.

Input Format

The first line contains an integer tt, the number of testdata.

For each test case, the first line contains two integers n,wn, w, representing the number of cars and the width of the parking lot.

The next nn lines describe the current positions. The ii-th line contains four integers x1,y1,x2,y2x_1, y_1, x_2, y_2, meaning that car ii currently occupies the rectangle determined by x1,y1,x2,y2x_1, y_1, x_2, y_2.

(Note: it is possible that x1>x2x_1 > x_2 or y1>y2y_1 > y_2.)

The next nn lines have the same format and meaning, describing the target positions of the cars.

Output Format

Output tt lines. The ii-th line should be TAK (yes) or NIE (no), indicating whether, in the ii-th test case, the cars can be moved as required.

2
3 3
0 0 2 2
2 1 4 3
4 0 6 1
0 0 2 2
2 1 4 3
0 2 2 3
3 3
0 0 2 2
2 1 4 3
4 0 6 1
2 1 4 3
0 0 2 2
4 0 6 1
TAK
NIE

Hint

Constraints: for 100%100\% of the data, 1t201 \le t \le 20, 1n5×1041 \le n \le 5 \times 10^4, 1w1091 \le w \le 10^9, 0x1,x21090 \le x_1, x_2 \le 10^9, 0y1,y2w0 \le y_1, y_2 \le w

Translated by ChatGPT 5