i = int(input()) for j in range(i): n = int(input()) r = list(map(int, input().split())) print(r.count(1))