AT_abc474_g LRUD Moving 2
Description
You are given positive integers $ N $ and $ K $ .
There is an $ N\times N $ grid. The cell at the $ r $ -th row from the top and the $ c $ -th column from the left is denoted as cell $ (r,c) $ .
Initially, a piece is placed on cell $ (1,1) $ .
You will perform the following operation exactly $ N^2-1 $ times so that the piece ends up in cell $ (N,N) $ :
- Move the piece one cell to a cell vertically or horizontally adjacent to the cell it is currently on.
Here, over the course of the movement, each of the $ N^2 $ cells must be visited exactly once. Cell $ (1,1) $ , where the piece is initially placed, is considered visited.
Determine whether there exists a sequence of operations where the piece moves one cell to the right exactly $ K $ times, and if it exists, find one such sequence.
You are given $ T $ test cases; solve each of them.
Input Format
The input is given from Standard Input in the following format:
> $ T $ $ \text{case}_1 $ $ \text{case}_2 $ $ \vdots $ $ \text{case}_T $
Each test case is given in the following format:
> $ N $ $ K $
Output Format
Output the answers for the test cases in order, separated by newlines.
For each test case, if there is no sequence of operations satisfying the condition, output `No`.
If there exists a sequence of operations satisfying the condition, output it in the following format:
> Yes $ S_1S_2\dots S_{N^2-1} $
Here, $ S_k $ represents the $ k $ -th move, and is one of the following:
- $ S_k= $ `L` if the piece moves one cell to the left
- $ S_k= $ `R` if the piece moves one cell to the right
- $ S_k= $ `U` if the piece moves one cell up
- $ S_k= $ `D` if the piece moves one cell down
If there are multiple sequences of operations satisfying the condition, any of them will be accepted.
Explanation/Hint
### Sample Explanation 1
Consider the first test case.
By moving from cell $ (1,1) $ in order to cells $ (1,2),(1,3),(2,3),(2,2),(2,1),(3,1),(3,2),(3,3) $ , you can move one cell to the right four times and reach cell $ (3,3) $ .
### Constraints
- $ 1\le T\le 5\times 10^3 $
- $ 2\le N\le 10^3 $
- $ 0\le K\le N^2-1 $
- The sum of $ N^2 $ over all test cases is at most $ 10^6 $ .
- All input values are integers.