Password-free alphabet arrangement

Arrange A to Z in one row so none of the given passwords appears as a contiguous block, choosing the smallest such order or reporting impossibility.

Medium6BacktrackingString matchingBrute forceNo attempts yetTime limit5sMemory limit512 MB

Problem

You bought your young nephew Andrey a full set of wooden English letters, A to Z, one of each. The box is long and narrow, so when the 26 letters sit in a row they read like a 26-letter message.

You log into your online accounts with NN different passwords, and you worry that the message contains one of them by accident. Decide whether the 26 letters can be placed in a row, each letter used exactly once, so that no password appears as a contiguous substring.

Input

The first line contains the number of test cases TT. Each test case takes two lines. The first line contains an integer NN. The second line contains the NN different passwords P1,P2,,PNP_1, P_2, \ldots, P_N, separated by spaces. Every password consists of uppercase English letters only.

Limits

  • 1T1001 \le T \le 100
  • 1N261 \le N \le 26
  • 1Pi261 \le |P_i| \le 26
  • PiPjP_i \ne P_j for iji \ne j
  • A single password may repeat a letter.

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 string that uses each of the 26 uppercase letters exactly once and contains no password as a contiguous substring. When more than one such string exists, print the lexicographically smallest one. When no such string exists, print IMPOSSIBLE in place of yy.