program scanword;
const
name='scanword';
var
maps:array[0..10001]of string;
mapn:array[0..10001]of longint;
i,j,r1,r2,n,m:longint;
r3:string;
begin
assign(input,name+'.in');
reset(input);
assign(output,name+'.out');
rewrite(output);
readln(n);
for i:=1 to n do
begin
readln(maps[i]);
readln(mapn[i]);
end;
readln(m);
for i:=1 to m do
begin
readln(r3);
for j:=1 to n do
if maps[j]=r3
then
begin
writeln(mapn[j]);
break;
end;
end;
close(output);
end.