N = int(eval(input()))

A = [0] * N

X = [[] for _ in range(N)]

for i in range(N):

  A[i] = int(eval(input()))

  for j in range(A[i]):

    X[i].append(list(map(int, input().split())))

Truth = 2 ** N

ans = 0

while(bin(Truth) != bin(2 ** (N + 1))):

  for i in range(N):

    if(bin(Truth)[i+3] == "1"):

      for j in range(A[i]):

        if(int(bin(Truth)[X[i][j][0] + 2]) != X[i][j][1]):

          break

      else:

        continue

      Truth += 1

      break

  else:

    ans = sum(list(map(int,list(bin(Truth)[3:]))))

    Truth += 1

print(ans)
N = int(eval(input()))

x = [[0] * (N-1) for _ in range(N)]

y = [[0] * (N-1) for _ in range(N)]

A = [0] * N

for i in range(N):

  A[i] = int(eval(input()))

  for j in range(A[i]):

    x[i][j], y[i][j] = list(map(int, input().split()))

n = 2 ** N

Flag = 0

ans = 0

while(n < 2 ** (N+1)):

  Flag = 0

  for i in range(N):

    if(int(bin(n)[i + 3]) == 1):

      for j in range(A[i]):

        if(y[i][j] != int(bin(n)[x[i][j] + 2])):

          Flag = 1

          break

    if(Flag == 1):

      break

  else:

    ans = max(ans, sum(list(map(int,bin(n)[3:]))))

  n += 1

print(ans)
N = int(eval(input()))
A = [0] * N
X = [[] for _ in range(N)]
for i in range(N):
    A[i] = int(eval(input()))
    for j in range(A[i]):
        X[i].append(list(map(int, input().split())))
Truth = 2**N
ans = 0
while bin(Truth) != bin(2 ** (N + 1)):
    for i in range(N):
        if bin(Truth)[i + 3] == "1":
            for j in range(A[i]):
                if int(bin(Truth)[X[i][j][0] + 2]) != X[i][j][1]:
                    break
            else:
                continue
            Truth += 1
            break
    else:
        ans = sum(list(map(int, list(bin(Truth)[3:]))))
        Truth += 1
print(ans)

N = int(eval(input()))
x = [[0] * (N - 1) for _ in range(N)]
y = [[0] * (N - 1) for _ in range(N)]
A = [0] * N
for i in range(N):
    A[i] = int(eval(input()))
    for j in range(A[i]):
        x[i][j], y[i][j] = list(map(int, input().split()))
n = 2**N
Flag = 0
ans = 0
while n < 2 ** (N + 1):
    Flag = 0
    for i in range(N):
        if int(bin(n)[i + 3]) == 1:
            for j in range(A[i]):
                if y[i][j] != int(bin(n)[x[i][j] + 2]):
                    Flag = 1
                    break
        if Flag == 1:
            break
    else:
        ans = max(ans, sum(list(map(int, bin(n)[3:]))))
    n += 1
print(ans)

+x = [[0] * (N - 1) for _ in range(N)] +y = [[0] * (N - 1) for _ in range(N)] -X = [[] for _ in range(N)] -        X[i].append(list(map(int, input().split()))) -Truth = 2**N +        x[i][j], y[i][j] = list(map(int, input().split())) +n = 2**N +Flag = 0 -while bin(Truth) != bin(2 ** (N + 1)): +while n < 2 ** (N + 1): +    Flag = 0 -        if bin(Truth)[i + 3] == "1": +        if int(bin(n)[i + 3]) == 1: -                if int(bin(Truth)[X[i][j][0] + 2]) != X[i][j][1]: +                if y[i][j] != int(bin(n)[x[i][j] + 2]): +                    Flag = 1 -            else: -                continue -            Truth += 1 +        if Flag == 1: -        ans = sum(list(map(int, list(bin(Truth)[3:])))) -        Truth += 1 +        ans = max(ans, sum(list(map(int, bin(n)[3:])))) +    n += 1