Target

Time limit1sMemory limit128 MB

Summary
Given all solution words of a letter puzzle, recover the 9 grid letters and place the letter common to every word in the middle.
Level

Easy3 of 10

Topics
Array, Hash map, String
Solved
No attempts yet

Problem

A newspaper runs a letter puzzle called Target. The puzzle shows a grid of 9 letters, and players form words from those letters. Every word must:

  • be at least 4 letters long,
  • use only the 9 letters of the grid, with no letter used more times than it appears in the grid, and
  • contain the central letter of the grid.

In addition, at least one valid word uses all nine letters.

For the grid shown above, the central (required) letter is P, so every word contains a P.

In this problem you are given the complete list of words that solve one puzzle, and you must reconstruct the grid. Print the 9 letters in alphabetical order, except that the required (central) letter is always moved to the 5th (middle) position, regardless of where it would fall alphabetically. For the example above, the reconstructed grid is printed as A A C I P M N O R — the required letter P sits in the middle.

Input

The input contains several puzzles. Each puzzle begins with a line holding a single integer NN (2<N≤502 < N \le 50), the number of words in that puzzle's solution. A line containing 00 marks the end of the input and is not processed.

The next NN lines each contain one word of the solution. Every word is lower case and has between 4 and 9 letters. At least one word in each puzzle has exactly 9 letters. Every word uses only letters that appear in the 9-letter word, and no letter appears in a word more times than it appears in the 9-letter word. Exactly one letter of the alphabet occurs in every word of the puzzle; that letter is the required central letter.

Output

For each puzzle, print one line with the 9 letters of the grid in upper case, separated by single spaces. The letters are in alphabetical order, except that the required letter is placed 5th (in the middle) regardless of its alphabetical position.

Examples1

  1. Example 1

    Input
    31
    apian
    apron
    camp
    campion
    capon
    carp
    corpa
    corp
    cramp
    crampon
    crimp
    crop
    napa
    orpin
    pain
    pair
    panic
    panoramic
    para
    piano
    pica
    pion
    pram
    prana
    prim
    prima
    primo
    prom
    ramp
    rampion
    romp
    0
    
    Expected output
    A A C I P M N O R