#include <fstream>
using namespace std;
ifstream fi ("sakinani.in");
ofstream fo ("sakinani.out");
class T
{
public:
string name,school;
bool k;
int sum;
}Saki[233];
T sch[233];
int n,m,j=0;
int main()
{
int n,m;
fi>>n;
for (int i=0;i<n;i++)
{
fi>>Saki[i].name>>Saki[i].school;
bool g=false;
for (int q=0;q<=j;q++)
if (Saki[i].school==sch[q].school)
{
g=true;
break;
}
if (g==false)
sch[j++].school=Saki[i].school;
}
string N;
fi>>m;
for (int i=0;i<m;i++)
{
fi>>N;
for (int q=0;q<n;q++)
if (N==Saki[q].name)
{
Saki[q].k=true;
break;
}
}
while (fi>>N)
{
string ss="-1";
bool w=false;
for (int i=0;i<n;i++)
if (N==Saki[i].name)
{
ss=Saki[i].school;
w=Saki[i].k;
break;
}
for (int i=0;i<=j;i++)
{
if (ss==sch[i].school)
{
sch[i].sum++;
if (w==true)
sch[i].sum++;
}
}
}
//for (int i=0;i<=j;i++)fo<<sch[i].school<<" "<<sch[i].sum<<endl;
int num=0;
string ans;
for (int i=0;i<=j;i++)
{
if (sch[i].sum>=num)
{
num=sch[i].sum;
ans=sch[i].school;
}
}
fo<<ans<<endl;
return 0;
}