n = int(eval(input()))

x = []

for i in range(n):

    ai = int(eval(input()))

    xi = []

    for j in range(ai):

        xi.append(list(map(int, input().split())))

    x.append(xi)



m = 0

for h in range(2**n - 1, -1, -1):

    is_break = False

    h = bin(h)[2:].zfill(n)

    for i, xi in enumerate(x):

        if h[i] == '0':

            continue

        for xij, yij in xi:

            if (int(h[xij - 1]) != yij):

                is_break = True

                break

        if is_break:

            break

    else:

        m = max(sum(map(int, list(h))), m)



print(m)
n = int(eval(input()))

v = []

for i in range(n):

    ai = int(eval(input()))

    vi = []

    for j in range(ai):

        vi.append(list(map(int, input().split())))

    v.append(vi)



m = 0

for bit in range(2**n - 1, -1, -1):

    is_break = False

    for i in range(n):

        if not (bit & (1 << i)):

            continue

        for xij, yij in v[i]:

            if not (not (bit & (1 << xij - 1))) != yij:

                is_break = True

                break

        if is_break:

            break

    else:

        m = max(bin(bit).count('1'), m)



print(m)
n = int(eval(input()))
x = []
for i in range(n):
    ai = int(eval(input()))
    xi = []
    for j in range(ai):
        xi.append(list(map(int, input().split())))
    x.append(xi)
m = 0
for h in range(2**n - 1, -1, -1):
    is_break = False
    h = bin(h)[2:].zfill(n)
    for i, xi in enumerate(x):
        if h[i] == "0":
            continue
        for xij, yij in xi:
            if int(h[xij - 1]) != yij:
                is_break = True
                break
        if is_break:
            break
    else:
        m = max(sum(map(int, list(h))), m)
print(m)

n = int(eval(input()))
v = []
for i in range(n):
    ai = int(eval(input()))
    vi = []
    for j in range(ai):
        vi.append(list(map(int, input().split())))
    v.append(vi)
m = 0
for bit in range(2**n - 1, -1, -1):
    is_break = False
    for i in range(n):
        if not (bit & (1 << i)):
            continue
        for xij, yij in v[i]:
            if not (not (bit & (1 << xij - 1))) != yij:
                is_break = True
                break
        if is_break:
            break
    else:
        m = max(bin(bit).count("1"), m)
print(m)

-x = [] +v = [] -    xi = [] +    vi = [] -        xi.append(list(map(int, input().split()))) -    x.append(xi) +        vi.append(list(map(int, input().split()))) +    v.append(vi) -for h in range(2**n - 1, -1, -1): +for bit in range(2**n - 1, -1, -1): -    h = bin(h)[2:].zfill(n) -    for i, xi in enumerate(x): -        if h[i] == "0": +    for i in range(n): +        if not (bit & (1 << i)): -        for xij, yij in xi: -            if int(h[xij - 1]) != yij: +        for xij, yij in v[i]: +            if not (not (bit & (1 << xij - 1))) != yij: -        m = max(sum(map(int, list(h))), m) +        m = max(bin(bit).count("1"), m)