t = int(input()) for _ in range(t): n = int(input()) f = list(map(int,input().split())) f_count = f.count(1) print(f_count)