N,M = [int(i) for i in input().split()] #Nがスイッチの数、Mは電球の数

sss = []

for i in range(M):

    buff = [int(i)-1 for i in input().split()][1:]

    onoff = [0 for i in range(N)]

    for j in buff:

        onoff[j]=1

    sss.append(onoff)



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



ct=0

for i in range(1<<N):

    bitcode = [int(i) for i in list(bin(i)[2:].zfill(N))]

    for s,p in zip(sss,ppp):

        if sum(j*k for j,k in zip(s,bitcode))%2!=p:

            break

    else:

        ct+=1



print(ct)
N,M = [int(i) for i in input().split()]

switches = []

for i in range(M):

    buff = 0

    k,*sss = [int(i) for i in input().split()]

    for s in sss:

        buff += 1 << (s-1)

    switches.append(buff)



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

ans = 0

for i in range(1<<N):

    for p,s in zip(ppp,switches):

        buff = s&i

        buff = bin(buff).count("1")%2

        if buff != p:

            break

    else:

        ans += 1



print(ans)
N, M = [int(i) for i in input().split()]  # Nがスイッチの数、Mは電球の数
sss = []
for i in range(M):
    buff = [int(i) - 1 for i in input().split()][1:]
    onoff = [0 for i in range(N)]
    for j in buff:
        onoff[j] = 1
    sss.append(onoff)
ppp = [int(i) for i in input().split()]
ct = 0
for i in range(1 << N):
    bitcode = [int(i) for i in list(bin(i)[2:].zfill(N))]
    for s, p in zip(sss, ppp):
        if sum(j * k for j, k in zip(s, bitcode)) % 2 != p:
            break
    else:
        ct += 1
print(ct)

N, M = [int(i) for i in input().split()]
switches = []
for i in range(M):
    buff = 0
    k, *sss = [int(i) for i in input().split()]
    for s in sss:
        buff += 1 << (s - 1)
    switches.append(buff)
ppp = [int(i) for i in input().split()]
ans = 0
for i in range(1 << N):
    for p, s in zip(ppp, switches):
        buff = s & i
        buff = bin(buff).count("1") % 2
        if buff != p:
            break
    else:
        ans += 1
print(ans)

-N, M = [int(i) for i in input().split()]  # Nがスイッチの数、Mは電球の数 -sss = [] +N, M = [int(i) for i in input().split()] +switches = [] -    buff = [int(i) - 1 for i in input().split()][1:] -    onoff = [0 for i in range(N)] -    for j in buff: -        onoff[j] = 1 -    sss.append(onoff) +    buff = 0 +    k, *sss = [int(i) for i in input().split()] +    for s in sss: +        buff += 1 << (s - 1) +    switches.append(buff) -ct = 0 +ans = 0 -    bitcode = [int(i) for i in list(bin(i)[2:].zfill(N))] -    for s, p in zip(sss, ppp): -        if sum(j * k for j, k in zip(s, bitcode)) % 2 != p: +    for p, s in zip(ppp, switches): +        buff = s & i +        buff = bin(buff).count("1") % 2 +        if buff != p: -        ct += 1 -print(ct) +        ans += 1 +print(ans)