n = int(eval(input()))

ip = []



for i in range(n):

  a = int(eval(input()))

  ip.append(a)

  for j in range(a):

    x,y = list(map(int,input().split()))

    ip.append([x,y])



max = 0    

for i in range(n) :

  max += 2**i



ans = 0

for i in range(0,max+1) :

  s = [2 for _ in range(n)]

  bit = i

  count = 0

  index = 0

  check = 0

  for j in range(n) :

    if bit%2 == 1 :

      if s[j] == 0 :

        check = 1

        break

      s[j] = 1

    else :

      if s[j] == 1 :

        check = 1

        break

      s[j] = 0

    bit = bit//2

    for k in range(ip[index]) :

      if s[j] == 1 :

        if ip[index+1+k][1] == 1 :

          if s[ip[index+1+k][0]-1] == 0 :

            check = 1

            break

          s[ip[index+1+k][0]-1] = 1

        elif ip[index+1+k][1] == 0 :

          if s[ip[index+1+k][0]-1] == 1 :

            check = 1

            break

          s[ip[index+1+k][0]-1] = 0

    if check == 1 :

      break

    index += ip[index] + 1

  if ans < s.count(1) and check ==0 :

    ans = s.count(1)



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

ip = []



for i in range(n):

  a = int(eval(input()))

  ip.append(a)

  for j in range(a):

    x,y = list(map(int,input().split()))

    ip.append([x,y])



max = 0    

for i in range(n) :

  max += 2**i



ans = 0

for i in range(0,max+1) :

  s = [2 for _ in range(n)]

  bit = i

  count = 0

  index = 0

  check = 0

  for j in range(n) :

    if bit%2 == 1 :

      if s[j] == 0 :

        check = 1

      s[j] = 1

    else :

      if s[j] == 1 :

        check = 1

      s[j] = 0

    bit = bit//2

    for k in range(ip[index]) :

      if s[j] == 1 :

        if ip[index+1+k][1] == 1 :

          if s[ip[index+1+k][0]-1] == 0 :

            check = 1

          s[ip[index+1+k][0]-1] = 1

        elif ip[index+1+k][1] == 0 :

          if s[ip[index+1+k][0]-1] == 1 :

            check = 1

          s[ip[index+1+k][0]-1] = 0

    index += ip[index] + 1

  if ans < s.count(1) and check ==0 :

    ans = s.count(1)



print(ans)
n = int(eval(input()))
ip = []
for i in range(n):
    a = int(eval(input()))
    ip.append(a)
    for j in range(a):
        x, y = list(map(int, input().split()))
        ip.append([x, y])
max = 0
for i in range(n):
    max += 2**i
ans = 0
for i in range(0, max + 1):
    s = [2 for _ in range(n)]
    bit = i
    count = 0
    index = 0
    check = 0
    for j in range(n):
        if bit % 2 == 1:
            if s[j] == 0:
                check = 1
                break
            s[j] = 1
        else:
            if s[j] == 1:
                check = 1
                break
            s[j] = 0
        bit = bit // 2
        for k in range(ip[index]):
            if s[j] == 1:
                if ip[index + 1 + k][1] == 1:
                    if s[ip[index + 1 + k][0] - 1] == 0:
                        check = 1
                        break
                    s[ip[index + 1 + k][0] - 1] = 1
                elif ip[index + 1 + k][1] == 0:
                    if s[ip[index + 1 + k][0] - 1] == 1:
                        check = 1
                        break
                    s[ip[index + 1 + k][0] - 1] = 0
        if check == 1:
            break
        index += ip[index] + 1
    if ans < s.count(1) and check == 0:
        ans = s.count(1)
print(ans)

n = int(eval(input()))
ip = []
for i in range(n):
    a = int(eval(input()))
    ip.append(a)
    for j in range(a):
        x, y = list(map(int, input().split()))
        ip.append([x, y])
max = 0
for i in range(n):
    max += 2**i
ans = 0
for i in range(0, max + 1):
    s = [2 for _ in range(n)]
    bit = i
    count = 0
    index = 0
    check = 0
    for j in range(n):
        if bit % 2 == 1:
            if s[j] == 0:
                check = 1
            s[j] = 1
        else:
            if s[j] == 1:
                check = 1
            s[j] = 0
        bit = bit // 2
        for k in range(ip[index]):
            if s[j] == 1:
                if ip[index + 1 + k][1] == 1:
                    if s[ip[index + 1 + k][0] - 1] == 0:
                        check = 1
                    s[ip[index + 1 + k][0] - 1] = 1
                elif ip[index + 1 + k][1] == 0:
                    if s[ip[index + 1 + k][0] - 1] == 1:
                        check = 1
                    s[ip[index + 1 + k][0] - 1] = 0
        index += ip[index] + 1
    if ans < s.count(1) and check == 0:
        ans = s.count(1)
print(ans)

-                break -                break -                        break -                        break -        if check == 1: -            break