Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.

Vasya decided to organize information about the phone numbers of friends. You will be given n strings — all entries from Vasya's phone books. Each entry starts with a friend's name. Then follows the number of phone numbers in the current entry, and then the phone numbers themselves. It is possible that several identical phones are recorded in the same record.

Vasya also believes that if the phone number a is a suffix of the phone number b (that is, the number b ends up with a), and both numbers are written by Vasya as the phone numbers of the same person, then a is recorded without the city code and it should not be taken into account.

The task is to print organized information about the phone numbers of Vasya's friends. It is possible that two different people have the same number. If one person has two numbers x and y, and x is a suffix of y (that is, y ends in x), then you shouldn't print number x. If the number of a friend in the Vasya's phone books is recorded several times in the same format, it is necessary to take it into account exactly once.

Read the examples to understand statement and format of the output better.


-----Input-----

First line contains the integer n (1 ≤ n ≤ 20) — number of entries in Vasya's phone books. 

The following n lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English letters. Number of phone numbers in one entry is not less than 1 is not more than 10. The telephone numbers consist of digits only. If you represent a phone number as a string, then its length will be in range from 1 to 10. Phone numbers can contain leading zeros.


-----Output-----

Print out the ordered information about the phone numbers of Vasya's friends. First output m — number of friends that are found in Vasya's phone books.

The following m lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each record must contain all the phone numbers of current friend.

Entries can be displayed in arbitrary order, phone numbers for one record can also be printed in arbitrary order.


-----Examples-----
Input
2
ivan 1 00123
masha 1 00123

Output
2
masha 1 00123 
ivan 1 00123 

Input
3
karl 2 612 12
petr 1 12
katya 1 612

Output
3
katya 1 612 
petr 1 12 
karl 1 612 

Input
4
ivan 3 123 123 456
ivan 2 456 456
ivan 8 789 3 23 6 56 9 89 2
dasha 2 23 789

Output
2
dasha 2 23 789 
ivan 4 789 123 2 456

Difficulty: MEDIUM
Tags: String algorithms

Implementation

Starter code:

Solutions:
def check_suffix(s1, s2):
	l1 = len(s1)
	l2 = len(s2)
	if l1 >= l2:
		return 0
	if s2[-l1:] == s1:
		return 1
	return 0

def no_suffix(ls):
	ls2 = []
	for i in range(len(ls)):
		for j in range(len(ls)):
			if i == j:
				continue
			if check_suffix(ls[i], ls[j]) == 1:
				ls2.append(ls[i])
	for i in ls2:
		if i in ls:
			ls.remove(i)
	return ls
n = int(input())
d = {}
for i in range(n):
	ls = input().split()
	if ls[0] not in d:
		d[ls[0]] = set(ls[2:])
	else:
		d[ls[0]] |= set(ls[2:])
print(len(d))
for i in d:
	print(i, end=' ')
	ls = no_suffix(list(d[i]))
	print(len(ls), end=' ')
	for i in ls:
		print(i, end=' ')
	print()


k = int(input())
d = dict()
for _ in range(k):
	(name, *nums) = input().split()
	nums = set(nums[1:])
	if name in d:
		d[name] = d[name].union(nums)
	else:
		d[name] = nums
print(len(d))
for name in d:
	arr = sorted(list(map(lambda x: x[::-1], d[name])))
	i = 0
	while i < len(arr) - 1:
		if arr[i + 1].startswith(arr[i]):
			arr.pop(i)
			i -= 1
		i += 1
	print(name, len(list(arr)), ' '.join([k[::-1] for k in arr]))


names = {}
n = int(input())
for i in range(n):
	row = input().split()
	if not row[0] in names.keys():
		names[row[0]] = set(row[2:])
	else:
		names[row[0]] |= set(row[2:])
keys = list(names.keys())
for j in range(len(keys)):
	names[keys[j]] = list(names[keys[j]])

def suffix(number, name):
	for i in range(len(names[name])):
		if not names[name][i] == number or len(names[name][i]) != len(number):
			if names[name][i].endswith(number):
				number = names[name][i]
			elif number.endswith(names[name][i]):
				names[name][i] = number
for j in range(len(keys)):
	for k in range(len(names[keys[j]])):
		suffix(names[keys[j]][k], keys[j])
print(len(keys))
for j in range(len(keys)):
	x = list(set(names[keys[j]]))
	print(keys[j], len(x), ' '.join(x))


n = int(input())
d = dict()
for i in range(n):
	inp = input().split()
	(name, cnt) = (inp[0], int(inp[1]))
	d[name] = d.get(name, set())
	d[name].update(inp[2:])
print(len(d))
for (k, v) in d.items():
	v = list(v)
	for i in range(len(v)):
		for j in range(len(v)):
			if i != j and len(v[i]) <= len(v[j]) and (v[j][len(v[j]) - len(v[i]):] == v[i]):
				v[i] = '-'
	l = 0
	for e in v:
		if e != '-':
			l += 1
	print(k, l, end=' ')
	for e in v:
		if e != '-':
			print(e, end=' ')
	print()


from collections import deque

def organize(inp):
	name = inp[0]
	records = deque(inp[1:])
	records_copy = deque(inp[1:])
	found = True
	while found:
		removed = False
		for l in records:
			to_remove = None
			for k in records_copy:
				index = min(len(k), len(l))
				if k[-index:] == l and k != l:
					to_remove = l
					break
			if to_remove and to_remove in records_copy:
				records_copy.remove(to_remove)
				removed = True
		if not removed:
			found = False
	final_res = []
	for l in records_copy:
		if l not in final_res:
			final_res.append(l)
	final_res = [name, str(len(final_res))] + final_res
	print(' '.join(final_res))
	return

def solution():
	n = int(input())
	d = {}
	for l in range(n):
		inp = [a for a in input().split(' ')]
		name = inp[0]
		record = inp[2:]
		if name in d:
			d[name] += record
		else:
			d[name] = record
	print(len(d))
	for k in d:
		organize([k] + d[k])
solution()


n = int(input())
d = {}
for i in range(n):
	arr = input().split()
	name = arr[0]
	cnt = arr[1]
	arr = arr[2:]
	if name in d:
		for j in arr:
			d[name].append(j)
	else:
		d[name] = arr
print(len(d))
for name in d.keys():
	print(name)
	d[name] = list(set(d[name]))
	ans = []
	for i in range(len(d[name])):
		le = len(d[name][i])
		for j in range(len(d[name])):
			if i != j and le < len(d[name][j]) and (d[name][j][-le:] == d[name][i]):
				break
		else:
			ans.append(d[name][i])
	ans = set(ans)
	print(len(ans))
	for i in ans:
		print(i)


def proverk(numb):
	answer = []
	journal = {}
	for i in numb:
		if not eto_suffiks(i, numb) and i not in journal:
			answer.append(i)
			journal[i] = True
	return answer

def eto_suffiks(i, numb):
	for s in numb:
		if len(s) > len(i) and s[len(s) - len(i):] == i:
			return True
	return False
n = int(input())
telbook = {}
for i in range(n):
	data = input().split()
	name = data[0]
	numbers = data[2:]
	if name in telbook:
		telbook[name] = telbook[name] + numbers
	else:
		telbook[name] = numbers
print(len(telbook))
for i in telbook:
	b = proverk(telbook[i])
	print(i, len(b), ' '.join(b))


import sys
import copy
cases = sys.stdin.readline()
my_input = []
for line in sys.stdin.readlines():
	my_input.append(line.strip().split(' '))
my_dict = dict()
for line in my_input:
	arr = []
	for i in range(2, len(line)):
		arr.append(line[i])
	if line[0] in my_dict:
		my_dict[line[0]].update(arr)
	else:
		my_dict[line[0]] = set(arr)
for x in my_dict:
	values = my_dict[x]
	final_values = copy.deepcopy(values)
	for a in values:
		for b in values:
			if a.endswith(b) and a != b and (b in final_values):
				final_values.remove(b)
	my_dict[x] = final_values
print(len(my_dict))
for x in my_dict:
	print(str(x) + ' ' + str(len(my_dict[x])) + ' ' + ' '.join(my_dict[x]))


from collections import defaultdict
n = int(input())
dic = defaultdict(set)
for i in range(n):
	a = input().split()
	d = a[2:]
	for j in d:
		dic[a[0]].add(j)
dic2 = defaultdict(list)
for (k, v) in dic.items():
	v = sorted(v, key=lambda x: len(x), reverse=True)
	tmp = []
	for i in v:
		if len(tmp) == 0:
			tmp.append(i)
		else:
			flag = True
			for h in tmp:
				if i == h[len(h) - len(i):]:
					flag = False
					continue
			if flag:
				tmp.append(i)
	dic2[k] = tmp
print(len(dic2))
for (k, v) in dic2.items():
	print('{} {} '.format(k, len(v)) + ' '.join(map(str, v)))


n = int(input())
d = dict()
for i in range(n):
	a = input().split()
	if a[0] not in d:
		d[a[0]] = []
	for j in range(2, len(a)):
		a[j] = a[j][::-1]
	d[a[0]] += a[2:]
print(len(d))
for x in d:
	a = d[x]
	a.sort(reverse=True)
	b = [a[0]]
	for i in range(1, len(a)):
		if a[i - 1][:len(a[i])] != a[i]:
			b += [a[i]]
	for i in range(len(b)):
		b[i] = b[i][::-1]
	print(x, len(b), *b)


n = int(input())
d = {}
for i in range(n):
	(s, j, a) = input().split(maxsplit=2)
	l = list(a.split())
	if s in d.keys():
		d[s] += l
	else:
		d[s] = l
for s in d.keys():
	l1 = []
	l = list(set(d[s]))
	d[s] = l
	for i in range(len(l)):
		q = l[i]
		l[i] = '0'
		if any((str.endswith(q) and len(q) < len(str) for str in l)):
			pass
		else:
			l1.append(q)
		l[i] = q
	d[s] = l1
print(len(list(d.keys())))
for s in d.keys():
	a = len(d[s])
	print(s, a, *d[s])


n = int(input())
entries = []
for i in range(n):
	entries.append(input().split())
book = {}
for e in entries:
	if e[0] in book:
		numbers = book[e[0]]
		for non_org_number in e[2:]:
			issuffix = False
			isselfsuffix = False
			selfindex = 0
			for i in range(len(numbers)):
				if numbers[i].endswith(non_org_number):
					issuffix = True
					break
				if non_org_number.endswith(numbers[i]):
					isselfsuffix = True
					selfindex = i
					break
			if not issuffix:
				if not isselfsuffix:
					numbers.append(non_org_number)
				if isselfsuffix:
					numbers[selfindex] = non_org_number
		book[e[0]] = numbers
	else:
		numbers = []
		for non_org_number in e[2:]:
			issuffix = False
			isselfsuffix = False
			selfindex = 0
			for i in range(len(numbers)):
				if numbers[i].endswith(non_org_number):
					issuffix = True
					break
				if non_org_number.endswith(numbers[i]):
					isselfsuffix = True
					selfindex = i
					break
			if not issuffix:
				if not isselfsuffix:
					numbers.append(non_org_number)
				if isselfsuffix:
					numbers[selfindex] = non_org_number
		book[e[0]] = numbers
print(len(book))
for e in book:
	print(e, len(book[e]), ' '.join(book[e]))


phone_book = {}
for _ in range(int(input())):
	(name, _, *numbers) = input().split()
	if name in phone_book:
		phone_book[name].update(numbers)
	else:
		phone_book[name] = set(numbers)
for (name, numbers) in phone_book.items():
	full_numbers = set()
	for number in sorted(numbers, key=len, reverse=True):
		if all((not full_number.endswith(number) for full_number in full_numbers)):
			full_numbers.add(number)
	phone_book[name] = full_numbers
print(len(phone_book))
for (name, numbers) in phone_book.items():
	print(name, len(numbers), *numbers)


n = int(input())
data = []
name = []
kk = []
num = []
l = 0
for i in range(n):
	a = list(map(str, input().split()))
	t = True
	for y in range(l):
		if name[y] == a[0]:
			t = False
			q = int(a[1])
			kk[y] += q
			for x in range(2, q + 2):
				num[y].append(a[x])
	if t:
		name.append(a[0])
		kk.append(int(a[1]))
		num.append(a[2:])
		l += 1
print(l)
for i in range(l):
	b = []
	print(name[i], end=' ')
	k = kk[i]
	b.append(k)
	c = 0
	j = 0
	while j < k:
		t = True
		p = 0
		while p < k:
			if j != p:
				if num[i][p] == num[i][j]:
					num[i].remove(num[i][j])
					k -= 1
					j -= 1
					t = False
					break
				elif num[i][p].endswith(num[i][j]):
					t = False
					break
			p += 1
		if t and j < k:
			b.append(num[i][j])
			c += 1
		j += 1
	b[0] = c
	print(c, end=' ')
	for z in range(1, c):
		print(b[z], end=' ')
	print(b[c])


n = int(input())
book = {}
for i in range(n):
	entry = input().split(' ')
	num = set(entry[2:])
	if entry[0] not in book:
		book[entry[0]] = num
	else:
		book[entry[0]].update(num)
for i in book:
	mod = book[i]
	modlist = []
	for j in mod:
		for k in mod:
			if j != k and j.endswith(k):
				modlist.append(k)
	for j in modlist:
		mod.discard(j)
	book[i] = mod
print(len(book))
for i in book:
	string = ''
	for j in book[i]:
		string += str(j) + ' '
	print(i, len(book[i]), string)


d = {}
for _ in range(int(input())):
	v = list(map(str, input().split()))
	ss = v[0]
	d[ss] = d.get(ss, set())
	d[ss] |= set(v[2:])
print(len(d))
for ss in d:
	l2 = list(d[ss])
	for i in range(len(l2)):
		for j in range(len(l2)):
			s = str(l2[j])
			if len(l2[j]) > len(l2[i]) and s[-len(l2[i]):] == l2[i]:
				l2[i] = 'a'
	l2 = list(set(l2))
	if 'a' in l2:
		l2.remove('a')
	l3 = [ss, len(l2)] + l2
	print(*l3)


from collections import defaultdict
d = defaultdict(list)
for _ in range(int(input())):
	a = list(input().split())
	s = a[0]
	x = a[1]
	ind = 2
	for i in range(int(x)):
		d[s].append(a[ind])
		ind += 1
print(len(d))
for keys in d:
	s = set()
	for j in sorted(d[keys], key=len):
		if j not in s:
			s.add(str(j))
			s1 = ''
			j = str(j)
			for i in range(len(j) - 1, 0, -1):
				s1 = j[i] + s1
				if s1 in s:
					s.remove(s1)
	print(keys, len(s), *s)


n = int(input())
d = {}
for i in range(n):
	s = list(str(input()).split(' '))
	if s[0] not in d:
		d[s[0]] = []
	for i in range(2, 2 + int(s[1])):
		d[s[0]] += [s[i][::-1]]
print(len(d))
for name in d:
	ph = sorted(d[name])
	ans = []
	for i in range(len(ph) - 1):
		li = len(ph[i])
		lj = len(ph[i + 1])
		if li > lj or ph[i] != ph[i + 1][:li]:
			ans += [ph[i][::-1]]
	ans += [ph[-1][::-1]]
	print(name, len(ans), ' '.join(ans))


n = int(input())

def is_suffix(phone, p):
	if len(p) <= len(phone):
		return False
	return phone == p[-len(phone):]

def is_any_suffix(phone, phones):
	for p in phones:
		if is_suffix(phone, p):
			return True
	return False
from collections import defaultdict
name_map = defaultdict(list)
for i in range(n):
	entry = input().split()
	name = entry[0]
	num = int(entry[1])
	phones = entry[2:]
	name_map[name].extend(phones)
print(len(name_map))
for name in name_map:
	phones = name_map[name]
	final_phones = set()
	for phone in phones:
		if not is_any_suffix(phone, phones) and phone not in final_phones:
			final_phones.add(phone)
	print(name, len(final_phones), ' '.join(final_phones))


import re
n = int(input())
temp = {}
for i in range(n):
	arr = input().strip().split()
	name = arr[0]
	num = arr[1]
	phone = arr[2:]
	if name not in temp.keys():
		temp[name] = phone
	else:
		temp[name].extend(phone)
for k in temp.keys():
	dis = []
	for ph in temp[k]:
		r = 1
		l = len(ph)
		while r < l:
			val = ph[r:]
			if val in temp[k]:
				dis.append(val)
			r += 1
	temp[k] = set(temp[k])
	new_temp = []
	for val in temp[k]:
		if val not in dis:
			new_temp.append(val)
	temp[k] = new_temp
print(len(temp))
for k in temp.keys():
	print(k, len(temp[k]), end=' ')
	for val in temp[k]:
		print(val, end=' ')
	print()


def same(x, y):
	if len(x) > len(y):
		if y == x[len(x) - len(y):]:
			return 2
	elif x == y[len(y) - len(x):]:
		return 1
	else:
		return 0
	return 0
n = int(input())
pb = dict()
for i in range(n):
	record = input().split()
	if record[0] in list(pb.keys()):
		pb[record[0]] += record[2:]
	else:
		pb[record[0]] = record[2:]
for i in list(pb.keys()):
	rf = []
	for j in pb[i]:
		flag = True
		for k in range(len(rf)):
			if same(j, rf[k]) == 2:
				flag = False
				rf[k] = j
			elif same(j, rf[k]) == 1:
				flag = False
		if flag:
			rf.append(j)
	pb[i] = rf
print(len(list(pb.keys())))
for i in list(pb.keys()):
	print(i, len(pb[i]), *pb[i])


from sys import stdout
n = int(input())
tab = []
m = []
for i in range(n):
	l = input().split()
	m.append(l[0])
	tab.append(list(l))
m = list(set(m))
for p in range(len(m)):
	m[p] = [m[p]]
m1 = []
for j in range(len(m)):
	for i in range(n):
		if tab[i][0] == m[j][0]:
			for u in tab[i][2:]:
				if u not in m[j]:
					m[j].append(u)
print(len(m))
for i in range(len(m)):
	t = []
	for k in range(1, len(m[i])):
		v = 0
		for j in range(1, len(m[i])):
			if k != j:
				if m[i][k] in m[i][j]:
					r1 = ''.join(reversed(m[i][k]))
					r2 = ''.join(reversed(m[i][j]))
					if r2.index(r1) == 0:
						v = 1
						break
		if v == 0:
			t.append(m[i][k])
	stdout.write(str(m[i][0]) + ' ' + str(len(t)) + ' ')
	for val in t:
		stdout.write(val + ' ')
	stdout.write('\n')


n = int(input())
gross = []
for i in range(n):
	gross.append(input())
contact = []
book = {}
for each in gross:
	k = each.split(maxsplit=2)
	if (k[0] in contact) == True:
		p = k[2]
		pp = p.split()
		book[k[0]].extend(pp)
	else:
		contact.append(k[0])
		p = k[2]
		pp = p.split()
		book[k[0]] = pp
print(len(contact))
for each in contact:
	q = list(set(book[each]))
	f = q[:]
	for it in q:
		count = 0
		for every in q:
			if every.endswith(it) == True:
				count += 1
		if count > 1:
			f.remove(it)
	print(each + ' ' + str(len(f)) + ' ' + ' '.join(f))


from sys import stdin, stdout
n = int(stdin.readline())
d = {}
for i in range(n):
	s = stdin.readline().strip().split()
	name = s[0]
	k = int(s[1])
	if not name in d:
		d[name] = []
	for v in s[2:]:
		d[name].append(v)
ans = {}
for name in d:
	numbers = list(set(d[name]))
	ans_local = []
	for i in range(len(numbers)):
		for j in range(len(numbers)):
			(s, f) = (numbers[i], numbers[j])
			if len(s) < len(f) and f[-len(s):] == s:
				break
		else:
			ans_local.append(s)
	ans[name] = ans_local
stdout.write(str(len(ans)) + '\n')
for name in ans:
	stdout.write(name + ' ' + str(len(ans[name])) + ' ' + ' '.join(ans[name]) + '\n')


inp = lambda : map(int, input().split())
n = int(input())
d = dict()
for i in range(n):
	(name, a, *numbers) = input().split()
	numbers = set(numbers)
	if name in d:
		d[name] = d[name].union(numbers)
	else:
		d[name] = numbers
for name in d:
	s = d[name].copy()
	for t in s:
		lt = len(t)
		for j in s:
			lj = len(j)
			if t != j and lt > lj and (t[lt - lj:] == j) and (j in d[name]):
				d[name].remove(j)
print(len(d))
for name in d:
	print(name, len(d[name]), ' '.join(d[name]))


n = int(input())
p = {}
for _ in range(n):
	r = input().split()
	(f, _, n) = (r[0], r[1], r[2:])
	if not p.get(f):
		p[f] = set()
	p[f].update(n)
s = ''
for (k, v) in p.items():
	r = []
	for (e, i) in enumerate(v):
		for (e1, j) in enumerate(v):
			if j.endswith(i) and e != e1:
				break
		else:
			r.append(i)
	s += '{} {} {}\n'.format(k, len(r), ' '.join(r))
print(s.count('\n'), s, sep='\n')


n = int(input())
l = []
l1 = []
for i in range(0, n):
	arr = list(map(str, input().split(' ')))
	if arr[0] not in l:
		l.append(arr[0])
		l1.append(set([]))
	x = l.index(arr[0])
	s = set()
	for j in range(0, int(arr[1])):
		s.add(arr[j + 2])
	l1[x] = l1[x].union(s)
print(len(l))
for i in range(0, len(l)):
	x = list(l1[i])
	y = x[:]
	for j in range(0, len(x)):
		for k in range(0, len(x)):
			if x[j] in x[k] and x[j] in y and (j != k) and (x[k][-len(x[j]):] == x[j]):
				y.remove(x[j])
	s = l[i] + ' ' + str(len(y)) + ' '
	for j in range(0, len(y)):
		s += y[j] + ' '
	print(s)


n = int(input())
a = {}
c = 0
vector = []
for i in range(n):
	tabela = [j for j in input().split()]
	if not tabela[0] in a:
		a.update({tabela[0]: c, c: tabela[0]})
		c += 1
		vector.append([])
	indice = a[tabela[0]]
	if vector[indice] == []:
		vector[indice].append(tabela[2])
	for j in range(2, int(tabela[1]) + 2):
		tn = len(tabela[j])
		chave = True
		for k in range(len(vector[indice])):
			tv = len(vector[indice][k])
			if tv >= tn and vector[indice][k][-tn:] == tabela[j]:
				chave = False
				break
			elif tabela[j][-tv:] == vector[indice][k]:
				chave = False
				del vector[indice][k]
				vector[indice].append(tabela[j])
				break
		if chave:
			vector[indice].append(tabela[j])
print(int(c))
for i in range(c):
	print('%s %d' % (a[i], len(vector[i])), end='')
	for j in vector[i]:
		print(' %s' % j, end='')
	print()


def suff(a, b):
	if a == b:
		return False
	else:
		return len(b) > len(a) and b[len(b) - len(a):] == a
n = int(input())
a = {}
for i in range(n):
	s = input().split()
	name = s[0]
	nums = s[2:]
	if name in a.keys():
		a[name].extend(nums)
	else:
		a[name] = nums
for name in a.keys():
	nums = []
	for i in a[name]:
		if i not in nums:
			fl = False
			for j in a[name]:
				if suff(i, j):
					fl = True
			if not fl:
				nums.append(i)
	a[name] = nums
print(len(a.keys()))
for name in a.keys():
	print(name, len(a[name]), end=' ')
	for i in a[name]:
		print(i, end=' ')
	print()


n = int(input())
dic = {}
for i in range(n):
	text = input().split()
	nam = text[0]
	if nam not in dic:
		dic[nam] = set()
	for elem in text[2:]:
		dic[nam].add(elem)
print(len(dic))
for (nam, s) in list(dic.items()):
	ls = []
	for e in s:
		add = True
		l = len(e)
		for j in s:
			if j != e and j[-l:] == e:
				add = False
				break
		if add:
			ls.append(e)
	print(nam, len(ls), *ls)


n = int(input())
d = {}
for i in range(n):
	a = input().split()
	if a[0] not in d:
		d[a[0]] = []
		for j in a[2:]:
			d[a[0]].append(j)
	else:
		for j in a[2:]:
			d[a[0]].append(j)
print(len(d.keys()))
for i in d.keys():
	a = []
	b = d[i]
	j = 0
	k = 0
	while j < len(b):
		l = len(b[j])
		k = 0
		while k < len(b):
			if j != k:
				if len(b[k]) >= l:
					if b[k][-1 * l:] == b[j]:
						b[j] = 'a'
						break
			k += 1
		j += 1
	a = []
	for k in b:
		if k != 'a':
			a.append(k)
	print(i, len(a), *a)


phones = dict()
n = int(input())
for i in range(n):
	(name, num, *numbers) = input().split()
	for number in numbers:
		try:
			for el in phones[name]:
				if el.endswith(number):
					break
				if number.endswith(el):
					phones[name].remove(el)
					phones[name].add(number)
					break
			else:
				phones[name].add(number)
		except KeyError:
			phones[name] = {number}
print(len(phones))
print('\n'.join([' '.join([name, ' '.join([str(len(numbers)), ' '.join(numbers)])]) for (name, numbers) in phones.items()]))


n_contacts = int(input())
names = dict()
for i in range(n_contacts):
	info = input().split()
	if info[0] in names:
		names[info[0]].extend(info[2:])
	else:
		names[info[0]] = info[2:]
final = dict()
for (key, value) in names.items():
	indexes_to_pop = []
	value = list(set(value))
	for n_i in range(len(value)):
		for p_i in range(n_i + 1, len(value)):
			s1 = value[n_i]
			s2 = value[p_i]
			if len(s1) > len(s2):
				if s1[len(s1) - len(s2):] == s2:
					indexes_to_pop.append(p_i)
			elif len(s1) == len(s2):
				if s1[len(s1) - len(s2):] == s2:
					indexes_to_pop.append(p_i)
			elif s2[len(s2) - len(s1):] == s1:
				indexes_to_pop.append(n_i)
	indexes_to_pop = list(set(indexes_to_pop))
	for index in sorted(indexes_to_pop, reverse=True):
		del value[index]
	final[key] = value
print(len(final))
for (key, value) in final.items():
	print('%s %d' % (key, len(value)), end='')
	for i in value:
		print(' ' + i, end='')
	print()


n = int(input())
l = []
for i in range(n):
	l.append([str(i) for i in input().split()])
for i in range(n):
	l[i] = [l[i][0]] + l[i][2:]
w = []
for i in range(n):
	if [l[i][0]] not in w:
		w.append([l[i][0]])
m = len(w)
for i in range(n):
	for j in range(m):
		if l[i][0] == w[j][0]:
			for k in range(len(l[i]) - 1):
				w[j].append(l[i][k + 1])
for i in range(m):
	if len(w[i]) != 2:
		for j in range(len(w[i]) - 2):
			for k in range(j + 1, len(w[i]) - 1):
				a = w[i][j + 1]
				b = w[i][k + 1]
				s = len(a)
				t = len(b)
				if s >= t:
					if a[-t:] == b:
						w[i][k + 1] = '*'
				elif b[-s:] == a:
					w[i][j + 1] = '*'
c = []
for i in range(m):
	count = 0
	for j in w[i][1:]:
		if j != '*':
			count += 1
	c.append(count)
print(len(w))
for i in range(m):
	print(w[i][0], end=' ')
	print(c[i], end=' ')
	for x in w[i][1:]:
		if x != '*':
			print(x, end=' ')
	print()


a = {}
c = []
n = int(input())
for i in range(n):
	b = input().split()
	if b[0] in c:
		c = c
	else:
		a[b[0]] = []
	if b[0] in c:
		c = c
	else:
		c.append(b[0])
	for j in range(2, len(b)):
		k = 0
		p = -1
		for x in range(len(a[b[0]])):
			if len(a[b[0]][x]) >= len(b[j]):
				if a[b[0]][x][len(a[b[0]][x]) - len(b[j]):] == b[j]:
					k = 1
			elif b[j][len(b[j]) - len(a[b[0]][x]):] == a[b[0]][x]:
				p = x
		if p != -1:
			del a[b[0]][p]
		if k == 0:
			a[b[0]].append(b[j])
print(len(c))
for i in range(len(c)):
	print(c[i], len(a[c[i]]), *a[c[i]])


n = int(input())
p = {}
o = {}
for i in range(n):
	e = input().split()
	if not e[0] in p:
		p[e[0]] = []
	for x in e[2:]:
		p[e[0]].append((len(x), x[::-1]))
for i in p:
	for x in sorted(p[i])[::-1]:
		f = False
		if not i in o:
			o[i] = []
		for z in o[i]:
			f |= x[1] == z or (x[0] < len(z) and x[1] == z[:x[0]])
		if not f:
			o[i].append(x[1])
print(len(o))
for i in o:
	print(i + ' ' + str(len(o[i])) + ' ' + ' '.join((x[::-1] for x in o[i])))


n = int(input())
directory = {}
for _ in range(n):
	(name, k, *nums) = input().split()
	if name in directory:
		directory[name] += nums
	else:
		directory[name] = nums
print(len(directory.keys()))
for name in directory:
	nums = directory[name]
	nums.sort(key=len)
	new_list = []
	for (ind, num) in enumerate(nums):
		l = len(num)
		if all((rest[-l:] != num for rest in nums[ind + 1:])):
			new_list.append(num)
	print(name, len(new_list), *new_list)


n = int(input())
p = {}
for _ in range(n):
	i = input().split()
	name = i[0]
	if name not in p:
		p[name] = i[2:]
	else:
		p[name] += i[2:]
	numbers = sorted(set(p[name]), key=len)
	c = True
	while c:
		c = False
		for x in range(len(numbers)):
			for y in range(x + 1, len(numbers)):
				if len(numbers[x]) != len(numbers[y]):
					if numbers[y][len(numbers[y]) - len(numbers[x]):] == numbers[x]:
						del numbers[x]
						c = True
						break
			if c:
				break
	p[name] = numbers
print(len(p))
for name in p:
	print(name, len(p[name]), ' '.join(p[name]))


n = int(input())
phoneAddr = {}

def SameSearchIndex(arr):
	arrIndex = ['1'] * len(arr)
	for i in range(len(arr)):
		for j in range(len(arr)):
			if arr[i].endswith(arr[j]) and i != j:
				arrIndex[j] = '0'
	return arrIndex
for i in range(n):
	inpt = input().split()
	name = inpt[0]
	phone = inpt[2:]
	if phoneAddr.get(name) == None:
		phoneAddr[name] = phone
	else:
		phoneAddr[name].extend(phone)
print(len(phoneAddr))
for name in phoneAddr:
	phoneAddr[name] = list(set(phoneAddr[name]))
	indx = SameSearchIndex(phoneAddr[name])
	print(name, indx.count('1'), end='')
	for i in range(len(indx)):
		if indx[i] == '1':
			print(' ', phoneAddr[name][i], end='')
	print()


from sys import stdin, stdout
import math
import heapq
from itertools import accumulate
N = int(input())
data = []
for i in range(N):
	s = input()
	data.append(s)
phone = {}
for entry in data:
	e = entry.split(' ')
	if e[0] not in phone:
		phone[e[0]] = []
	for p in e[2:]:
		phone[e[0]].append(p)
k = 0
for person in phone:
	phone[person] = list(set(phone[person]))
	k += 1
print(k)
for person in phone:
	p = phone[person]
	tmp = {}
	for num in p:
		tmp[num] = 1
	for i in range(len(p)):
		s = p[i]
		for k in range(1, len(s)):
			if s[k:] in p:
				tmp[s[k:]] = 0
	valid = 0
	for num in p:
		if tmp[num] == 1:
			valid += 1
	print(person, valid, end=' ')
	for num in p:
		if tmp[num] == 1:
			print(num, end=' ')
	print('', end='\n')


n = int(input())
dct = {}
for i in range(n):
	s = input().split()
	name = s[0]
	if not dct.__contains__(name):
		dct[name] = []
	k = int(s[1])
	for i in range(1, k + 1):
		dct[name].append(s[1 + i])
	arr = dct[name]
	for i in range(len(arr)):
		check = arr[i]
		for j in range(len(arr)):
			if i != j and check == arr[j]:
				arr[i] = '#'
				break
			if len(check) < len(arr[j]):
				if arr[j][len(arr[j]) - len(check):] == check:
					arr[i] = '#'
					break
	new_arr = []
	for i in arr:
		if i != '#':
			new_arr.append(i)
	dct[name] = new_arr
print(len(dct))
for k in dct.keys():
	print(k, len(dct[k]), end=' ')
	for i in range(len(dct[k])):
		print(dct[k][i], end=' ')
	print()


import sys
entries = {}
records = []
for line in sys.stdin.readlines():
	records += [line.replace('\n', '').split(' ')]
records = records[1:]

def check_if_suffixed(s1, s2):
	if len(s1) >= len(s2):
		extra = len(s1) - len(s2)
		if s1[extra:] == s2:
			return s1
	elif len(s1) < len(s2):
		extra = len(s2) - len(s1)
		if s2[extra:] == s1:
			return s2
	return False

def arr_filter(lon):
	result = []
	for ph in lon:
		to_add = True
		for (i, a) in enumerate(result):
			r = check_if_suffixed(ph, a)
			if r == False:
				pass
			elif r == ph:
				to_add = False
				result[i] = ph
			elif r == a:
				to_add = False
			else:
				pass
		if to_add:
			result.append(ph)
	return result
for record in records:
	name = record[0]
	num_ph = record[1]
	if name not in entries:
		entries[name] = []
		for ph in arr_filter(record[2:]):
			entries[name].append(ph)
	elif name in entries:
		for ph in record[2:]:
			to_add = True
			for (i, ph2) in enumerate(entries[name]):
				r = check_if_suffixed(ph, ph2)
				if r == False:
					pass
				else:
					entries[name][i] = r
					to_add = False
			if to_add:
				entries[name].append(ph)
print(len(entries))
for (name, phs) in entries.items():
	out = '{0} {1} '.format(name, len(entries[name]))
	for (i, e) in enumerate(entries[name]):
		out += e
		if i < len(entries[name]) - 1:
			out += ' '
	print(out)


import os, sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil
mod = 10 ** 9 + 7

def get_suffix(numbers):
	l = ['' for _ in range(len(numbers))]
	for i in range(len(numbers) - 1, -1, -1):
		if i == len(numbers) - 1:
			l[i] = numbers[i]
		else:
			l[i] = numbers[i] + l[i + 1]
	return l

def get_numbers_count(x):
	count = 0
	for k in x:
		if x[k]:
			count += 1
	return count
for _ in range(1):
	n = int(input())
	info = {}
	for i in range(n):
		info1 = input().split(' ')
		name = info1[0]
		if name not in info:
			info[name] = {}
		for numbers in info1[2:]:
			if numbers not in info[name]:
				info[name][numbers] = get_suffix(numbers)
	for (name, values) in info.items():
		for (num, suffixes) in info[name].items():
			if info[name][num] != 0:
				cn = num
				for (num1, suffixes1) in info[name].items():
					if info[name][num1] != 0 and num1 != cn and (cn in suffixes1):
						info[name][cn] = 0
	print(get_numbers_count(info))
	for name in info:
		print(name, get_numbers_count(info[name]), end=' ')
		for k in info[name]:
			if info[name][k] != 0:
				print(k, end=' ')
		print()


def check(a, b):
	(p, q) = (len(a), len(b))
	if p > q:
		return 0
	else:
		t = 0
		for i in range(p):
			if a[p - 1 - i] == b[q - 1 - i]:
				t = t + 1
		if t == p:
			return 1
		return 0
n = int(input())
a = {}
g = {}
for _ in range(n):
	b = list(input().split())
	m = b[0]
	p = int(b[1])
	c = b[2:]
	if m in a:
		for i in range(p):
			a[m].append(c[i])
	else:
		a[m] = []
		for i in range(p):
			a[m].append(c[i])
for i in a:
	k = a[i]
	k = list(set(k))
	a[i] = k
for i in a:
	k = a[i]
	b = set()
	l = len(k)
	for j in range(l):
		p = 0
		for x in range(l):
			if j != x:
				p += check(k[j], k[x])
		if p >= 1:
			b.add(j)
	w = []
	for j in range(l):
		if j in b:
			continue
		else:
			w.append(k[j])
	g[i] = w
print(len(g))
for i in g:
	print(i, end=' ')
	print(len(g[i]), end=' ')
	for j in g[i]:
		print(j, end=' ')
	print()


n = int(input())
L = []
m = {}
names = []
for i in range(n):
	a = input().split()
	name = a[0]
	names.append(a[0])
	a = a[2:]
	if name not in m:
		m[name] = []
	for j in a:
		m[name].append(j)
names = set(names)
for i in names:
	a = list(set(m[i]))
	good = [True] * len(a)
	for j in range(len(a)):
		for k in range(len(a)):
			if j != k:
				if a[k].endswith(a[j]):
					good[j] = False
					break
	ok = False
	cnt = 0
	for j in range(len(a)):
		if good[j] == True:
			cnt += 1
			ok = True
	if ok == False:
		continue
	out = i + ' ' + str(cnt)
	for j in range(len(a)):
		if good[j]:
			out += ' ' + a[j]
	L.append(out)
print(len(L))
for i in L:
	print(i)
exit(0)


n = input()
notes = list()
d = dict()

def isSuffix(a, b):
	lb = len(b)
	la = len(a)
	if la > lb:
		return False
	for i in range(0, la):
		if a[i] != b[lb - la + i]:
			return False
	return True

def shotNote(note):
	i = 0
	ln = len(note)
	while i < ln:
		j = -1
		while j < ln - 1:
			j += 1
			if i != j and isSuffix(note[i], note[j]):
				note.pop(i)
				ln = len(note)
				i -= 1
				break
		i += 1
	return note
for i in range(0, int(n)):
	s = input().split()
	name = s[0]
	s.pop(0)
	s.pop(0)
	if d.get(name) == None:
		d.update({name: list(s)})
	else:
		d.update({name: list(set(d.get(name)).union(s))})
print(str(len(d)))
for (key, value) in d.items():
	shotNote(value)
	print(str(key) + ' ' + str(len(value)) + ' ' + ' '.join(value))


from sys import stdin
n = int(stdin.readline().strip())
d = dict()
for i in range(n):
	s = stdin.readline().strip().split()
	if s[0] in d:
		d[s[0]] += s[2:]
	else:
		d.update({s[0]: s[2:]})
for i in d:
	d[i] = list(set(d[i]))
	rem = []
	for j in range(len(d[i])):
		for k in range(len(d[i])):
			if k != j and len(d[i][k]) >= len(d[i][j]) and (d[i][k][len(d[i][k]) - len(d[i][j]):] == d[i][j]):
				rem.append(d[i][j])
	rem = set(rem)
	for j in rem:
		d[i].remove(j)
print(len(d))
for j in d:
	print(j, len(d[j]), *d[j])


def check(str1, str2):
	for i in range(len(str1)):
		if str1[i] != str2[i]:
			return False
	return True

def main():
	n = int(input())
	pdict = {}
	for i in range(n):
		ls = []
		tmp = [x for x in input().split()]
		name = tmp[0]
		if name not in pdict:
			pdict[name] = []
		for j in range(2, len(tmp)):
			ls.append(tmp[j])
		pdict[name] += ls
	for key in pdict:
		pdict[key] = list(set(pdict[key]))
		tmp = pdict[key]
		for i in range(len(tmp)):
			tmp[i] = tmp[i][::-1]
		tmp = list(sorted(tmp))
		dels = []
		for i in range(len(tmp)):
			for j in range(i + 1, len(tmp)):
				if check(tmp[i], tmp[j]):
					dels.append(i)
					break
		for i in reversed(range(len(dels))):
			del tmp[dels[i]]
		for i in range(len(tmp)):
			tmp[i] = tmp[i][::-1]
		pdict[key] = tmp
	slist = []
	for key in pdict:
		s = ''
		s += key + ' ' + str(len(pdict[key]))
		for el in pdict[key]:
			s += ' ' + el
		slist.append(s)
	print(len(slist))
	for el in slist:
		print(el)
main()


n = int(input())
d = dict()
for i in range(n):
	m = input().split()
	if m[0] not in d:
		d[m[0]] = set()
	d[m[0]].update(set(m[2:]))
p = []
for i in d:
	m = list(d[i])
	x = 0
	while x < len(m):
		k = x + 1
		while k < len(m):
			if m[x].endswith(m[k]):
				m.pop(k)
			elif m[k].endswith(m[x]):
				m.pop(x)
				break
			else:
				k += 1
		else:
			x += 1
	p.append(i + ' ' + str(len(m)) + ' ' + ' '.join(m))
print(len(p))
for i in p:
	print(i)


n = int(input())
friends = {}
for _ in range(n):
	data = input().split()
	name = data[0]
	numbers = set(data[2:])
	if name in friends:
		friends[name].update(numbers)
	else:
		friends[name] = numbers
print(len(friends))
for (friend, numbers) in friends.items():
	used = numbers.copy()
	for x in numbers:
		for y in numbers:
			if x == y:
				continue
			if x not in used or y not in used:
				continue
			if y.endswith(x):
				used.remove(x)
	print(friend, len(used), *used)


import collections
import itertools
INVALID = '***'

def in_place_parse_book(book):
	for key in book.keys():
		names = book[key]
		m = len(names)
		for (i, j) in itertools.combinations(range(m), 2):
			if names[i] == INVALID or names[j] == INVALID:
				continue
			if names[i].endswith(names[j]):
				names[j] = INVALID
			elif names[j].endswith(names[i]):
				names[i] = INVALID
		ns = set(names)
		ns.discard(INVALID)
		book[key] = list(ns)

def main():
	n = int(input())
	book = collections.defaultdict(list)
	for _ in range(n):
		args = input().split()
		name = args[0]
		numbers = args[2:]
		book[name].extend(numbers)
	in_place_parse_book(book)
	print(len(book))
	for (k, v) in book.items():
		m = len(v)
		print('{} {} '.format(k, m) + ' '.join(map(str, v)))
main()


R = lambda t: tuple(map(t, input().split()))
rn = lambda : R(int)
n = rn()[0]
ans = {}
for i in range(n):
	v = input().split()
	if not v[0] in ans:
		ans[v[0]] = []
	ans[v[0]] += v[2:]
for k in ans:
	(l, dl) = (list(set(ans[k])), set())
	for i in range(len(l)):
		for j in range(len(l)):
			(v1, v2) = (l[i], l[j])
			if i != j and len(v1) <= len(v2) and (v2[-len(v1):] == v1):
				dl.add(i)
	ans[k] = [v for (i, v) in enumerate(l) if not i in dl]
print(len(ans))
for (k, v) in ans.items():
	print(k, len(v), *v)


n = int(input())
data = {}
for i in range(n):
	lst = list(input().split())
	name = lst[0]
	lst = lst[2:]
	if name not in data.keys():
		data[name] = set()
	for item in lst:
		data[name].add(item)
print(len(data))
for key in data:
	print(key, end=' ')
	result = []
	for item1 in data[key]:
		ok = True
		for item2 in data[key]:
			if item1 == item2:
				continue
			if item2.endswith(item1):
				ok = False
				break
		if not ok:
			continue
		else:
			result.append(item1)
	print(len(result), end=' ')
	for item in result:
		print(item, end=' ')
	print()


import random
import math
from collections import defaultdict
import itertools
from sys import stdin, stdout
import sys
import operator
from decimal import Decimal
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()

def main():
	n = int(input())
	d = defaultdict(list)
	for i in range(n):
		l = [i for i in input().split()]
		for j in range(int(l[1])):
			if l[2 + j] not in d[l[0]]:
				d[l[0]].append(l[2 + j])
	ans = defaultdict(list)
	for k in d.keys():
		d[k].sort()
		d[k].sort(key=len)
		j = 0
		while j < len(d[k]) - 1:
			for l in range(j + 1, len(d[k])):
				l1 = len(d[k][l])
				l2 = len(d[k][j])
				if l1 > l2:
					if d[k][l][l1 - l2:] == d[k][j]:
						d[k].remove(d[k][j])
						j -= 1
						break
			else:
				j += 1
	print(len(d))
	for k in d.keys():
		ans = k + ' ' + str(len(d[k])) + ' '
		ans += ' '.join(d[k])
		print(ans)
main()


n = int(input())
book = {}
for _ in range(n):
	toks = input().strip().split()
	name = toks[0]
	numbers = toks[2:]
	book.setdefault(name, [])
	book[name].extend(numbers)
print(len(book))
for (k, v) in book.items():
	v.sort(key=lambda x: len(x))
	new_v = []
	for i in range(len(v)):
		if any((v[j].endswith(v[i]) for j in range(i + 1, len(v)))):
			continue
		new_v.append(v[i])
	v = new_v
	print(k, len(v), *v)


import sys
import math as mt
import bisect
t = 1

def solve():
	for i in d:
		ind = {}
		d[i] = list(set(d[i]))
		for j1 in range(len(d[i])):
			for j2 in range(len(d[i])):
				s1 = d[i][j1]
				s2 = d[i][j2]
				if j1 != j2:
					last = len(s1)
					if len(s1) < len(s2):
						if s2[len(s2) - last:] == s1:
							ind[s1] = 1
		for j in ind:
			d[i].remove(j)
	print(len(d))
	for i in d:
		print(i, len(d[i]), end=' ')
		for j in d[i]:
			print(j, end=' ')
		print()
for _ in range(t):
	n = int(input())
	d = {}
	for i in range(n):
		l = list(input().split())
		if d.get(l[0], -1) == -1:
			d[l[0]] = []
		ind = 2
		for j in range(int(l[1])):
			d[l[0]].append(l[ind])
			ind += 1
	solve()


c = int(input())
d = {}
t = {}
for i in range(c):
	s = input().split()
	if s[0] not in t:
		t[s[0]] = []
	for m in s[2:]:
		t[s[0]].append(m)
for i in t:
	d[i] = []
	u = set(t[i])
	q = []
	for p in u:
		q.append(p)
	for j in range(len(q)):
		a = q[j][::-1]
		z = 0
		for k in range(len(q)):
			b = q[k][::-1]
			if j != k and b.find(a) != -1:
				if b.find(a) == 0:
					z = 1
					break
		if z == 0:
			d[i].append(a[::-1])
print(len(d))
for i in d:
	print(i, len(d[i]), end=' ')
	for j in d[i]:
		print(j, end=' ')
	print('\n')


n = int(input())
d = dict()
for i in range(n):
	(name, x, *nums) = input().split()
	if name in d:
		d[name] |= set(nums)
	else:
		d[name] = set(nums)
newd = dict()
for (name, nums) in d.items():
	for j in nums:
		fl = False
		for u in nums:
			if j == u:
				continue
			s = ''
			for v in range(len(u) - 1, -1, -1):
				s = u[v] + s
				if j == s:
					fl = True
					break
			if fl:
				break
		else:
			if name in newd:
				newd[name].add(j)
			else:
				newd[name] = set([j])
print(len(newd))
print('\n'.join(map(lambda x: x[0] + ' ' + str(len(x[1])) + ' ' + ' '.join(x[1]), newd.items())))


n = int(input())
d = {}
for i in range(n):
	line = input().split()
	try:
		d[line[0]]
	except:
		d[line[0]] = []
	for z in range(2, len(line)):
		d[line[0]].append(line[z])
for name in d:
	for i in range(len(d[name])):
		for j in range(len(d[name])):
			if i != j and d[name][i] != None and (d[name][j] != None):
				if d[name][i].endswith(d[name][j]):
					d[name][j] = None
				elif d[name][j].endswith(d[name][i]):
					d[name][i] = None
print(len(d))
for name in d:
	print(name, end=' ')
	nums = []
	for i in d[name]:
		if i != None:
			nums.append(i)
	print(len(nums), end=' ')
	print(*nums)


n = int(input())
entries = {}
for _ in range(n):
	(name, _, *nums) = input().split()
	if name not in entries:
		entries[name] = set()
	for num in nums:
		for k in tuple(entries[name]):
			if k.endswith(num):
				break
			elif num.endswith(k):
				entries[name].add(num)
				entries[name].remove(k)
				break
		else:
			entries[name].add(num)
print(len(entries))
for (name, nums) in entries.items():
	print(name, len(nums), *nums)


def check(a, s1, s2):
	(s1, s2) = (str(s1), str(s2))
	if s1[len(s1) - len(s2):len(s1)] == s2:
		return True
	elif s1 == s2 or not s2 in a:
		return False
n = int(input())
name = []
phone = []
for i in range(n):
	a = list(input().split())
	if not a[0] in name:
		name.append(a[0])
		phone.append(a[2:2 + int(a[1])])
	else:
		phone[name.index(a[0])] += a[2:2 + int(a[1])]
ans = []
for i in range(len(phone)):
	phone[i] = list(set(phone[i]))
	ans.append([])
for i in range(len(phone)):
	for j in range(len(phone[i])):
		kek = 0
		for k in range(len(phone[i])):
			if j != k and check(ans[i], phone[i][k], phone[i][j]):
				kek += 1
		if kek == 0:
			ans[i].append(phone[i][j])
print(len(name))
for i in range(len(name)):
	print(name[i], len(ans[i]), *ans[i])


def solve(a):
	res = []
	a.sort(key=lambda x: len(x))
	n = len(a)
	for i in range(n):
		fl = True
		for j in range(i + 1, n):
			if a[j][-len(a[i]):] == a[i]:
				fl = False
				break
		if fl:
			res.append(a[i])
	print(len(res), *res)
n = int(input())
d = dict()
for i in range(n):
	tmp = input().split()
	name = tmp[0]
	if name not in d:
		d[name] = []
	d[name] += tmp[2:]
print(len(d))
for i in d:
	print(i, end=' ')
	solve(d[i])


n = int(input())

def check(c, b):
	r = len(c)
	for i in range(r - 1, -1, -1):
		if c[i:r] == b:
			return True
	return False
dic = {}
for x in range(n):
	a = list(map(str, input().strip().split()))
	if a[0] in dic:
		sl = a[2:]
		for i in sl:
			flag = 1
			for j in dic[a[0]]:
				if check(j, i) == True:
					flag = 0
				elif check(i, j) == True:
					dic[a[0]].remove(j)
				else:
					pass
			if flag == 1:
				dic[a[0]].append(i)
	else:
		dic[a[0]] = []
		sl = a[2:]
		for i in sl:
			flag = 1
			for j in dic[a[0]]:
				if check(j, i) == True:
					flag = 0
				elif check(i, j) == True:
					dic[a[0]].remove(j)
				else:
					pass
			if flag == 1:
				dic[a[0]].append(i)
print(len(dic))
for i in dic:
	print(i, len(dic[i]), ' '.join(dic[i]))


n = int(input())
d = dict()
for i in range(n):
	a = [i for i in input().split()]
	if a[0] not in d.keys():
		d[a[0]] = set()
	for j in range(2, len(a)):
		d[a[0]].add(a[j])
print(len(d))

def check(a, b):
	if a not in b:
		return 0
	return b.rfind(a) + len(a) == len(b)
for (nm, a) in d.items():
	(bad, a) = (set(), list(a))
	for i in range(len(a)):
		for j in range(i + 1, len(a)):
			if check(a[i], a[j]):
				bad.add(i)
			if check(a[j], a[i]):
				bad.add(j)
	print(nm, len(a) - len(bad), end=' ')
	for i in range(len(a)):
		if i not in bad:
			print(a[i], end=' ')
	print()


n = int(input())
s = set()
arr = []
a = {}
for i in range(n):
	rr = list(map(str, input().strip().split(' ')))
	arr.append(rr)
for i in range(n):
	t = arr[i]
	s.add(t[0])
	try:
		p = a[t[0]]
		for j in range(2, 2 + int(t[1])):
			a[t[0]].append(t[j])
	except:
		p = t[2]
		a[t[0]] = [p]
		for j in range(3, 2 + int(t[1])):
			a[t[0]].append(t[j])
for ii in s:
	p = a[ii]
	p = list(set(p))
	for i in range(len(p)):
		if p[i] != '-1':
			tt = p[i]
			for j in range(len(p)):
				if j != i:
					pp = p[j]
					if len(pp) >= len(tt):
						continue
					else:
						y = 0
						ans = 0
						for uu in range(len(tt) - len(pp), len(tt)):
							if tt[uu] != pp[y]:
								ans = 1
							y += 1
						if ans == 0:
							p[j] = '-1'
	d = []
	cnt = 0
	for oo in p:
		if oo != '-1':
			cnt += 1
	d.append(cnt)
	for oo in p:
		if oo != '-1':
			d.append(oo)
	a[ii] = d
print(len(s))
for i in s:
	print(i, end=' ')
	t = a[i]
	for j in t:
		print(j, end=' ')
	print()


def print_arr(arr):
	for i in arr:
		print(i, '', end='')
	print()
n = int(input())
d = {}
for _ in range(n):
	(name, num, *numbers) = input().split()
	if name in d:
		s = d[name]
	else:
		s = []
	for nm in numbers:
		for i in s:
			if i.endswith(nm):
				state = 1
				break
			if nm.endswith(i):
				s.remove(i)
		else:
			s.append(nm)
	d[name] = s
print(len(d))
for name in d:
	print(name, len(d[name]), end=' ')
	print_arr(d[name])


n = int(input())
d = dict()
bad = dict()
inp = dict()
for i in range(n):
	tmp = [z for z in input().split()]
	name = tmp[0]
	num = int(tmp[1])
	a = tmp[2:]
	if name not in d:
		inp[name] = []
		d[name] = []
		bad[name] = set()
	for elem in a:
		inp[name].append(elem)
for name in inp:
	cur = inp[name]
	cur.sort(key=lambda x: len(x), reverse=True)
	for elem in cur:
		if elem not in bad[name]:
			d[name].append(elem)
			for l in range(len(elem)):
				bad[name].add(elem[l:])
print(len(d))
for elem in d:
	print(elem, end=' ')
	print(len(d[elem]), end=' ')
	for i in range(len(d[elem]) - 1):
		print(d[elem][i], end=' ')
	print(d[elem][-1])


def cmp(x):
	return len(x)

def check(x, y):
	for i in range(len(y) - len(x), len(y)):
		if x[i - len(y) + len(x)] != y[i]:
			return False
	return True
n = int(input())
d = {}
for i in range(n):
	arr = list(input().split())
	if arr[0] in d:
		d[arr[0]] = d[arr[0]] + arr[2:]
	else:
		d[arr[0]] = arr[2:]
print(len(d))
for person in d:
	t = d[person]
	print(person, end=' ')
	t.sort(key=cmp)
	s = len(t)
	ans = []
	for j in range(len(t)):
		for k in range(j + 1, len(t)):
			if check(t[j], t[k]) == True:
				s -= 1
				break
		else:
			ans.append(t[j])
	print(s, end=' ')
	for x in ans:
		print(x, end=' ')
	print('')


n = int(input())
phonebook = {}
for i in range(n):
	s = input().split()
	del s[1]
	if s[0] in phonebook.keys():
		phonebook[s[0]] += s[1:]
	else:
		phonebook[s[0]] = s[1:]
phonebookvals = []
for a in phonebook.keys():
	items = phonebook[a]
	lendict = len(items)
	index1 = 0
	index2 = 0
	newvals = []
	c = 0
	while index1 < len(items) and len(items) != 1:
		if items[index1][-1] == items[index2][-1] and index1 != index2:
			lena = len(items[index1])
			lenb = len(items[index2])
			if lena > lenb:
				if items[index1][-lenb:] == items[index2]:
					items.remove(items[index2])
					index1 = 0
					index2 = 0
				else:
					index2 += 1
			elif items[index2][-lena:] == items[index1]:
				items.remove(items[index1])
				index1 = 0
				index2 = 0
			else:
				index2 += 1
		else:
			index2 += 1
		if index2 >= len(items):
			index2 = 0
			index1 += 1
	phonebookvals.append(list(set(items)))
b = 0
print(len(phonebook.keys()))
for a in phonebook.keys():
	strg = ' '.join(phonebookvals[b])
	print(a, len(phonebookvals[b]), strg)
	b += 1


n = int(input())
d = {}
for _ in range(n):
	a = list(input().split())
	name = a[0]
	cnt = int(a[1])
	bfr = a[2:]
	if name in d:
		for bf in bfr:
			s = d[name]
			x = set()
			for i in s:
				if bf.endswith(i):
					x.add(i)
			s = s.difference(x)
			if not any((i.endswith(bf) for i in s)):
				s.add(bf)
			d[name] = s
	else:
		d[name] = set()
		for bf in bfr:
			s = d[name]
			x = set()
			for i in s:
				if bf.endswith(i):
					x.add(i)
			s = s.difference(x)
			if not any((i.endswith(bf) for i in s)):
				s.add(bf)
			d[name] = s
print(len(d))
for i in d:
	print(i, end=' ')
	s = d[i]
	print(len(s), end=' ')
	for j in s:
		print(j, end=' ')
	print()


n = int(input())
d = {}
for i in range(n):
	lis = list(map(str, input().split()))
	if lis[0] not in d:
		d[lis[0]] = list(set(lis[2:]))
	else:
		d[lis[0]] = list(set(lis[2:] + d[lis[0]]))
for _ in d:
	a = d[_]
	ans = []
	l = len(a)
	for i in range(l):
		c = 1
		k = len(a[i])
		for j in range(l):
			if i != j and a[i] == a[j][-k:]:
				c = 0
		if c:
			ans.append(a[i])
	d[_] = ans
print(len(d))
for i in d:
	print(i, len(d[i]), *d[i])


n = int(input())
from collections import defaultdict
d = defaultdict(list)
for i in range(n):
	s = input().split()
	a = s[0]
	b = s[2:]
	for x in b:
		if x not in d[a]:
			d[a].append(x)
for i in d:
	curr = d[i]
	ans = curr[:]
	curr.sort(key=lambda x: -len(x))
	le = len(curr)
	for x in range(le - 1, -1, -1):
		for j in range(0, x):
			if curr[j].endswith(curr[x]):
				try:
					ans.remove(curr[x])
				except:
					pass
	d[i] = ans
print(len(d))
for i in d:
	print(i, end=' ')
	print(len(d[i]), end=' ')
	print(*d[i])


from math import *
import copy

def func(arr):
	arr = list(set(arr))
	arr = sorted(arr, key=len)
	c = len(arr)
	for i in range(c - 1):
		for j in range(i + 1, c):
			istrue = True
			for k in range(0, len(arr[i])):
				if arr[i][len(arr[i]) - 1 - k] != arr[j][len(arr[j]) - 1 - k]:
					istrue = False
					break
			if istrue == True:
				arr[i] = -1
				break
	arr = list(filter(lambda x: x != -1, arr))
	return arr
n = int(input())
d = dict()
name = []
for _ in range(n):
	arr = list(map(str, input().split()))
	if arr[0] not in name:
		d[arr[0]] = arr[2:]
		name.append(arr[0])
	else:
		d[arr[0]] += arr[2:]
for i in range(len(name)):
	arr = copy.deepcopy(d[name[i]])
	d[name[i]] = func(arr)
print(len(name))
for i in range(len(name)):
	print(name[i], len(d[name[i]]), end=' ')
	for x in d[name[i]]:
		print(x, end=' ')
	print()


n = int(input())
friends = dict()
for _ in range(n):
	line = input().strip().split()
	if line[0] not in friends:
		friends[line[0]] = set()
	for i in range(2, len(line)):
		friends[line[0]].add(line[i])

def order(S):
	S2 = [(len(e), e) for e in S]
	S2.sort()
	real = set()
	for i in range(len(S2)):
		(d, e) = S2[i]
		flag = True
		for j in range(i + 1, len(S2)):
			x = S2[j][1]
			if x[-d:] == e:
				flag = False
				break
		if flag:
			real.add(e)
	return real
print(len(friends))
for f in friends:
	nums = order(friends[f])
	st = ' '.join(nums)
	print(f + ' ' + str(len(nums)) + ' ' + st)


n = int(input())
M = {}
for _ in range(n):
	line = input().strip().split()
	M[line[0]] = M.get(line[0], set()) | set(line[2:])
ans = []
for (name, S) in M.items():
	L = sorted(list(S), key=lambda s: len(s), reverse=True)
	for (i, s1) in enumerate(L):
		if s1 not in S:
			continue
		for s2 in L[i + 1:]:
			if s2 in S and s2 == s1[-len(s2):]:
				S -= set([s2])
	ans.append([name, list(S)])
print(len(ans))
for elm in ans:
	print(elm[0], len(elm[1]), end=' ')
	for s in elm[1]:
		print(s, end=' ')
	print()


from collections import defaultdict
from sys import stderr
n = int(input())
friends = defaultdict(lambda : set())
for i in range(n):
	(name, _, *numbers) = input().split()
	for number in numbers:
		skip_number = False
		for old_number in list(friends[name]):
			if number.endswith(old_number):
				friends[name].remove(old_number)
			elif old_number.endswith(number):
				skip_number = True
		if not skip_number:
			friends[name].add(number)
print(len(friends))
for name in friends:
	print('{} {} {}'.format(name, len(friends[name]), ' '.join(friends[name])))


n = int(input())
dic = {}
for i in range(n):
	y = input().split()
	try:
		dic[y[0]]
	except:
		dic[y[0]] = []
	for i in range(2, len(y)):
		dic[y[0]].append(y[i])
print(len(dic.keys()))
for k in dic.keys():
	l = dic[k]
	y = sorted(l, key=lambda x: len(x))
	new_y = []
	n = len(y)
	stat = False
	for i in range(0, n):
		stat = False
		curr_i = y[i]
		curr_len = len(y[i])
		for j in range(i + 1, n):
			if stat:
				continue
			if y[j][-curr_len:] == curr_i:
				stat = True
				break
		if stat:
			continue
		if not stat:
			new_y.append(y[i])
			stat = False
	print(k, end=' ')
	print(len(new_y), end=' ')
	for i in new_y:
		print(i, end=' ')
	print()


n = int(input())
peo = dict()
for i in range(n):
	(na, a, *k) = input().split()
	for j in range(int(a)):
		peo[na] = peo.get(na, [])
		peo[na].append(k[j])
pr = []
for na in peo.keys():
	l = len(peo[na])
	li = [0] * l
	for i in range(l):
		for j in range(i + 1, l):
			l1 = len(peo[na][i])
			l2 = len(peo[na][j])
			if peo[na][i] == peo[na][j]:
				li[i] = -1
			elif len(peo[na][i]) > len(peo[na][j]):
				if peo[na][i][l1 - l2:] == peo[na][j]:
					li[j] = -1
			elif len(peo[na][j]) > len(peo[na][i]):
				if peo[na][j][l2 - l1:] == peo[na][i]:
					li[i] = -1
	pk = []
	for i in range(len(li)):
		if not li[i]:
			pk.append(peo[na][i])
	pr.append((na, len(pk), pk))
if len(pr):
	print(len(pr))
	for i in pr:
		print(i[0], i[1], *i[2])


from sys import stdin, stdout
n = int(stdin.readline().rstrip())
nameDict = {}
for _ in range(n):
	s = stdin.readline().rstrip().split()
	name = s[0]
	if name not in nameDict:
		nameDict[name] = set()
	for number in s[2:]:
		nameDict[name].add(number)
for name in list(nameDict.keys()):
	rem = set()
	for no1 in nameDict[name]:
		for no2 in nameDict[name]:
			if no1 == no2:
				continue
			l1 = len(no1)
			l2 = len(no2)
			if l1 < l2 and no2[-l1:] == no1:
				rem.add(no1)
	for no in rem:
		nameDict[name].remove(no)
print(len(list(nameDict.keys())))
for name in list(nameDict.keys()):
	print(' '.join([name, str(len(nameDict[name]))] + list(nameDict[name])))


def clean(l):
	l = list(set(l))
	l.sort()
	ans = []
	for i in range(len(l)):
		for j in range(0, len(l)):
			if l[j].endswith(l[i]) and i != j:
				break
		else:
			ans += [l[i]]
	return ans
d = dict()
for t in range(int(input())):
	l = [x for x in input().split(' ')]
	(name, x) = (l[0], [1])
	l = l[2:]
	if name in d:
		d[name] += l
	else:
		d[name] = l
keys = d.keys()
print(len(keys))
for k in keys:
	l = clean(d[k])
	print(k, len(l), *l)


import sys
input = sys.stdin.readline
from collections import *

def judge(s, t):
	return s[len(s) - len(t):] == t
d = defaultdict(set)
for _ in range(int(input())):
	l = list(input().split())
	for num in l[2:]:
		d[l[0]].add(num)
print(len(d))
for k in d.keys():
	ans = []
	for num1 in d[k]:
		flag = True
		for num2 in d[k]:
			if num1 == num2:
				continue
			if judge(num2, num1):
				flag = False
		if flag:
			ans.append(num1)
	print(k, len(ans), *ans)


n = int(input())
d = {}

def suffix(x, y):
	if x in y:
		for k in range(1, len(y)):
			if y[k:] == x:
				return True
	return False
for i in range(n):
	info = input().split()
	name = info[0]
	nnumber = int(info[1])
	numbers = info[2:]
	if name in d.keys():
		d[name] = d[name] + numbers
	else:
		d[name] = numbers
print(len(d.keys()))
for names in d.keys():
	d[names] = list(set(d[names]))
	L = []
	for j in range(len(d[names])):
		judge = 0
		for l in range(len(d[names])):
			if l != j:
				if suffix(d[names][j], d[names][l]) == True:
					judge = 1
					break
		if judge == 0:
			L.append(d[names][j])
	Lmax = [names, str(len(L))] + L
	print(' '.join(Lmax))


entries = int(input())
contacts_dict = {}
for entry in range(entries):
	contact = list(input().split())
	if contact[0] not in contacts_dict:
		contacts_dict[contact[0]] = []
	for nr in contact[2:]:
		contacts_dict[contact[0]].append(nr)
for key in contacts_dict:
	numbers = []
	new_numbers = []
	for value in contacts_dict[key]:
		numbers.append(value)
		numbers.sort(key=len)
	for number in range(len(numbers) - 1):
		add_new = True
		number1 = numbers[number]
		nr_length = len(number1)
		for number2 in numbers[number + 1:]:
			if str(number2)[-nr_length:] == number1:
				add_new = False
				break
		if add_new:
			new_numbers.append(number1)
	new_numbers.append(numbers[-1])
	contacts_dict[key] = new_numbers
print(len(contacts_dict))
for key in contacts_dict:
	out_string = key
	out_string += ' '
	out_string += str(len(contacts_dict[key]))
	for value in contacts_dict[key]:
		out_string += ' '
		out_string += str(value)
	print(out_string)


n = int(input())
dic = dict()
for _ in range(n):
	s = input().split()
	dic[s[0]] = dic.get(s[0], '') + ' '.join(s[2:]) + ' '
print(len(dic))
for i in dic:
	s = list(set(dic[i].split()))
	j = 0
	while j < len(s):
		k = 0
		while k < len(s):
			if s[j] != s[k] and s[j] == s[k][-len(s[j]):]:
				s.pop(j)
				j -= 1
				break
			k += 1
		j += 1
	print(i, len(s), *s)


n = int(input())
(d, res) = ({}, 0)
for i in range(n):
	s = input().split()
	(friend, m, numb) = (s[0], s[1], list(set(s[2:])))
	if d.get(friend) == None:
		d[friend] = []
		res += 1
	d[friend].extend(numb)
	d[friend] = list(set(d[friend]))
print(res)
for (i, friend) in enumerate(d):
	numb = d[friend]
	(lst, res) = ([], 0)
	for (i, x) in enumerate(numb):
		(k, a) = (0, len(x))
		for (j, y) in enumerate(numb):
			if x != y:
				if x == y[-a:]:
					k = 1
					break
		if k == 0:
			lst.append(x)
			res += 1
	print(friend, res, *lst)


t = int(input())
d = {}
for _ in range(t):
	arr = input().split()
	if arr[0] in d.keys():
		d[arr[0]] += arr[2:]
	else:
		d[arr[0]] = arr[2:]
for i in d:
	for j in range(len(d[i])):
		for k in range(len(d[i])):
			if j == k:
				continue
			if len(d[i][j]) >= len(d[i][k]) and d[i][j][-len(d[i][k]):] == d[i][k]:
				d[i][k] = '.'
print(len(d))
for i in d:
	d[i] = [d[i][j] for j in range(len(d[i])) if d[i][j] != '.']
	print(i, len(d[i]), *d[i])


n = int(input())
a = {}
for i in range(n):
	q = input().split()
	if q[0] in a:
		a[q[0]] += q[2:]
	else:
		a[q[0]] = q[2:]
print(len(a))
for w in a:
	b = a[w]
	b.sort(key=lambda x: len(x))
	i = 0
	while True:
		j = i + 0
		while j != len(b) - 1:
			j += 1
			if b[i] == b[j][len(b[j]) - len(b[i]):]:
				del b[i]
				break
		else:
			i += 1
		if i == len(b):
			break
	print(w, len(b), *b)


n = int(input())
d = {}
gaboleh = {}
while n > 0:
	sem = input().split()
	now = sem[0]
	if now not in d:
		d[now] = []
		gaboleh[now] = set()
	for i in range(len(sem)):
		if i >= 2:
			if sem[i] not in gaboleh[now]:
				d[now].append(sem[i])
				for x in range(1, len(sem[i])):
					gaboleh[now].add(sem[i][x:])
	n -= 1
for nama in d:
	d[nama] = set(d[nama])
	d[nama] = list(d[nama])
for nama in d:
	idx = 0
	while idx < len(d[nama]):
		if d[nama][idx] in gaboleh[nama]:
			del d[nama][idx]
			idx = 0
		idx += 1
print(len(d))
for (i, j) in d.items():
	print(i, len(d[i]), end=' ')
	for x in range(len(j)):
		if x != len(j) - 1:
			print(j[x], end=' ')
		else:
			print(j[x])


n = int(input())
l = [[] for i in range(n + 1)]
l[0] = [0]
for i in range(n):
	k = input().split()
	if k[0] in l[0]:
		g = l[0].index(k[0])
	else:
		l[0].append(k[0])
		g = len(l[0]) - 1
	for j in range(2, int(k[1]) + 2):
		h = 0
		for x in range(len(l[g])):
			for y in range(1, len(l[g][x]) + 1):
				if l[g][x][-y:] == k[j]:
					h = 1
			for y in range(1, len(k[j]) + 1):
				if k[j][-y:] == l[g][x]:
					h = 1
					l[g][x] = k[j]
		if h == 0:
			l[g].append(k[j])
print(len(l[0]) - 1)
loop = ''
for i in range(1, len(l[0])):
	loop = l[0][i] + ' ' + str(len(l[i]))
	for j in range(len(l[i])):
		loop = loop + ' ' + str(l[i][j])
	print(loop)


from collections import defaultdict

def fix(nums):
	nums.sort(key=len, reverse=True)
	seen = set()
	fin = []
	for x in nums:
		if x in seen:
			continue
		fin.append(x)
		for i in range(len(x)):
			seen.add(x[i:])
	return fin

def main():
	n = int(input())
	by_name = defaultdict(list)
	for _ in range(n):
		line = input().split()
		name = line[0]
		nums = line[2:]
		by_name[name] += nums
	print(len(by_name))
	for (name, nums) in by_name.items():
		fixed = fix(nums)
		print(name, len(fixed), ' '.join((str(x) for x in fixed)))
main()


n = int(input())
m = []
for oo in range(n):
	m.append(input().split())
	i = 2
	while i < len(m[oo]):
		j = 2
		while j < len(m[oo]):
			if i != j:
				res = m[oo][i].rfind(m[oo][j])
				if res != -1 and res == len(m[oo][i]) - len(m[oo][j]):
					m[oo].pop(j)
					break
			j += 1
		i += 1
	m[oo][1] = str(len(m[oo]) - 2)
i = 0
while i < len(m):
	j = i + 1
	while j < len(m):
		if i != j:
			if m[i][0] == m[j][0]:
				while len(m[j]) > 2:
					m[i].append(m[j].pop(2))
				m.pop(j)
				j -= 1
		j += 1
	i += 1
n = len(m)
dd = True
while dd:
	dd = False
	for oo in range(n):
		i = 2
		while i < len(m[oo]):
			j = 2
			while j < len(m[oo]):
				if i != j:
					res = m[oo][i].rfind(m[oo][j])
					if res != -1 and res == len(m[oo][i]) - len(m[oo][j]):
						dd = True
						m[oo].pop(j)
						break
				j += 1
			i += 1
		m[oo][1] = str(len(m[oo]) - 2)
print(len(m))
for i in m:
	print(' '.join(i))


n = int(input())
d = {}
for _ in range(n):
	a = input().split()
	if a[0] in d:
		for i in range(int(a[1])):
			d[a[0]].append(a[2 + i])
		continue
	d[a[0]] = []
	for i in range(int(a[1])):
		d[a[0]].append(a[2 + i])
print(len(d))
for i in d:
	for j in range(len(d[i])):
		for k in range(len(d[i])):
			if j != k and d[i][k].endswith(d[i][j]):
				d[i][j] = 'a'
	print(i, len([e for e in d[i] if e != 'a']), end=' ')
	for g in d[i]:
		if g != 'a':
			print(g, end=' ')
	print()


import sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
pn = defaultdict(list)

def is_suffix(name, number):
	for num in pn[name]:
		if num.endswith(number):
			return True
	return False

def clean(lst, number):
	i = 0
	while i < len(lst):
		if lst[i] != number and number.endswith(lst[i]):
			del lst[i]
		else:
			i += 1
for _ in range(n):
	(name, num_numbers, *nums) = input().rstrip().split()
	num_numbers = int(num_numbers)
	nums = list(nums)
	nums.sort(key=len, reverse=True)
	for number in nums:
		if not is_suffix(name, number):
			pn[name].append(number)
			clean(pn[name], number)
print(len(pn))
for (name, nums) in pn.items():
	print(name, len(nums), *nums)


import bisect

def list_output(s):
	print(' '.join(map(str, s)))

def list_input(s='int'):
	if s == 'int':
		return list(map(int, input().split()))
	elif s == 'float':
		return list(map(float, input().split()))
	return list(map(str, input().split()))
n = int(input())
d = dict()
for _ in range(n):
	seq = list(input().split())
	name = seq[0]
	k = int(seq[1])
	seq = seq[2:]
	if name not in d:
		d[name] = []
	d[name].extend(seq)
for key in d:
	seq = d[key]
	seq = list(set(seq))
	k = len(seq)
	valid = [True] * k
	for i in range(k):
		if not valid[i]:
			continue
		for j in range(k):
			if i == j or not valid[j]:
				continue
			if seq[i].endswith(seq[j]):
				valid[j] = False
			if seq[j].endswith(seq[i]):
				valid[i] = False
	vseq = list()
	for i in range(k):
		if valid[i]:
			vseq.append(seq[i])
	d[key] = vseq
print(len(d))
for key in d:
	seq = d[key]
	k = len(seq)
	seq = ' '.join(seq)
	print('{} {} {}'.format(key, k, seq))


import sys
import bisect
from collections import deque
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

def suffix(i, j):
	for k in range(len(j)):
		if i[-1 - k] != j[-1 - k]:
			return False
	return True
n = int(ri())
dic = {}
for i in range(n):
	temp = ri().split()
	arr = temp[2:]
	s = set()
	for i in arr:
		s.add(i)
	if temp[0] in dic:
		temps = dic[temp[0]]
		for i in s:
			temps.add(i)
	else:
		dic[temp[0]] = s
print(len(dic))
for k in dic:
	s = dic[k]
	q = []
	ans = []
	for j in s:
		q.append(j)
	q.sort(key=lambda x: -len(x))
	flag = [True] * len(q)
	for i in range(len(q)):
		for j in range(i + 1, len(q)):
			if suffix(q[i], q[j]):
				flag[j] = False
	for i in range(len(q)):
		if flag[i]:
			ans.append(q[i])
	print(k, end=' ')
	print(len(ans), end=' ')
	print(*ans)


n = int(input())
names = {}
for i in range(n):
	(name, cnt, *numbers) = input().split()
	if name not in names:
		existingNums = []
	else:
		existingNums = names[name]
	for newNum in numbers:
		for exNum in existingNums:
			if exNum.endswith(newNum):
				break
			if newNum.endswith(exNum):
				existingNums.remove(exNum)
		else:
			existingNums += [newNum]
	names[name] = existingNums
print(len(names))
for name in names:
	print(name, len(names[name]), end=' ')
	for num in names[name]:
		print(num, end=' ')
	print()


n = int(input())
d = {}
for i in range(n):
	l = list(map(str, input().split()))
	if l[0] not in d:
		d[l[0]] = list(set(l[2:]))
	else:
		d[l[0]] = list(set(list(list(set(l[2:])) + d[l[0]])))
for i in d:
	a = d[i]
	ans = []
	m = len(a)
	for j in range(m):
		c = 1
		for z in range(m):
			if j != z and a[z].endswith(a[j]):
				c = 0
		if c:
			ans.append(a[j])
	d[i] = ans
print(len(d))
for i in d:
	print(i, len(d[i]), *d[i])


k = int(input())
tmp_names_num = {}
names_num = {}
names_set = {}
for _ in range(k):
	(name, n, *nums) = input().split(' ')
	for _ in range(int(n)):
		if name not in names_num:
			tmp_names_num[name] = []
			names_num[name] = []
			names_set[name] = set()
		if type(nums) is list:
			for num in nums:
				tmp_names_num[name].append(num)
		else:
			tmp_names_num[name].append(num)
for name in tmp_names_num:
	tmp_names_num[name].sort(key=len, reverse=True)
	for num in tmp_names_num[name]:
		if num not in names_set[name]:
			for i in range(len(num)):
				names_set[name].add(num[i:])
			names_num[name].append(num)
print(len(names_num))
for name in names_num:
	print(name, end=' ')
	print(len(names_num[name]), end=' ')
	for num in names_num[name]:
		print(num, end=' ')
	print()


n = int(input())
ans = [[] for i in range(n)]
name = ['' for i in range(n)]
itog = [[''] for i in range(n)]
used = [[] for i in range(n)]
for i in range(n):
	a = input()
	j = 0
	now = ''
	while a[j] != ' ':
		now += a[j]
		j += 1
	place = 0
	for k in range(n):
		if name[k] == now or name[k] == '':
			name[k] = now
			place = k
			break
	now = ''
	j += 1
	kol = 0
	while j != len(a):
		if a[j] == ' ':
			if kol == 0:
				kol += 1
				now = ''
			else:
				kol += 1
				ans[place].append(now)
				now = ''
				used[place].append(0)
		else:
			now += a[j]
		j += 1
	ans[place].append(now)
	used[place].append(0)
	for k1 in range(len(ans[place])):
		for k2 in range(k1 + 1, len(ans[place])):
			bad = False
			for p in range(len(ans[place][k2])):
				if ans[place][k2][p:len(ans[place][k2])] == ans[place][k1]:
					bad = True
					used[place][k1] = 1
			if bad == False:
				for p in range(len(ans[place][k1])):
					if ans[place][k1][p:len(ans[place][k1])] == ans[place][k2]:
						bad = True
						used[place][k2] = 1
i = 0
k = 0
aaa = [0 for i in range(n)]
while name[i] != '':
	for p in range(len(ans[i])):
		if used[i][p] == 0:
			aaa[i] += 1
	k += 1
	i += 1
	if i == n:
		break
print(k)
i = 0
while name[i] != '':
	print(name[i], end=' ')
	print(aaa[i], end=' ')
	for k in range(len(ans[i])):
		if used[i][k] == 0:
			print(ans[i][k], end=' ')
	i += 1
	print()
	if i == n:
		break


n = int(input())
a = []
names = set()
numbers = [[] for i in range(21)]
for i in range(n):
	l = list(input().split())
	names.add(l[0])
	a.append(l)
names = list(names)
for (index, i) in enumerate(names):
	for j in a:
		if j[0] == i:
			for k in range(2, len(j)):
				numbers[index].append(j[k])
for (index, i) in enumerate(names):
	numbers[index] = list(set(numbers[index]))
	for a in range(len(numbers[index])):
		for b in range(len(numbers[index])):
			str_a = str(numbers[index][a])
			str_b = str(numbers[index][b])
			if str_a == str_b and a != b:
				numbers[index][a] = 'x'
			elif a != b and str_b[len(str_b) - len(str_a):len(str_b)] == str_a:
				numbers[index][a] = 'x'
print(len(names))
for (index, i) in enumerate(names):
	var = []
	for j in range(len(numbers[index])):
		if numbers[index][j] != 'x':
			var.append(str(numbers[index][j]))
	print(names[index], len(var), ' '.join(var))


n = int(input())
entries = {}
for i in range(n):
	line = input().split()
	name = line[0]
	phones = line[2:]
	if name not in entries:
		entries[name] = set(phones)
	else:
		entries[name].update(phones)
print(len(entries))
for ele in entries:
	list_phones = list(entries[ele])
	for i in range(len(list_phones) - 1):
		cur_i = list_phones[i]
		for j in range(i + 1, len(list_phones)):
			cur_j = list_phones[j]
			if cur_j.endswith(cur_i) and cur_i in entries[ele]:
				entries[ele].remove(cur_i)
			elif cur_i.endswith(cur_j) and cur_j in entries[ele]:
				entries[ele].remove(cur_j)
	print(ele, len(entries[ele]), ' '.join(entries[ele]))


n = int(input())
d = {}
for i in range(n):
	(a, *b) = input().split()
	d[a] = d.get(a, []) + b[1:]
print(len(d))
for x in d:
	L = list(set(d[x]))
	l = []
	for i in range(len(L)):
		flaf = True
		for j in range(len(L)):
			if i != j and L[j].endswith(L[i]):
				flaf = False
		if flaf:
			l.append(L[i])
	print(x + ' ' + str(len(l)) + ' ' + ' '.join(l))


phone_book = {}
friends = 0
n = int(input().strip())
for _ in range(n):
	record = input().strip().split()
	name = record[0]
	num = int(record[1])
	if name not in phone_book:
		phone_book[name] = []
		friends += 1
	for i in range(num):
		c = record[i + 2]
		flag = True
		if record[i + 2] in phone_book[name]:
			continue
		else:
			l1 = len(phone_book[name])
			for i in range(len(phone_book[name])):
				if i == l1:
					break
				contact = phone_book[name][i]
				if len(contact) > len(c):
					if contact[-1 * len(c):] == c:
						flag = False
				elif c[-1 * len(contact):] == contact:
					phone_book[name].remove(contact)
					l1 -= 1
					i -= 1
			if flag:
				phone_book[name].append(c)
print(friends)
for contact in phone_book:
	ans = ''
	ans += contact
	ans += ' ' + str(len(phone_book[contact]))
	for i in phone_book[contact]:
		ans += ' ' + i
	print(ans)


n = int(input())
annuaire = []
entree = []
for _ in range(n):
	s = [ch for ch in input().split()]
	entree.append(s)
	if not s[0] in annuaire:
		annuaire.append(s[0])
print(len(annuaire))
for i in range(len(annuaire)):
	num = []
	for j in range(n):
		if entree[j][0] == annuaire[i]:
			s = entree[j]
			num.extend([s[k] for k in range(2, len(s))])
	keep = [True] * len(num)
	for j in range(len(num)):
		lj = len(num[j])
		for k in range(len(num)):
			lk = len(num[k])
			if j != k and keep[k] and (lj <= lk) and (num[j] == num[k][lk - lj:lk]):
				keep[j] = False
				break
	numf = [num[j] for j in range(len(num)) if keep[j]]
	rep = annuaire[i] + ' ' + str(len(numf))
	for j in range(len(numf)):
		rep += ' ' + numf[j]
	print(rep)


def main():
	n = int(input())
	phone_book = {}
	for i in range(n):
		values = input().split()
		(name, k) = (values[0], values[1])
		name_phones = values[2:]
		if name not in phone_book:
			phone_book[name] = []
		phone_book[name].extend(name_phones)
	for (key, value) in phone_book.items():
		phone_book[key] = set(value)
	for (name, phones) in phone_book.items():
		phone_book[name] = [phone for phone in phones if not any((phone != another_phone and another_phone.endswith(phone) for another_phone in phones))]
	print(len(phone_book), *[' '.join(map(str, [name, len(phones), ' '.join(phones)])) for (name, phones) in phone_book.items()], sep='\n')
main()


n = int(input())
names = {}
for i in range(n):
	entry = input().split(' ')
	(name, k, numbers) = (entry[0], int(entry[1]), entry[2:])
	if not names.__contains__(name):
		names[name] = numbers
	else:
		names[name] += numbers
for name in names:
	lst = sorted(names[name], key=len)
	i = 0
	while i < len(lst):
		letter = lst[i]
		for j in range(i + 1, len(lst)):
			if lst[j].find(lst[i], len(lst[j]) - len(lst[i])) >= 0:
				lst.remove(lst[i])
				i -= 1
				break
		i += 1
	names[name] = lst
print(len(names))
for name in names:
	print('%s %d ' % (name, len(names[name])), end='')
	for ent in names[name]:
		print('%s ' % ent, end='')
	print()


from collections import defaultdict
d = defaultdict(list)
n = int(input())
for i in range(n):
	m = input().split()
	name = m[0]
	numbers = set(m[2:] + d[name])
	out = []
	for num in numbers:
		for num1 in numbers:
			if num != num1 and num1.endswith(num):
				out.append(num)
	numbers = list(set(numbers) - set(out))
	d[name] = numbers
print(len(d))
for i in d:
	print(i, len(d[i]), ' '.join(d[i]))


n = int(input().strip())
dct = dict()
for i in range(n):
	arr = list(input().strip().split())
	name = arr[0]
	arr = arr[2:]
	if name in dct:
		dct[name] = dct[name].union(set(arr))
	else:
		dct[name] = set(arr)
for name in dct.keys():
	tl = list(dct[name])
	tmp = [1 for _ in range(len(tl))]
	for i in range(len(tl)):
		for j in range(i + 1, len(tl)):
			if len(tl[i]) > len(tl[j]) and tl[i].endswith(tl[j]):
				tmp[j] = 0
			elif len(tl[i]) < len(tl[j]) and tl[j].endswith(tl[i]):
				tmp[i] = 0
	lst = []
	for i in range(len(tmp)):
		if tmp[i] == 1:
			lst.append(tl[i])
	dct[name] = lst
print(len(dct))
for name in dct.keys():
	s = name + ' ' + str(len(dct[name])) + ' '
	x = ' '.join(dct[name])
	print(s + x)


n = int(input())
dic = {}
for i in range(n):
	l = list(map(str, input().split()))
	s1 = l[0]
	if s1 in dic.keys():
		dic[l[0]] += list(set(l[2:]))
	else:
		dic[l[0]] = list(set(l[2:]))
print(len(dic.keys()))
for ix in dic.keys():
	l = dic[ix][:]
	ll = len(l)
	lln = [1 for i in range(ll)]
	for i in range(ll):
		for j in range(i + 1, ll):
			s1 = l[i]
			s2 = l[j]
			if len(s1) > len(s2):
				for k in range(len(s1)):
					if s2 == s1[k:]:
						lln[j] = 0
			else:
				for k in range(len(s2)):
					if s1 == s2[k:]:
						lln[i] = 0
	ls = []
	for i in range(ll):
		if lln[i] == 1:
			ls.append(l[i])
	print(ix, lln.count(1), *ls)


n = int(input())
d = {}
for i in range(n):
	s = [z for z in input().split()]
	name = s[0]
	count = int(s[1])
	for z in range(count):
		if name in d.keys():
			d[name].append(s[2 + z])
		else:
			d[name] = [s[2 + z]]
for k in d.keys():
	a = set(d[k])
	a = list(a)
	b = []
	for i in range(len(a)):
		f = False
		for j in range(len(a)):
			if i != j:
				if len(a[i]) <= len(a[j]):
					if a[j][len(a[j]) - len(a[i]):] == a[i]:
						f = True
						break
		if f == False:
			b.append(a[i])
	d[k] = b
print(len(d))
for k in d.keys():
	print(k, end=' ')
	print(len(d[k]), end=' ')
	print(' '.join(d[k]))


d = {}
n = int(input())
for _ in range(n):
	s = input().split()
	try:
		d[s[0]].extend(s[2:])
	except:
		d[s[0]] = s[2:]
print(len(d))
for key in d.keys():
	d[key] = list(set(d[key]))
	r = []
	for nos in d[key]:
		for oth_nos in d[key]:
			if nos == oth_nos:
				continue
			if oth_nos.endswith(nos):
				r.append(nos)
				break
	for ele in r:
		d[key].remove(ele)
	print(key, len(d[key]), *d[key])


import math
import sys
import getpass
import bisect

def ria():
	return [int(i) for i in input().split()]
files = True
if getpass.getuser().lower() == 'frohe' and files:
	sys.stdin = open('test.in')
n = ria()[0]
nm = {}
for i in range(n):
	ar = [i.strip() for i in input().split()]
	name = ar[0]
	if not name in nm:
		nm[name] = []
	for j in ar[2:]:
		nm[name].append(j)
for i in nm:
	nm[i] = sorted(nm[i], key=lambda x: len(x))
nmfin = {}
for i in nm:
	cur = nm[i]
	nmfin[i] = []
	for j in range(len(cur)):
		bad = False
		for j1 in range(j + 1, len(cur)):
			if cur[j1].endswith(cur[j]):
				bad = True
				break
		if not bad:
			nmfin[i].append(cur[j])
print(len(nmfin))
for i in nmfin:
	print(i, len(nmfin[i]), end=' ')
	for j in nmfin[i]:
		print(j, end=' ')
	print()


n = int(input())
t = {}
while n:
	n -= 1
	l = input().split()
	name = l[0]
	try:
		tmp = t[name]
	except KeyError:
		tmp = []
	l = list(set(l[2:] + tmp))
	l.sort(key=len, reverse=True)
	cur = [l[0]]
	for i in l[1:]:
		try:
			for j in cur:
				if j.endswith(i):
					3 / 0
			cur.append(i)
		except ZeroDivisionError:
			continue
	t[name] = cur
print(len(t.keys()))
for key in t.keys():
	print(key, len(t[key]), ' '.join([str(i) for i in t[key]]))


def fltr(tels):
	ts = list(tels)
	for (i, t) in enumerate(ts):
		l = len(t)
		for (i2, t2) in enumerate(ts):
			if i == i2:
				continue
			if t == t2 and i < i2:
				tels.remove(t)
				break
			if t != t2 and t2[-l:] == t:
				tels.remove(t)
				break
t = int(input())
names = {}
for _ in range(t):
	e = input().split()
	if not e[0] in names:
		names[e[0]] = []
	for tttt in e[2:]:
		names[e[0]].append(tttt)
for tels in names.values():
	fltr(tels)
print(len(names))
for (name, tels) in names.items():
	print(' '.join([name, str(len(tels)), ' '.join(tels)]))


n = int(input())
d = dict()
writes = dict()
scanf = dict()
for i in range(n):
	write = input().split()
	if write[0] not in scanf:
		scanf[write[0]] = []
	for i in write[2:]:
		scanf[write[0]].append(i)
for (name, write) in scanf.items():
	write.sort(reverse=True, key=lambda x: len(x))
	if name not in d:
		d[name] = set()
		writes[name] = []
	for num in write:
		if num not in d[name]:
			writes[name].append(num)
			for i in range(len(num)):
				d[name].add(num[i:])
writes = writes.items()
print(len(writes))
for i in writes:
	print(i[0], len(i[1]), *i[1])


def reverse_numbers(s: str) -> str:
	s = list(s)
	s.reverse()
	return ''.join(s)
cnt = int(input())
res = {}
for i in range(cnt):
	s = input().split(' ')
	(name, cnt) = (s[0], int(s[1]))
	numbers = s[2:]
	if name not in res:
		res[name] = [reverse_numbers(number) for number in numbers]
	else:
		res[name] += [reverse_numbers(number) for number in numbers]
for key in res.keys():
	res[key].sort()
	t = []
	for number in res[key]:
		if t == []:
			t.append(number)
		elif number.startswith(t[-1]):
			t[-1] = number
		else:
			t.append(number)
	res[key] = '{0} {1} {2}'.format(key, len(t), ' '.join([reverse_numbers(tt) for tt in t]))
print(len(res))
for key in res.keys():
	print(res[key])


n = int(input())
D = {}
for _ in range(n):
	(name, amount, *numbers) = input().split()
	if name in D:
		D[name] += numbers
	else:
		D[name] = numbers
for (name, numbers) in D.items():
	ns = sorted(numbers, key=len)[::-1]
	nn = [ns[0]]
	for i in range(1, len(ns)):
		if not any([j[-len(ns[i]):] == ns[i] for j in nn]):
			nn += [ns[i]]
	D[name] = nn
print(len(D))
for (name, numbers) in D.items():
	print(name, len(numbers), ' '.join(numbers))


def suf(a, b):
	(a, b) = (str(a), str(b))
	if a == '-1' or b == '-1':
		return False
	if len(a) > len(b):
		return False
	i = 1
	while i <= len(a):
		if a[len(a) - i] != b[len(b) - i]:
			return False
		i = i + 1
	return True
n = int(input())
book = {}
p = 0
while n > 0:
	txt = input().split()
	if txt[0] not in book.keys():
		book[txt[0]] = []
		p = p + 1
	aux = txt[2:]
	for i in aux:
		if i not in book[txt[0]]:
			book[txt[0]].append(i)
	n = n - 1
for i in book:
	k = 0
	j = 0
	while k < len(book[i]):
		j = 0
		while j < len(book[i]):
			if k != j and suf(book[i][k], book[i][j]):
				book[i][k] = -1
				break
			j = j + 1
		k = k + 1
print(p)
for i in book:
	print(i, end=' ')
	cont = 0
	ans = []
	for j in book[i]:
		if j != -1:
			cont = cont + 1
			ans.append(j)
	print(cont, end=' ')
	l = 0
	while l < len(ans) - 1:
		print(ans[l], end=' ')
		l = l + 1
	print(ans[l])


n = int(input())
book = dict()
for i in range(n):
	phones = []
	inp = [i for i in input().split()]
	name = inp[0]
	phones = [i for i in inp[2:]]
	for ph in phones:
		if not name in book:
			book[name] = [ph]
			continue
		f = True
		for j in range(len(book[name])):
			if len(book[name][j]) <= len(ph) and ph.rfind(book[name][j]) + len(book[name][j]) == len(ph):
				book[name][j] = ph
				break
			elif len(book[name][j]) >= len(ph) and book[name][j].rfind(ph) + len(ph) == len(book[name][j]):
				f = False
		else:
			if f:
				book[name].append(ph)
print(len(book))
for name in book:
	print(name, len(book[name]), end=' ')
	for ph in book[name]:
		print(ph + '', end=' ')
	print()


n = int(input())
book = {}
book_cool = {}
for i in range(n):
	li = list(input().split())
	if li[0] not in book:
		book[li[0]] = []
	for num in li[2:int(li[1]) + 2]:
		book[li[0]].append(num[::-1])
for name in book:
	t = book[name]
	t.sort()
	book_cool[name] = set()
	tt = book_cool[name]
	for i in range(1, len(t)):
		if t[i].startswith(t[i - 1]):
			pass
		else:
			tt.add(t[i - 1])
	tt.add(t[-1])
print(len(book_cool))
for i in book_cool:
	print(i, len(book_cool[i]), end=' ')
	for j in book_cool[i]:
		print(j[::-1], end=' ')
	print()


n = int(input())
tel = []
for i in range(n):
	s = input()
	s = s.split()
	r = []
	r.append(s[0])
	r.append(s[1])
	z = []
	for x in range(int(s[1])):
		z.append(s[x + 2])
	r.append(z)
	tel.append(r)
book = []
name = []
for t in tel:
	if t[0] not in name:
		name.append(t[0])
for b in range(len(name)):
	x = []
	x.append(name[b])
	w = []
	for e in tel:
		if name[b] == e[0]:
			for i in e[2]:
				w.append(i)
	x.append(w)
	book.append(x)

def check(sp, data):
	for c in data:
		for i in range(len(c)):
			if sp == c[len(c) - i:len(c)]:
				return False
	return True
result = []
for b in book:
	rt = []
	rt.append(b[0])
	x = []
	for c in b[1]:
		if c not in x and check(c, b[1]):
			x.append(c)
	rt.append(x)
	result.append(rt)
print(len(result))
for x in result:
	s = ''
	for i in x[1]:
		s += i + ' '
	print(str(x[0]) + ' ' + str(len(x[1])) + ' ' + s)


from collections import defaultdict
n = int(input())
book = defaultdict(lambda : [])
for i in range(n):
	s = input().split()
	k = s[1]
	for j in s[2:]:
		book[s[0]].append(j)
final = defaultdict(lambda : [])
for entry in book:
	book[entry] = list(set(book[entry]))
	for i in book[entry]:
		flag = 0
		for j in book[entry]:
			if i == j:
				continue
			if j.endswith(i):
				flag = 1
		if not flag:
			final[entry].append(i)
print(len(final))
for entry in final:
	print(entry, len(final[entry]), ' '.join(final[entry]))


def stringmod(s):
	l = s[s.find(' ', s.find(' ') + 1) + 1:].split(' ')
	w = l[:]
	q = len(l)
	i = len(l) - 2
	while i > -1:
		j = i + 1
		while j < len(l):
			if l[j][::-1].find(l[i][::-1]) == 0:
				q -= 1
				l.pop(i)
				break
			elif l[i][::-1].find(l[j][::-1]) == 0:
				q -= 1
				l.pop(j)
				j -= 1
			j += 1
		i -= 1
	return l
n = int(input())
g = []
for t in range(n):
	s = input()
	k = stringmod(s)
	c = s[:s.find(' ')] + ' ' + str(len(k))
	for u in k:
		c = c + ' ' + str(u)
	for f in range(len(g)):
		if g[f][:g[f].find(' ')] == s[:s.find(' ')]:
			c += ' ' + g[f][g[f].find(' ', g[f].find(' ') + 1) + 1:]
			g.pop(f)
			break
	k = stringmod(c)
	c = c[:c.find(' ')] + ' ' + str(len(k))
	for u in k:
		c = c + ' ' + str(u)
	g.append(c)
print(len(g))
for t in g:
	print(t)


def suff(a, b):
	if b[len(b) - len(a):] == a:
		return True
	return False
n = int(input())
a = {}
for i in range(n):
	tmp = input().split()
	s = [_ for _ in tmp[2:]]
	if tmp[0] not in a:
		a[tmp[0]] = set(s)
	else:
		for _ in s:
			a[tmp[0]].add(_)
for _ in a.keys():
	tmp = []
	a[_] = list(a[_])
	for i in range(len(a[_])):
		for j in range(i + 1, len(a[_])):
			if suff(a[_][i], a[_][j]):
				tmp.append(a[_][i])
			if suff(a[_][j], a[_][i]):
				tmp.append(a[_][j])
	tmp = list(set(tmp))
	for i in tmp:
		a[_].remove(i)
print(len(a))
for i in a.keys():
	print(i, len(a[i]), ' '.join([str(_) for _ in a[i]]))


n = int(input())
d = dict()
for i in range(n):
	items = input().split()
	name = items[0]
	del items[0]
	del items[0]
	if name in d:
		d[name] += items
	else:
		d[name] = items
print(len(d))
for name in d:
	nums = d[name]
	nums = sorted(nums, key=lambda x: len(x))
	i = 0
	while i < len(nums):
		j = i + 1
		while j < len(nums):
			if nums[j].endswith(nums[i]):
				del nums[i]
				i -= 1
				break
			j += 1
		i += 1
	print(name, len(nums), ' '.join(nums))