program cdc;
type c=record
s:string;
r:integer;
end;
var
f:text;
x:array[1..10000] of c;
b:array[1..10000] of string;
a:array[1..10000] of integer;
i,j,k,l,n,m:integer;
begin
assign(f,'scanword.in');
reset(f);
readln(f,n);
for i:=1to n do
begin
readln(f,x[i].s);
readln(f,x[i].r);
end;
readln(f,m);
for i:=1 to m do
readln(f,b[i]);
close(f);
for i:=1 to m do
for j:=1 to n do
if b[i]=x[j].s then
a[i]:=x[j].r ;
assign(f,'scanword.out');
rewrite(f);
for i:=1 to m do
writeln(f,a[i]);
close(f);
end.