using System.Collections.Generic;
using System.Threading.Tasks;
namespace ConsoleApplication2
static void Main(string[] args)
var namelist = new List<string>();
var partylist = new List<string>();
var votes = new Dictionary<string,int>();
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n ; i++ ) {
namelist.Add(Console.ReadLine());
partylist.Add(Console.ReadLine());
int m = int.Parse(Console.ReadLine());
for (int j = 0; j < m; j++) {
String name = Console.ReadLine();
if (namelist.Contains(name)) {
if (!votes.ContainsKey(name)) {
foreach (KeyValuePair<string, int> vote in votes)
if (vote.Value.Equals(votes.Values.Max())) {
Console.WriteLine("tie");
string winner = votes.Aggregate((x, y) => x.Value > y.Value ? x : y).Key;
Console.WriteLine(partylist[namelist.IndexOf(winner)]);