1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def calculate_fuel_amount(n, map):
    max_zeros = 0
    current_zeros = 0

    for i in range(n):
        current_zeros = 0
        for j in range(len(map[i])):
            if map[i][j] == "0":
                current_zeros += 1
        if max_zeros < current_zeros:
            max_zeros = current_zeros

    max_zeros -= 1
    if max_zeros > 0:
        max_zeros -= 1
    else:
        max_zeros += 1

    return max_zeros

t = int(input())
for i in range(t):
    n = int(input())
    map = []
    for j in range(n):
        map.append(input())
    print(calculate_fuel_amount(n, map))