'''第一遍做时候是这么想的,再看感觉有很多能简化的部分,懒得再改了'''
while 1:
try:
lst_a=input().split()[1:]
lst_b=set(input().split()[1:])
lst_b=sorted(list(map(int, lst_b)))
lst_b=list(map(str,lst_b))
# 原来直接排序用例不通过,因为str排序和int排序规则不一样
lst_c=[]
for i in lst_b:
lst=[0,0] # [元素,个数]
for j,v in enumerate(lst_a):
if i in v:
lst[0]=i
lst[1]+=1
lst.append((j,v))
# 用元组形式添加,方便后续排序
if len(lst)!=2:
lst[2:]=sorted(lst[2:],key=lambda x:x[0])
# 按索引排序
lst_c.append(lst[0]) # 大表中放入
lst_c.append(lst[1])
for t in lst[2:]:
lst_c.append(t[0])
lst_c.append(t[1])
print(len(lst_c),end=' ')
print(' '.join(list(map(str,lst_c))))
except:
break