for _ in range(int(input())): input() print(input().count('1'))