import java.util.Arrays; import java.util.LinkedList; public class prog { public static void main(final String[] args) { java.util.Scanner scan = new java.util.Scanner(System.in); String[] keys = new String[10]; for (int i = 0; i < 10; i++) { char[] chars = scan.nextLine().toCharArray(); Arrays.sort(chars); keys[i] = new String(chars); } String combinationKeys = scan.nextLine(); LinkedList queue = new LinkedList<>(); int currentKey = combinationKeys.charAt(0) - '0'; int howManyToExtract = keys[currentKey].length(); for (int i = 0; i < howManyToExtract; i++) { queue.addLast(String.valueOf(keys[currentKey].charAt(i))); } for (int i = 1; i < combinationKeys.length(); i++) { currentKey = combinationKeys.charAt(i) - '0'; for (int j = 0; j < howManyToExtract; j++) { String s = queue.removeFirst(); for (int k = 0; k < keys[currentKey].length(); k++) { char c = keys[currentKey].charAt(k); queue.addLast(s + c); } } howManyToExtract = howManyToExtract * keys[currentKey].length(); } //System.out.println("---------------"); for (String s : queue) { System.out.println(s); } } }