name = input()
numOfTeam = int(input())
teamList = []
probList = []
teamIndex = 0
maxPorb = 0;
for i in range(numOfTeam):
teamList.append(input())
L = name.count("L") + str(teamList[i]).count("L")
O = name.count("O") + str(teamList[i]).count("O")
V = name.count("V") + str(teamList[i]).count("V")
E = name.count("E") + str(teamList[i]).count("E")
num = ((L+O) * (L+V) * (L+E) * (O+V) * (O+E) * (V+E)) % 100
probList.append((num, teamList[i]))
probList.sort(key=lambda x : (-x[0], x[1]))
print(probList[0][1])
from sys import stdin
a=stdin.readline().strip()
ini=0
r=[]
for i in range(int(stdin.readline().strip())):
b=stdin.readline().strip()
s=a+b
l=s.count('L')
o=s.count('O')
v=s.count('V')
e=s.count('E')
chk=((l+o)*(l+v)*(l+e)*(o+v)*(o+e)*(v+e))%100
if i==0:
ini=chk
r.append(b)
else:
if chk>ini:
r[0]=b
ini=max(chk,ini)
elif chk==ini:
r.append(b)
r.sort()
r.pop()
print(''.join(r))
from sys import stdin
name = stdin.readline().rstrip()
numOfTeam = int(stdin.readline().rstrip())
probList = []
for i in range(numOfTeam):
teamName = stdin.readline().rstrip()
s = name+teamName
L = s.count("L")
O = s.count("O")
V = s.count("V")
E = s.count("E")
num = ((L+O) * (L+V) * (L+E) * (O+V) * (O+E) * (V+E)) % 100
probList.append((num, teamName))
probList.sort(key=lambda x : (-x[0], x[1]))
print(probList[0][1])