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 ACDEHIJKMORST
).
The park's only attraction is a maze that has a set of

We want to place exactly one of our
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?
Input Specification
The first line of the input gives the number of test cases,
Output Specification
For each test case, output one line containing Case #x: y
,
where IMPOSSIBLE
if there is no way to assign mascots while obeying the rules explained above. Otherwise, ACDEHIJKMORST
, representing that you wish to assign that mascot to the
Limits
Memory limit: 1 GB.
Test Set 1
Time limit: 20 seconds.
Test Set 2
Time limit: 45 seconds.
Sample Input
4
3
2 1 1
3 3 2
6
3 1 4 1 2 3
5 3 5 2 4 5
20
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 1 1
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 20 2
19
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 1
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 19 3
Sample Output
Case #1: IMPOSSIBLE
Case #2: TSHIRT
Case #3: HCJKSHCJKSHCJKSHCJKS
Case #4: CODEJAMROCKSTHEMOST
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.
Note
This problem has different time limits for different batches. If you exceed the Time Limit for any batch, the judge will incorrectly display >45.000s
regardless of the actual time taken. Refer to the Limits section for batch-specific time limits.
Comments