def a():
num = [] #create a list
i = 0
x = int(raw_input())
for i in range(0, x):
s = (raw_input())
mynums = map(int, s.split()) #to take multiple inputs in a single line
num.append(mynums) #append all the inputs into the list num
flag = num.count([0]) #count the number of zeros as that would be equal to the number of players for whom tournament could be set
print flag
y = int(raw_input())
for j in range(0, y):
a()