This problem is based on a puzzle by Randall L. Whipkey.
In the game of Letter Cubes you have a set of cubes. Every face of every cube carries one letter of the alphabet, and no letter appears more than once in the whole set. A set has at most 4 cubes, so at most 24 of the 26 letters are used.
Rearrange the cubes and turn them so that the top faces, read from left to right, spell a string. A puzzle is more fun when the strings are real words, but any string of uppercase letters works the same way.
You are given strings that one particular set of cubes can spell. Work out which letters sit on which cube.
Write a set of cubes in canonical form: put the six letters of a cube in alphabetical order to form a string, then list the resulting six-letter strings in alphabetical order, separated by a single space.
Sometimes one letter of the set never shows up in the given strings, so the strings alone cannot place it. You are then told which letter it is, and that hint is enough.
The input contains 1 to 20 datasets. The first line of a dataset holds a positive integer n (6≤n≤30) and a character c. The next n lines each hold one string of uppercase letters. All n strings have the same length k, with 2≤k≤4. A line containing only 0 follows the last dataset.
The k cubes behind a dataset carry 6k distinct letters. If all 6k of them appear among the n strings, then c is a hyphen, '-'. Otherwise exactly one cube letter is missing from the strings, and c is that missing letter.
Print one line per dataset: the canonical form of that dataset's cubes, so k six-letter strings, each with its letters in alphabetical order, the strings themselves in alphabetical order and separated by a single space.
Every dataset has exactly one solution.