dct = {}
n = int(raw_input())
for i in range(n):
    line = raw_input()
    line = line.replace(',', '')
    line = line.replace('-', '')
    words = line.split()
    word_eng, words_rus = (words[0], words[1:])
    for word in words_rus:
        if word not in dct:
            dct[word] = []
        dct[word].append(word_eng)
dct_sorted = dct.items()
dct_sorted.sort()
print len(dct_sorted)
for dct_item in dct_sorted:
    dct_item[1].sort()
    ans = dct_item[0] + ' - ' + ', '.join(dct_item[1])
    print ans