import java.util.*;

public class ProblemC
{
	public static String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		
		s.nextLine();
		
		while(true)
		{
			String word = s.nextLine();
			
			if(word.equals("LINGO"))
				System.exit(0);
			
			ArrayList<String> guesses = new ArrayList<String>();
			
			String line;
			
			while(!(line = s.nextLine()).equals(""))
				guesses.add(line);
			
			playGame(word, guesses);
		}
	}
	public static void playGame(String word, ArrayList<String> guesses)
	{
		String last;
		System.out.println("\n" + (last = (word.charAt(0) + "....")));
		
		int tries = 0;
		
		for(String guess : guesses)
		{	
			tries++;
			
			if(tries > 6)
			{
				System.out.println(word.toLowerCase());
				return;
			}
			
			String wordCopy = "" + word;
			
			if(guess.length() != 5)
			{
				if(tries < 6)
					System.out.println(last);
				
				continue;
			}
			
			boolean isBadGuess = false;
			
			for(int i = 0; i < guess.length(); i++)
				if(!alpha.contains("" + guess.charAt(i)))
				{
					isBadGuess = true;
					break;
				}
			
			if(isBadGuess)
			{
				if(tries < 6)
					System.out.println(last);
				
				continue;
			}
			
			char[] reply = new char[5];
			
			for(int i = 0; i < guess.length(); i++)
				if(guess.charAt(i) == word.charAt(i))
				{
					if(wordCopy.length() == 1)
					{
						System.out.println(word);
						return;
					}
					
					reply[i] = word.charAt(i);
					
					int index = i - (5 - wordCopy.length());
					
					wordCopy = wordCopy.substring(0, index) + wordCopy.substring(index + 1, wordCopy.length());
				}
				else
					reply[i] = (char)0;
			
			for(int i = 0; i < guess.length(); i++)
			{
				if(reply[i] != (char)0)
					continue;
				
				int index = wordCopy.indexOf(guess.charAt(i));
				if(index == -1)
					reply[i] = '.';
				else
				{
					reply[i] = ("" + guess.charAt(i)).toLowerCase().charAt(0);
					wordCopy = wordCopy.substring(0, index) + wordCopy.substring(index + 1, wordCopy.length());
				}
			}
			
			if(tries < 6)
				System.out.println(last = new String(reply));
		}
		
		System.out.println(word.toLowerCase()); //Ran out of guesses
	}
}