public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        scanner.nextLine();//eat start
        String line=null;
        while (!"END".equals(line=scanner.nextLine())){
            String[]arr=line.split("\\s+");
            dictionary.put(arr[1],arr[0]);
        }

        scanner.nextLine();//eat start
        while (!"END".equals(line=scanner.nextLine())){
            if(line.isEmpty()){
                System.out.println();
                continue;
            }
            System.out.println(translate(line));
        }
    }