QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#14742. Seagull Encounter

统计

!%?#¥@ and Z-shaped pipe cat are watching seagulls together.

In a grid with multiple rows and columns, there are initially $n$ seagulls and $n$ portions of food, each located in a distinct cell.

You can command the seagulls to forage. In one command, you must choose a seagull in the grid and a direction: Up (row index decreases, column index stays the same), Down (row index increases, column index stays the same), Left (row index stays the same, column index decreases), or Right (row index stays the same, column index increases). The seagull will then fly in that direction to the nearest cell that does not contain a seagull. When a seagull reaches a cell containing food, it eats the food and flies off the grid, meaning both the seagull and the food immediately disappear from the grid.

Please execute exactly $n$ commands such that all seagulls eat the food and fly off the grid, or report that it is impossible.

Input

Each test case contains multiple test data. The first line gives an integer $T(1 \le T \le 10^3)$, representing the number of test cases.

For each test case: The first line gives an integer $n(1 \le n \le 5000)$, representing $n$ seagulls, $n$ portions of food, and the limit of $n$ commands. The next $n$ lines each give two integers $r_i, c_i(1 \le r_i, c_i \le 5000)$, where the two integers in the $i$-th line represent the initial position of seagull $i$ at row $r_i$ and column $c_i$. The next $n$ lines each give two integers $r_i, c_i(1 \le r_i, c_i \le 5000)$, representing the initial position of a portion of food at row $r_i$ and column $c_i$.

It is guaranteed that all initial positions of seagulls and food are distinct. It is guaranteed that the sum of $n$ over all test cases in each test point does not exceed $5000$.

Output

For each test case: The first line outputs Yes or No, indicating whether a solution exists or not. If a solution exists, then output $n$ lines, each containing an integer $u_i$ and a character $c_i(c_i \in \{U, D, L, R\})$ separated by a space. The integer $u_i$ in the $i$-th line represents the seagull chosen in the $i$-th command, and the character $c_i$ (U, D, L, or R) represents the flight direction (Up, Down, Left, or Right, respectively). If there are multiple valid command sequences, output any one of them.

Please note not to output extra spaces.

Examples

Input 1

5
4
2 1
4 1
1 4
3 3
1 1
5 1
1 3
3 4
4
1 3
2 2
2 3
3 3
1 2
2 1
3 2
4 3
1
1 1
1 3
4
2 3
3 2
3 3
2 2
2 4
3 1
4 3
1 2
2
2 2
1 1
1 3
1 2

Output 1

Yes
1 U
2 D
3 L
4 R
Yes
1 D
3 L
4 L
2 U
No
Yes
4 U
3 D
1 R
2 L
No

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.