n = int(eval(input()))

lst = [(bin(i)[2:]).zfill(n) for i in range(2**n)]

num_list = []

A_list = []

xy_list = []

for i in range(n):

    a = int(eval(input()))

    A_list.append(a)

    for j in range(a):

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

        xy_list.append([x,y])

for i in range(len(lst)):

    choose = lst[i]

    one_count = choose.count("1")

    a_count = 0

    flag = True

    for num, j in enumerate(A_list):

        a_count += j

        for k in range(a_count-j, a_count):

            x,y = xy_list[k][0],xy_list[k][1]

            if choose[num] == "1" and choose[x-1] != str(y):

                flag = False

                break

    if flag:

        num_list.append(one_count)

    else:

        num_list.append(0)

print((max(num_list)))

n = int(eval(input()))

lst = [(bin(i)[2:]).zfill(n) for i in range(2**n)]

ans = 0

A_list = []

xy_list = []

for i in range(n):

    a = int(eval(input()))

    A_list.append(a)

    for j in range(a):

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

        xy_list.append([x,y])

for i in range(len(lst)):

    choose = lst[i]

    one_count = choose.count("1")

    a_count = 0

    flag = True

    for num, j in enumerate(A_list):

        a_count += j

        for k in range(a_count-j, a_count):

            x,y = xy_list[k][0],xy_list[k][1]

            if choose[num] == "1" and choose[x-1] != str(y):

                flag = False

                break

    if flag:

        ans = max(ans,one_count)

print(ans)

n = int(eval(input()))
lst = [(bin(i)[2:]).zfill(n) for i in range(2**n)]
num_list = []
A_list = []
xy_list = []
for i in range(n):
    a = int(eval(input()))
    A_list.append(a)
    for j in range(a):
        x, y = list(map(int, input().split()))
        xy_list.append([x, y])
for i in range(len(lst)):
    choose = lst[i]
    one_count = choose.count("1")
    a_count = 0
    flag = True
    for num, j in enumerate(A_list):
        a_count += j
        for k in range(a_count - j, a_count):
            x, y = xy_list[k][0], xy_list[k][1]
            if choose[num] == "1" and choose[x - 1] != str(y):
                flag = False
                break
    if flag:
        num_list.append(one_count)
    else:
        num_list.append(0)
print((max(num_list)))

n = int(eval(input()))
lst = [(bin(i)[2:]).zfill(n) for i in range(2**n)]
ans = 0
A_list = []
xy_list = []
for i in range(n):
    a = int(eval(input()))
    A_list.append(a)
    for j in range(a):
        x, y = list(map(int, input().split()))
        xy_list.append([x, y])
for i in range(len(lst)):
    choose = lst[i]
    one_count = choose.count("1")
    a_count = 0
    flag = True
    for num, j in enumerate(A_list):
        a_count += j
        for k in range(a_count - j, a_count):
            x, y = xy_list[k][0], xy_list[k][1]
            if choose[num] == "1" and choose[x - 1] != str(y):
                flag = False
                break
    if flag:
        ans = max(ans, one_count)
print(ans)

-num_list = [] +ans = 0 -        num_list.append(one_count) -    else: -        num_list.append(0) -print((max(num_list))) +        ans = max(ans, one_count) +print(ans)