n = int(input())
ids = [ [[] for x in range(3)] for i in range(9)]
e = ['A','E','H','I','L','M','O','S','T']
for i in range(n):
id,name = [x for x in input().split()]
pos = e.index(id[8])
col = int(id[0])/2 - 2
ids[pos][int(col)].append(name)
for i in range(9):
if len(ids[i]):
for j in range(3):
for k in range(len(ids[i][j])):
print(e[i] + ':', ids[i][j][k])