n=int(eval(input()))

a=[]

for i in range(n):

  m=int(eval(input()))

  a.append([])

  for i in range(m):

    a[-1].append(list(map(int,input().split())))

ans=0

for i in range(2**n):

  s=bin(i)[2:].zfill(n)

  f=True

  for j,k in enumerate(a):

    for x,y in k:

      if s[x-1]!=str(y) and s[j]=="1":f=False

  if f:ans=max(ans,s.count("1"))

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

xy=[[]for _ in range(n)]

for i in range(n):

  for j in range(int(eval(input()))):

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

ans=0

for i in range(1,1<<n):

  syojiki=[(i&(1<<j)!=0)+0 for j in range(n)]

  flag=True

  for j in range(n):

    for x,y in xy[j]:

      if syojiki[x-1]!=y and syojiki[j]==1:flag=False

  if flag:

    ans=max(ans,syojiki.count(1))

print(ans)
n = int(eval(input()))
a = []
for i in range(n):
    m = int(eval(input()))
    a.append([])
    for i in range(m):
        a[-1].append(list(map(int, input().split())))
ans = 0
for i in range(2**n):
    s = bin(i)[2:].zfill(n)
    f = True
    for j, k in enumerate(a):
        for x, y in k:
            if s[x - 1] != str(y) and s[j] == "1":
                f = False
    if f:
        ans = max(ans, s.count("1"))
print(ans)

n = int(eval(input()))
xy = [[] for _ in range(n)]
for i in range(n):
    for j in range(int(eval(input()))):
        xy[i].append(list(map(int, input().split())))
ans = 0
for i in range(1, 1 << n):
    syojiki = [(i & (1 << j) != 0) + 0 for j in range(n)]
    flag = True
    for j in range(n):
        for x, y in xy[j]:
            if syojiki[x - 1] != y and syojiki[j] == 1:
                flag = False
    if flag:
        ans = max(ans, syojiki.count(1))
print(ans)

-a = [] +xy = [[] for _ in range(n)] -    m = int(eval(input())) -    a.append([]) -    for i in range(m): -        a[-1].append(list(map(int, input().split()))) +    for j in range(int(eval(input()))): +        xy[i].append(list(map(int, input().split()))) -for i in range(2**n): -    s = bin(i)[2:].zfill(n) -    f = True -    for j, k in enumerate(a): -        for x, y in k: -            if s[x - 1] != str(y) and s[j] == "1": -                f = False -    if f: -        ans = max(ans, s.count("1")) +for i in range(1, 1 << n): +    syojiki = [(i & (1 << j) != 0) + 0 for j in range(n)] +    flag = True +    for j in range(n): +        for x, y in xy[j]: +            if syojiki[x - 1] != y and syojiki[j] == 1: +                flag = False +    if flag: +        ans = max(ans, syojiki.count(1))