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

s = []

for _ in range(m):

    tmp = list(map(int, input().split()))

    s.append(tmp[1:])

p = list(map(int, input().split()))



ans = 0

for bit in range(0, 1 << n):

    flag = 1

    for i in range(m):

        on_count = 0

        for switch in s[i]:

            if bit & (1 << (switch-1)):

                on_count += 1

        if (on_count % 2) != p[i]:

            flag = 0

    if flag == 1:

        ans += 1

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

s = [list(map(int, input().split()))[1:] for _ in range(m)]

p = list(map(int, input().split()))

ans = 0

for bit in range(1 << n):

    flag = 1

    for i in range(m):

        on_count = 0

        for switch in s[i]:

            if bit & (1 << (switch-1)):

                on_count += 1

        if (on_count % 2) != p[i]:

            flag = 0

            break

    ans += flag

print(ans)
n, m = list(map(int, input().split()))
s = []
for _ in range(m):
    tmp = list(map(int, input().split()))
    s.append(tmp[1:])
p = list(map(int, input().split()))
ans = 0
for bit in range(0, 1 << n):
    flag = 1
    for i in range(m):
        on_count = 0
        for switch in s[i]:
            if bit & (1 << (switch - 1)):
                on_count += 1
        if (on_count % 2) != p[i]:
            flag = 0
    if flag == 1:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
s = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for bit in range(1 << n):
    flag = 1
    for i in range(m):
        on_count = 0
        for switch in s[i]:
            if bit & (1 << (switch - 1)):
                on_count += 1
        if (on_count % 2) != p[i]:
            flag = 0
            break
    ans += flag
print(ans)

-s = [] -for _ in range(m): -    tmp = list(map(int, input().split())) -    s.append(tmp[1:]) +s = [list(map(int, input().split()))[1:] for _ in range(m)] -for bit in range(0, 1 << n): +for bit in range(1 << n): -    if flag == 1: -        ans += 1 +            break +    ans += flag