#供養提出
n,m=map(int,input().split())
tmp=[]
k=[]
s=[]
p=[]
S=[]
Ev=0
Od=0
cnt=0
for i in range(m):
    tmp=input().split()
    tmp=[int(k) for k in tmp]
    k.append(tmp[0])
    for j in range(len(tmp)-1):
        s.append(tmp[j+1])
    S.append(s)
    s=[]

p=input().split()
p=[int(i) for i in p]


for i in range(m):
    for j in range(k[i]):
        if S[i][j]%2==0:
            Ev+=1
        else:
            Od+=1
    if p[i]==0:
        cnt+=2**Ev+2**(Od-1)+Ev*Od
    else:
        cnt+=2**Od+Ev*Od
        if Od==0: cnt-=2
    Ev=0
    Od=0
        
print(cnt)
print(k)
print(S)
print(p)