행과 열을 나누어 문제를 풀어보았다
T = int(input())
# 여러개의 테스트 케이스가 주어지므로, 각각을 처리합니다.
for test_case in range(1, T + 1):
size, w_len = map(int, input().split())
mat = []
for i in range(size):
rows = list(input().split())
mat.append(rows)
test_ex= ''.join(['1']*w_len)
cnt = 0
#행
for row in mat:
check=''.join(row).split('0')
if test_ex in check:
cnt += check.count(test_ex)
#열
for x in range(size):
check=[]
for y in range(size):
check.append(mat[y][x])
check = ''.join(check).split('0')
if test_ex in check:
cnt += check.count(test_ex)
print('#{} {}'.format(test_case, cnt))