package lkformat2;
import java.io.*;
import java.util.*;
import java.util.regex.*;
public class PostprocessIntegers {
private static final Pattern ENTITY_PATTERN = Pattern.compile("]*)>([^<]*)");
public static void main(String[] argv) {
String idFileName = argv[0];
try {
BufferedReader br = new BufferedReader(new FileReader(idFileName));
HashMap labelToId = new HashMap();
String line = br.readLine();
while(line != null) {
line = line.trim();
String[] ts = line.split("\\s+");
if(labelToId.containsKey(ts[0]))
throw new RuntimeException("already mapped");
labelToId.put(ts[0], Integer.parseInt(ts[1]));
line = br.readLine();
}
BufferedReader br2 = new BufferedReader(new InputStreamReader(System.in));
line = br2.readLine();
while(line != null) {
StringBuffer sb = new StringBuffer();
Matcher m = ENTITY_PATTERN.matcher(line);
while(m.find()) {
m.appendReplacement(sb, "");
sb.append("");
String data = m.group(2);
Integer mapped = labelToId.get(data);
if(mapped == null)
throw new RuntimeException("mapped == null for " + data);
sb.append(mapped);
sb.append("");
}
m.appendTail(sb);
System.out.println(sb);
line = br2.readLine();
}
} catch(Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}