#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;
}