import re
d = {}
for i in range(int(input())):
engWord, *latWords = re.split('\ - |, ', input())
for latWord in latWords:
d[latWord] = d.get(latWord, '') + engWord + ', '
print(len(d.keys()))
for latWord in sorted(d):
print(latWord + ' - ' + d[latWord][:-2])