This page is still under construction.

Parts of this page are still being built. What you see may change.

Folding the Figure

Time limit2sMemory limit512 MB

Summary
Given a connected polyomino of n cells that results from folding a k-cell polyomino along one grid line, reconstruct any valid original k-cell figure and the fold line.
Level

Hard8 of 10

Topics
Implementation, Geometry, Simulation, Greedy
Solved
No attempts yet

Problem

Petya was getting bored at his math lesson, so he started painting squares on his grid paper. When that too became boring, he noticed that he now had a connected set of k painted squares: from any painted square it is possible to reach any other painted square by moving between painted squares that share a side.

He cut the figure out of the sheet of paper and folded it along some grid line (horizontal or vertical, he did not remember which). After that he painted squares of another sheet of grid paper to create a copy of the folded figure. Now Petya has lost the original figure, so all he has is the copy of it after folding. Now Petya wants to restore the figure.

Restoring the figure exactly is difficult, but Petya has decided that he would like to have at least some figure of k squares that can be folded to get the same folded image. Help him find some connected figure of k squares that can be folded the required way.

Consider the second sample test, for example. It has a folded figure similar to an upside-down "U", and the original figure contains 12 squares. One possible appearance of the original figure is shown in the picture; it was folded along the line y = 3:

Input

The input data contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 200).

Each of the t test cases is described as follows. The first line of the description contains two integers n, k: the number of painted squares in the folded figure and the number of painted squares in the original figure (1 ≤ n < k ≤ 10^5).

Each of the following n lines contains two integers x_i, y_i: the coordinates of the bottom left corner of the i-th painted square (-10^8 ≤ x_i, y_i ≤ 10^8). All painted cells are guaranteed to be distinct and to form a connected figure.

The sum of the values of k over all test cases of one input data does not exceed 10^5.

Output

For each test case, output the answer to that test. Output the description of the figure and the way to fold it to get the input figure.

The first line must contain the description of the folding line. Each of the following k lines must contain two integers (x'_i, y'_i): the coordinates of the squares of the connected figure that can be folded along the given line to get the figure from the input data.

The folding line description must be one of the following 4:

  • L num: fold along the line x = num, put the left side atop the right one;
  • R num: fold along the line x = num, put the right side atop the left one;
  • U num: fold along the line y = num, put the top side atop the bottom one;
  • D num: fold along the line y = num, put the bottom side atop the top one.

All x'_i, y'_i, and the coordinate of the folding line must not exceed 10^9 in absolute value. The required figure is guaranteed to exist. If there are several possible answers, output any of them.

Examples1

  1. Example 1

    Input
    2
    7 14
    0 0
    0 1
    0 2
    1 2
    2 2
    2 1
    2 0
    7 12
    0 0
    0 1
    0 2
    1 2
    2 2
    2 1
    2 0
    
    Expected output
    L 0
    0 0
    0 1
    0 2
    1 2
    2 0
    2 1
    2 2
    -1 0
    -1 1
    -1 2
    -2 2
    -3 2
    -3 1
    -3 0
    U 3
    0 0
    0 1
    0 2
    1 2
    2 2
    2 1
    2 0
    0 3
    1 3
    2 3
    0 4
    2 4