Alphabet Blocks and Passwords

Arrange A to Z into the lexicographically smallest permutation with none of the given passwords appearing as a contiguous block.

Hard8BacktrackingString matchingTrieNo attempts yetTime limit5sMemory limit512 MB

Problem

You bought a set of 26 wooden English alphabet blocks, one for each letter from A to Z. The blocks come in a long box in a single row, so laying them out reads like a 26 letter message.

You use NN different passwords across your online accounts, and you are worried that one of them might show up in that message by accident. Decide whether the 26 letters can be arranged so that no password appears as a contiguous substring.

Input

The first line of the input contains the number of test cases TT. Then TT test cases follow. Each test case has two lines. The first line contains an integer NN, and the second line contains NN different strings of uppercase English letters P1P_1, P2P_2, ..., PNP_N separated by spaces. These strings are the passwords.

Limits

  • 1T1001 \le T \le 100
  • 1N501 \le N \le 50
  • 1Pi261 \le |P_i| \le 26 for every ii
  • PiPjP_i \ne P_j whenever iji \ne j

Output

For each test case, print one line in the form Case #x: y, where xx is the test case number starting from 1.

yy is a permutation of the 26 letters A to Z that contains no password as a contiguous substring. When several permutations satisfy the condition, print the lexicographically smallest one. When no permutation satisfies it, print IMPOSSIBLE in place of yy.