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