# coding: utf-8
d = dict()
nn = int(input())
for i in range(nn):
d[i] = str(input())
d_new = dict()
for k, v in d.items():
l = d[k].split(',')
l_sp = list()
for i in range(len(l)):
l_sp.append(l[i].rpartition('-')[-1].strip())
l_new = list()
for j in range(2, len(l_sp)):
l_new.append(l[j].strip())
d_new[l[0].rpartition('-')[0]] = l_sp
d_lat = dict()
for k, v in d_new.items():
l = d_new[k]
ll = list()
ll = l
for n in range(len(ll)):
key = ll[n].strip()
l_add = list()
l_add.append(k)
if d_lat.get(key):
for i in range(len(l_add)):
l_sup = d_lat[key]
l_sup.append(l_add[i].strip())
d_lat[key] = l_sup
else:
d_lat[key] = l_add
l_k = list()
print(len(d_lat))
for k in d_lat:
l_k.append(k.strip())
l_k = sorted(l_k)
for i in range(len(l_k)):
ll = d_lat[l_k[i]]
l_v = sorted(ll)
#tt = ', '.join(l_v)
tt = l_v[0].strip()
for q in range(1, len(l_v)):
tt = tt + ', ' + l_v[q].strip()
if len(l_v) > 1:
print('{0} - {1}'.format(l_k[i], tt))
else:
print('{0} - {1}'.format(l_k[i], tt))