var n,i,m,t,k,t1,t2,j:longint;
a,b:array[0..1000] of string;
sc,f,hash:array[0..1000] of longint;
s1,s2,s:string;
function find2(s:string):longint;
var i:longint;
begin
for i:=1 to m do
if b[i]=s then exit(i);
exit(0);
end;
function find1(s:string):longint;
var i:longint;
begin
for i:=1 to n do
if a[i]=s then exit(i);
exit(0);
end;
begin
assign(input,'sakinani.in');
assign(output,'sakinani.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do
begin
readln(s2);
t:=pos(' ',s2);
s1:=copy(s2,1,t-1);
delete(s2,1,t);
a[i]:=s1;
sc[i]:=1;
t2:=find2(s2);
if t2=0 then
begin
inc(m);
b[m]:=s2;
t2:=m;
end;
hash[i]:=t2;
end;
readln(k);
for i:=1 to k do
begin
readln(s1);
t:=find1(s1);
sc[t]:=2;
end;
while not eof do
begin
readln(s);
if s='' then continue;
t:=find1(s);
f[hash[t]]:=f[hash[t]]+sc[t];
end;
for i:=1 to m-1 do
for j:=i+1 to m do
if (f[j]>f[i])or((f[i]=f[j])and(b[j]<b[j])) then
begin
t:=f[i];
f[i]:=f[j];
f[j]:=t;
s:=b[i];
b[i]:=b[j];
b[j]:=s;
end;
writeln(b[1]);
close(input);
close(output);
end.