#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstring>
#include <map>
using namespace std;
int main ()
{
map<string,string>mp;
string s1,s2;
int n,q,m,i,j,k;
cin>>n;
getchar();
for(i=0;i<n;i++)
{
getline(cin,s1);
getline(cin,s2);
mp[s1]=s2;
}
cin>>q;
getchar();
while(q--)
{
cin>>s1;
cout<<mp[s1]<<endl;
}
return 0 ;
}
#include <iostream>
#include <string>
#include <cstring>
#include <map>
using namespace std;
int main ()
{
map<string,string>mp;
string s1,s2;
int n,q,m,i,j,k;
cin>>n;
getchar();
for(i=0;i<n;i++)
{
getline(cin,s1);
getline(cin,s2);
mp[s1]=s2;
}
cin>>q;
getchar();
while(q--)
{
cin>>s1;
cout<<mp[s1]<<endl;
}
return 0 ;
}