Problem O
Toy Railway

Each switch looks as in Figure 1 and can be set to either of two states: B or C. If the trains enters at A it goes to B or C depending on the state of the switch. On the other hand, if the train enters at B or C, it always goes to A regardless of the state of the switch.
![\includegraphics[width=0.25\textwidth ]{rail1.pdf}](/problems/railway/file/statement/en/img-0002.png)
The starting position of Nora’s train is such that it is entering switch 1 at point A. The program should find static switch settings that make the train return to the starting position, faced in the same direction, while passing as few switches as possible, or determine that it is impossible. The train may travel on the same track multiple times (in different directions), but can never be reversed.
![\includegraphics[width=0.5\textwidth ]{rail2.pdf}](/problems/railway/file/statement/en/img-0003.png)
Input
The first line of the input contains two integers
Output
If a solution exists, output a string of
Note that there are many possible solutions in the first
example below: only the states of switches
Sample Input 1 | Sample Output 1 |
---|---|
10 13 1B 2B 1C 3C 3A 2A 4B 5B 4C 5A 1A 6A 6C 4A 3B 7B 7A 8C 8A 9A 9C 10A 10C 6B 10B 5C |
BCBBBBBBCC |
Sample Input 2 | Sample Output 2 |
---|---|
2 3 1B 1C 1A 2C 2A 2B |
Impossible |