// Arup Guha
// 1/24/2015
// Solution to 2013 MCPC Problem E: Letter Cubes

import java.util.*;

public class e {

	public static int numCubes;
	public static boolean[] letters;
	public static boolean[][] allowed;
	public static char[][] res;
	public static int[] current;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();

		while (n != 0) {

			// Set up storage for letters.
			char extra = stdin.next().charAt(0);
			letters = new boolean[26];
			allowed = new boolean[26][26];
			for (int i=0; i<26; i++)
				Arrays.fill(allowed[i], true);

			// Process each word.
			for (int i=0; i<n; i++) {

				String s = stdin.next();
				numCubes = s.length();

				// Go through each letter, marking we have it and marking which
				// letters can't be on its cube.
				for (int j=0; j<numCubes; j++) {
					letters[s.charAt(j)-'A'] = true;
					for (int k=0; k<numCubes; k++) {
						if (j == k) continue;
						allowed[s.charAt(j)-'A'][s.charAt(k)-'A'] = false;
						allowed[s.charAt(k)-'A'][s.charAt(j)-'A'] = false;
					}
				}
			}

			// If this letter is on a cube also...
			if (Character.isLetter(extra)) letters[extra-'A'] = true;

			// Set up storage for cubes.
			res	= new char[numCubes][6];
			current = new int[numCubes];

			// Solve problem.
			go(0);

			// Print result.
			for (int i=0; i<numCubes-1; i++)
				System.out.print(new String(res[i])+" ");
			System.out.println(new String(res[numCubes-1]));

			n = stdin.nextInt();
		}
	}

	public static boolean go(int k) {

		// Woohoo! We got a solution.
		if (filled()) return true;

		// Must skip this letter since it's not in our puzzle.
		if (!letters[k]) return go(k+1);

		// Try putting this letter on each cube.
		for (int i=0; i<numCubes; i++) {

			// See if this letter is valid here, if so place it.
			if (current[i] < 6 && okay(i,k)) {
				res[i][current[i]] = (char)('A'+k);
				current[i]++;
				boolean outcome = go(k+1);
				if (outcome) return true;
				current[i]--;
			}
		}

		// Awww, nothing worked :(
		return false;
	}

	// Returns true iff all 6 sides of each cube are filled.
	public static boolean filled() {
		for (int i=0; i<numCubes; i++)
			if (current[i] != 6)
				return false;
		return true;
	}

	public static boolean okay(int cube, int letter) {

		// If any letter already on this cube conflicts with letter, we can't do this.
		for (int i=0; i<current[cube]; i++)
			if (!allowed[letter][res[cube][i]-'A'])
				return false;

		// If we get here, we're okay.
		return true;
	}
}