import collections;

dic = collections.OrderedDict()
for i in range(int(input())):
    txt=input()
    if txt in dic: dic[txt]+=1
    else: dic[txt]=1
print(len(dic));

for k,v in dic.items():
    print(v,end=" ")
f302e2bc0fade22feb42e70367983747f740df60
<mask token>

<mask token>
for i in range(int(input())):
    txt = input()
    if txt in dic:
        dic[txt] += 1
    else:
        dic[txt] = 1
print(len(dic))
for k, v in dic.items():
    print(v, end=' ')

<mask token>
dic = collections.OrderedDict()
for i in range(int(input())):
    txt = input()
    if txt in dic:
        dic[txt] += 1
    else:
        dic[txt] = 1
print(len(dic))
for k, v in dic.items():
    print(v, end=' ')

import collections
dic = collections.OrderedDict()
for i in range(int(input())):
    txt = input()
    if txt in dic:
        dic[txt] += 1
    else:
        dic[txt] = 1
print(len(dic))
for k, v in dic.items():
    print(v, end=' ')

import collections;

dic = collections.OrderedDict()
for i in range(int(input())):
    txt=input()
    if txt in dic: dic[txt]+=1
    else: dic[txt]=1
print(len(dic));

for k,v in dic.items():
    print(v,end=" ")