# https://codeforces.com/contest/1923/problem/A # Returns indices of largest block starting and ending with 1s def get_largest_block(s): l = s.index('1') r = len(s) - s[::-1].index('1') - 1 return l, r # Returns number of operations to get single largest block with all 1s def single_block(s): ops = 0 l, r = get_largest_block(s) block = s[l:r] while '0' in block: while l < r: if s[l] == '0' and s[l+1] == '1': s[l], s[l+1] = '1', '0' l += 1 ops += 1 l, r = get_largest_block(s) block = s[l:r] return ops # Main function t = int(input()) for _ in range(t): n = int(input()) ribbon = input().split(' ') ops = single_block(ribbon) print(ops)