/*
* tui yi xuan shou da ge jiang you
* 退役选手打个酱油
*/
#include<cstdio>
#include<map>
#include<string>
#include<iostream>
using namespace std;
map<string,int>maaa;
int main()
{
freopen("scanword.in","r",stdin);
freopen("scanword.out","w",stdout);
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
string s;int num;
cin>>s>>num;
maaa[s]=num;
}
int m;
scanf("%d",&m);
for(int i=0;i<m;i++){
string s;
cin>>s;
printf("%d\n",maaa[s]);//cout<<m[s]<<endl;
}
return 0;
}