n=int(eval(input()))

a=[[list(map(int,input().split()))for _ in'_'*int(eval(input()))]for _ in'_'*n]

m=0

for i in range(2**n):

  *s,=list(map(int,bin(i)[2:].zfill(n)))

  f=1

  for j,t in enumerate(a):

    if s[~j]:

      for x,y in t:f&=s[-x]==y

  m=max(m,sum(s)*f)

print(m)
i=input

n=int(i())

a=eval('[list(map(int,i().split()))for _ in"_"*int(i())],'*n)

print((max(all(y==i>>x-1&1for j,t in enumerate(a)if i>>j&1for x,y in t)*bin(i).count('1')for i in range(2**n))))
n = int(eval(input()))
a = [
    [list(map(int, input().split())) for _ in "_" * int(eval(input()))] for _ in "_" * n
]
m = 0
for i in range(2**n):
    (*s,) = list(map(int, bin(i)[2:].zfill(n)))
    f = 1
    for j, t in enumerate(a):
        if s[~j]:
            for x, y in t:
                f &= s[-x] == y
    m = max(m, sum(s) * f)
print(m)

i = input
n = int(i())
a = eval('[list(map(int,i().split()))for _ in"_"*int(i())],' * n)
print(
    (
        max(
            all(
                y == i >> x - 1 & 1 for j, t in enumerate(a) if i >> j & 1 for x, y in t
            )
            * bin(i).count("1")
            for i in range(2**n)
        )
    )
)

-n = int(eval(input())) -a = [ -    [list(map(int, input().split())) for _ in "_" * int(eval(input()))] for _ in "_" * n -] -m = 0 -for i in range(2**n): -    (*s,) = list(map(int, bin(i)[2:].zfill(n))) -    f = 1 -    for j, t in enumerate(a): -        if s[~j]: -            for x, y in t: -                f &= s[-x] == y -    m = max(m, sum(s) * f) -print(m) +i = input +n = int(i()) +a = eval('[list(map(int,i().split()))for _ in"_"*int(i())],' * n) +print( +    ( +        max( +            all( +                y == i >> x - 1 & 1 for j, t in enumerate(a) if i >> j & 1 for x, y in t +            ) +            * bin(i).count("1") +            for i in range(2**n) +        ) +    ) +)