public static void main(String[] args) throws Throwable{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		diccionario = new TreeMap<Integer, ArrayList<char[]>>();
		for (int c = 0, C = parseInt(in.readLine().trim()); c < C; c++) {
			String str = in.readLine().trim();
			if(!diccionario.containsKey(str.length()))
				diccionario.put(str.length(), new ArrayList<char[]>());
			diccionario.get(str.length()).add(str.toCharArray());
		}
		for (String ln; (ln = in.readLine()) != null; ) {
			StringTokenizer st = new StringTokenizer(ln.trim());
			char[] linea = ln.toCharArray();
			palabras = new ArrayList<char[]>(); 
			while(st.hasMoreTokens())palabras.add(st.nextToken().toCharArray());
			if(function(new TreeSet<Character>(), new TreeMap<Character, Character>(), 0, 0))
				/*for (int i = 0; i < palabras.size(); i++) {
					for (char ch: palabras.get(i)) 
						sb.append(solucion.get(ch));
					sb.append(i < palabras.size() - 1?" ":"");
				}
			else
				for (int i = 0; i < palabras.size(); i++) {
					for (char ch: palabras.get(i)) 
						sb.append("*");
					sb.append(i < palabras.size() - 1?" ":"");
				}*/
				for (int i = 0; i < linea.length; i++) {
					Character ch = solucion.get(linea[i]);
					if(ch != null)sb.append(ch);
					else sb.append(linea[i]);
				}
			else{
				for (int i = 0; i < linea.length; i++) {
					if(linea[i]!=' ')sb.append("*");
					else sb.append(linea[i]);
				}
			}
			sb.append("\n");
		}
		System.out.print(new String(sb));
	}