x = input().split()
N = int(x[0])
I = list(map(str,x[1:]))
y = input().split()
M = int(y[0])
r = list(map(int,y[1:])) # 规则排序
r.sort()
# 规则简化
R = []
for i in r:
R0 = str(i)
if R0 in R:
continue
else:
R.append(R0)
# 输出定义
ptstr = []
for i in R:
a = []
b = []
for j in range(len(I)):
if i in I[j]:
a.append(j)
b.append(I[j])
if len(a) == 0:
continue
ptstr.append(i)
ptstr.append(len(a))
for i in range(len(a)):
ptstr.append(a[i])
ptstr.append(b[i])
Ptstr = str(len(ptstr))
for i in ptstr:
Ptstr += ' ' + str(i)
print(Ptstr)