← Home
write a go solution for Description:
You have a rectangular grid of height 2 and width 10^9 consisting of unit cells. There are n rectangles placed on this grid, and the borders of these rectangles pass along cell borders. The i-th rectangle covers all cells in rows from u_i to d_i inclusive and columns from l_i to r_i inclusive (1<=u_i<=d_i<=2; 1<=l_i<=r_i<=10^9). The initial rectangles can intersect, be nested, and coincide arbitrarily.

You should either remove each rectangle, or replace it with any of its non-empty subrectangles. In the latter case, the new subrectangle must lie inside the initial rectangle, and its borders must still pass along cell borders. In particular, it is allowed for the subrectangle to be equal to the initial rectangle.

After that replacement, no two (non-removed) rectangles are allowed to have common cells, and the total area covered with the new rectangles must be as large as possible.

Illustration for the first test case. The initial rectangles are given at the top, the new rectangles are given at the bottom. Rectangle number 4 is removed.

Input Format:
Each test contains multiple test cases. The first line contains the number of test cases t (1<=t<=10^4). The description of the test cases follows.

The first line of each test case contains a single integer n (1<=n<=2*10^5) — the number of rectangles.

Each of the next n lines contains four integers u_i,l_i,d_i,r_i (1<=u_i<=d_i<=2; 1<=l_i<=r_i<=10^9) — the coordinates of cells located in the top-left and the bottom-right corners of the rectangle, respectively.

It is guaranteed that the sum of n over all test cases does not exceed 2*10^5.

Output Format:
For each test case, first print an integer s — the largest possible covered by new rectangles area. Then print n lines with your solution to cover this area.

In the i-th of these lines print four integers u'_i,l'_i,d'_i,r'_i. If you remove the i-th rectangle, print u'_i=l'_i=d'_i=r'_i=0. Otherwise, these numbers denote the new coordinates of the top-left and the bottom-right corners of the i-th rectangle, satisfying u_i<=u'_i<=d'_i<=d_i; l_i<=l'_i<=r'_i<=r_i.

If there are multiple solutions, print any.

Note:
The picture in the statement illustrates the first test case.. Output only the code with no comments, explanation, or additional text.