#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
#define ALPHABETSIZE 26
class TrieNode{
public :
string t;
int val;
TrieNode * edges[ ALPHABETSIZE] ;
TrieNode( ) {
val= - 1 ;
for ( int i= 0 ; i< ALPHABETSIZE; i++ ) edges[ i] = NULL ;
}
} ;
class Trie{
private :
TrieNode * root;
public :
void insert( string s,string t) ;
TrieNode * update( string s) ;
Trie( ) {
root= new TrieNode( ) ;
}
} ;
void Trie:: insert ( string s,string t) {
TrieNode * tmp= root;
for ( int i= 0 ; s[ i] ; i++ ) {
if ( s[ i] < 'a' || s[ i] > 'z' ) continue ;
if ( ! tmp- > edges[ s[ i] - 'a' ] ) {
TrieNode* newNode= new TrieNode( ) ;
tmp- > edges[ s[ i] - 'a' ] = newNode;
}
tmp= tmp- > edges[ s[ i] - 'a' ] ;
}
tmp- > t= t;
tmp- > val= 0 ;
//cout<<tmp->t<<endl;
}
TrieNode* Trie:: update ( string s) {
TrieNode * tmp= root;
for ( int i= 0 ; s[ i] ; i++ ) {
//cout<<s[i]<<endl;
if ( s[ i] < 'a' || s[ i] > 'z' ) continue ;
if ( ! tmp- > edges[ s[ i] - 'a' ] ) return NULL ;
tmp= tmp- > edges[ s[ i] - 'a' ] ;
//cout<<tmp->val<<endl;
}
if ( tmp- > val== - 1 ) return NULL ;
tmp- > val+ = 1 ;
return tmp;
}
int main( ) {
int n;
cin >> n;
Trie * tr= new Trie( ) ;
string s,t;
char ch;
ch= getchar ( ) ;
for ( int i= 0 ; i< n; i++ ) {
getline( cin ,s) ;
getline( cin ,t) ;
//cout<<s<<'\t'<<t<<endl;
transform( s.begin ( ) , s.end ( ) , s.begin ( ) , :: tolower ) ;
tr- > insert( s,t) ;
}
int m;
cin >> m;
ch= getchar ( ) ;
//cout<<m;
int max= 0 ;
string maxVotes;
bool flag= false ;
for ( int i= 0 ; i< m; i++ ) {
getline( cin ,s) ;
transform( s.begin ( ) , s.end ( ) , s.begin ( ) , :: tolower ) ;
//cout<<s<<endl;
TrieNode * tmp= tr- > update( s) ;
if ( tmp== NULL ) continue ;
int count= tmp- > val;
//cout<<count<<endl;
if ( max< count) { maxVotes= tmp- > t; max= count; flag= false ; }
else if ( max== count) flag= true ;
}
if ( flag== true ) cout << "tie" << endl;
else cout << maxVotes<< endl;
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8Y3N0ZGlvPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIEFMUEhBQkVUU0laRSAyNgpjbGFzcyBUcmllTm9kZXsKCXB1YmxpYzoKCXN0cmluZyB0OwoJaW50IHZhbDsKCVRyaWVOb2RlICplZGdlc1tBTFBIQUJFVFNJWkVdOwoJVHJpZU5vZGUoKXsKCQl2YWw9LTE7CgkJZm9yKGludCBpPTA7aTxBTFBIQUJFVFNJWkU7aSsrKSBlZGdlc1tpXT1OVUxMOwoJfQp9OwoKY2xhc3MgVHJpZXsKCXByaXZhdGU6CglUcmllTm9kZSAqcm9vdDsKCXB1YmxpYzoKCXZvaWQgaW5zZXJ0KHN0cmluZyBzLHN0cmluZyB0KTsKCVRyaWVOb2RlICp1cGRhdGUoc3RyaW5nIHMpOwoJVHJpZSgpewoJCXJvb3Q9bmV3IFRyaWVOb2RlKCk7Cgl9Cn07Cgp2b2lkIFRyaWU6Omluc2VydChzdHJpbmcgcyxzdHJpbmcgdCl7CglUcmllTm9kZSAqdG1wPXJvb3Q7Cglmb3IoaW50IGk9MDtzW2ldO2krKyl7CgkJaWYoc1tpXTwnYScgfHwgc1tpXT4neicpIGNvbnRpbnVlOwoJCWlmKCF0bXAtPmVkZ2VzW3NbaV0tJ2EnXSl7CgkJCVRyaWVOb2RlKiBuZXdOb2RlPW5ldyBUcmllTm9kZSgpOwoJCQl0bXAtPmVkZ2VzW3NbaV0tJ2EnXT1uZXdOb2RlOwoJCX0KCQl0bXA9dG1wLT5lZGdlc1tzW2ldLSdhJ107Cgl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0PDxzPDxlbmRsOwoJCVRyaWVOb2RlICp0bXA9dHItPnVwZGF0ZShzKTsKCQlpZih0bXA9PU5VTEwpIGNvbnRpbnVlOwoJCWludCBjb3VudD10bXAtPnZhbDsKCQkvL2NvdXQ8PGNvdW50PDxlbmRsOwoJCWlmKG1heDxjb3VudCl7bWF4Vm90ZXM9dG1wLT50OyBtYXg9Y291bnQ7IGZsYWc9ZmFsc2U7fQoJCWVsc2UgaWYobWF4PT1jb3VudCkgZmxhZz10cnVlOwoJfQoJaWYoZmxhZz09dHJ1ZSkgY291dDw8InRpZSI8PGVuZGw7CgllbHNlIGNvdXQ8PG1heFZvdGVzPDxlbmRsOwoJcmV0dXJuIDA7Cn0=
stdin
MwpNYXJpbHluIE1hbnNvbgpSaGlub2Nlcm9zCkphbmUgRG9lCkZhbWlseSBDb2FsaXRpb24KSm9obiBTbWl0aAppbmRlcGVuZGVudAo2Ck1hcmlseW4gTWFuc29uCmxvbwpNYXJpbHluIE1hbnNvbgpNYXJpbHluIE1hbnNvbgpNYXJpbHluIE1hbnNvbgpNYXJpbHluIE1hbnNvbg==
3
Marilyn Manson
Rhinoceros
Jane Doe
Family Coalition
John Smith
independent
6
Marilyn Manson
loo
Marilyn Manson
Marilyn Manson
Marilyn Manson
Marilyn Manson