n, m = list(map(int, input().split()))

denq = []

for _ in range(m):

    ks = tuple([int(x)-1 for x in input().split()])

    denq.append(ks[1:])

P = tuple(map(int, input().split()))



ans = 0

for i in range(2**n):

    # switch_states = [(i>>j)&1 for j in range(n)]

    for idq, dq in enumerate(denq):

        counts = 0

        for s in dq:

            counts += (i>>s)&1

        if counts%2 != P[idq]:

            break

    else:

        ans += 1

print(ans)
n, m = list(map(int, input().split()))

denq = []

for _ in range(m):

    ks = tuple([int(x)-1 for x in input().split()])

    denq.append(ks[1:])

P = tuple(map(int, input().split()))



ans = 0

for i in range(2**n):

    switch_states = [(i>>j)&1 for j in range(n)]

    for idq, dq in enumerate(denq):

        counts = 0

        for s in dq:

            counts += switch_states[s]

        if counts%2 != P[idq]:

            break

    else:

        ans += 1

print(ans)

n, m = list(map(int, input().split()))
denq = []
for _ in range(m):
    ks = tuple([int(x) - 1 for x in input().split()])
    denq.append(ks[1:])
P = tuple(map(int, input().split()))
ans = 0
for i in range(2**n):
    # switch_states = [(i>>j)&1 for j in range(n)]
    for idq, dq in enumerate(denq):
        counts = 0
        for s in dq:
            counts += (i >> s) & 1
        if counts % 2 != P[idq]:
            break
    else:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
denq = []
for _ in range(m):
    ks = tuple([int(x) - 1 for x in input().split()])
    denq.append(ks[1:])
P = tuple(map(int, input().split()))
ans = 0
for i in range(2**n):
    switch_states = [(i >> j) & 1 for j in range(n)]
    for idq, dq in enumerate(denq):
        counts = 0
        for s in dq:
            counts += switch_states[s]
        if counts % 2 != P[idq]:
            break
    else:
        ans += 1
print(ans)

-    # switch_states = [(i>>j)&1 for j in range(n)] +    switch_states = [(i >> j) & 1 for j in range(n)] -            counts += (i >> s) & 1 +            counts += switch_states[s]