#P9626. [ICPC2020 Nanjing R] Evil Coordinate
[ICPC2020 Nanjing R] Evil Coordinate
题目描述
A robot is standing on an infinite 2-dimensional plane. Programmed with a string of length , where $s_i \in \{\text{`U'}, \text{`D'}, \text{`L'}, \text{`R'}\}$, the robot will start moving from and will follow the instructions represented by the characters in the string.
More formally, let be the current coordinate of the robot. Starting from , the robot repeats the following procedure times. During the -th time:
- If the robot moves from to ;
- If the robot moves from to ;
- If the robot moves from to ;
- If the robot moves from to .-
However, there is a mine buried under the coordinate . If the robot steps onto during its movement, it will be blown up into pieces. Poor robot!
Your task is to rearrange the characters in the string in any order, so that the robot will not step onto .
输入格式
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:
The first line contains two integers and () indicating the coordinate of the mine.
The second line contains a string of length (, $s_i \in \{\text{`U'}, \text{`D'}, \text{`L'}, \text{`R'}\}$) indicating the string programmed into the robot.
It's guaranteed that the sum of of all test cases will not exceed .
输出格式
For each test case output one line. If a valid answer exists print the rearranged string, otherwise print Impossible
instead. If there are multiple valid answers you can print any of them.
5
1 1
RURULLD
0 5
UUU
0 3
UUU
0 2
UUU
0 0
UUU
LDLRUUR
UUU
Impossible
Impossible
Impossible