Mascot Maze

아직 제출이 없습니다메모리 제한1024 MB

문제

The Google Coding Competitions team is setting up a new theme park. As in any good theme park, we want to have actors dressed up as mascots to interact with visitors. Because we are in a rush to open, we decided to use the letters from CODE JAM, KICK START, and HASH CODE as mascots, for a total of 1313 different mascots (the letters ACDEHIJKMORST).

The park's only attraction is a maze that has a set of N\mathbf{N} rooms numbered from 11 to N\mathbf{N}. Each room has a left exit and a right exit. Each exit takes the visitor to another room. Exits cannot be used in reverse; for example, if room 22 has an exit to room 33, you cannot go back from room 33 to room 22 unless room 33 also happens to have an exit to room 22.

We want to place exactly one of our 1313 mascots in each room. Each letter may be present in zero, one, or more rooms of the maze. To increase variety, we want to place mascots so that any three (not necessarily distinct) rooms that a visitor can visit consecutively have three different mascots.

Can you help us choose a mascot for each room such that this goal is met, or let us know that it cannot be done?

입력

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} test cases follow. Each test case consists of 33 lines. The first line contains a single integer N\mathbf{N}, representing the number of rooms in the maze. The second line contains N\mathbf{N} integers L_1,L_2,,L_N\mathbf{L\_1}, \mathbf{L\_2}, \dots, \mathbf{L\_N}, representing that the left exit from room ii leads to room L_i\mathbf{L\_i}. The third and last line contains N\mathbf{N} integers R_1,R_2,,R_N\mathbf{R\_1}, \mathbf{R\_2}, \dots, \mathbf{R\_N}, representing that the right exit from room ii leads to room R_i\mathbf{R\_i}.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is IMPOSSIBLE if there is no way to assign mascots while obeying the rules explained above. Otherwise, yy is an N\mathbf{N} character long string. The ii-th character of yy should be an uppercase letter from the set ACDEHIJKMORST, representing that you wish to assign that mascot to the ii-th room.

제한

  • 1T1001 \le \mathbf{T} \le 100.
  • L_ii\mathbf{L\_i} \neq i, for all ii. R_ii\mathbf{R\_i} \neq i, for all ii. 1L_i<R_iN1 \le \mathbf{L\_i} \lt \mathbf{R\_i} \le \mathbf{N}, for all ii.

힌트

Sample Case #1 is the image in the problem statement. It is possible to visit rooms 1, 2, and 1 consecutively (which visits room 1 twice), so the case is impossible.

Sample Case #2 has the following layout (blue arrows represent the left exits and red arrows represent the right exits):

One of many valid answers is to assign mascots as indicated. Notice that although we do not need to assign two T mascots in this case, we have done so in a way that does not break the rules.

Sample Cases #3 and #4 are possible, but require the use of multiple copies of some mascots.