name = input()
N = int(input())
lst = [input() for _ in range(N)]
LL = name.count('L')
OO = name.count('O')
VV = name.count('V')
EE = name.count('E')
_max_rank = -1
name = ''
for n in lst:
L = LL + n.count('L')
O = OO + n.count('O')
V = VV + n.count('V')
E = EE + n.count('E')
temp = ((L+O)*(L+V)*(L+E)*(O+V)*(O+E)*(V+E)) % 100
if _max_rank < temp:
_max_rank = temp
name = n
elif _max_rank == temp and n < name:
name = n
print(name)