```while True:
    try:
        lst = input().split()
        lst_str = lst[1:]
        num = input().split()
        num_str = num[1:]
        num_str = sorted(list(map(int, set(num_str))))
        res = {}
        for x in num_str:
            count = 0
            tmp_lst = []
            for i in range(len(lst_str)):
                if str(x) in lst_str[i]:
                    count += 1
                    tmp_lst.append(i)
                    tmp_lst.append(lst_str[i])
                else:
                    continue
            if count !=0:
                res[x] = {count: tmp_lst}
        out = []
        for x in res:
            out.append(x)
            for i in res[x]:
                out.append(i)
                for j in res[x][i]:
                    out.append(j)
        print(len(out),' '.join([str(x) for x in out]))         


    except:
        break