dict = dict()
for _ in range(int(input())):
aword, bwords = input().split(' - ')
bwords = bwords.split(', ')
for bword in bwords:
if bword in dict:
dict[bword] |= set([aword])
else:
dict[bword] = set([aword])
print(len(dict))
for k,v in sorted(dict.items()):
print(k, '-', ', '.join(sorted(v)))