#include <iostream>#include <cstdio>#include <string.h>#include <map>using namespace std;map <string,string>mp;map <string,int>num;int main(){ int n,m,i,maxi; string a,b; map <string,int>::iterator it; bool flag; while( cin>>n ) { while( getchar()!='n' ) continue; for( i=0;i<n;i++ ) { getline( cin,a ); getline( cin,b ); mp[a]=b; num[a]=0; } cin>>m; while( getchar()!='n' ) continue; for( i=0;i<m;i++ ) { getline( cin,a ); if( mp[a].size()!=0 ) num[a]++; } maxi=0; flag=false; for( it=num.begin();it!=num.end();it++ ) { if( it->second>maxi ) { maxi=it->second; a=it->first; flag=true; } else if( it->second==maxi ) { flag=false; } } if( flag ) cout<<mp[a]<<endl; else cout<<"tien"; mp.clear(); num.clear(); } return 0;}