program zuobi;
var
n,m,i,j:longint;
a:array[1..10000]of string[100];
yeshu:array[1..10000]of longint;
s:string;
begin
assign (input,'scanword.in');
reset (input);
assign (output,'scanword.out');
rewrite (output);
readln (n);
for i:=1 to n do
begin
readln (a[i]);
readln (yeshu[i])
end;
readln (m);
for i:=1 to m do
begin
readln (s);
for j:=1 to n do
if s=a[j] then
begin
writeln (yeshu[j]);
break
end
end;
close (input);
close (output)
end.