There is a bookshelf which can fit $n$ books. The $i$-th position of bookshelf is $a_i = 1$ if there is a book on this position and $a_i = 0$ otherwise. It is guaranteed that there is at least one book on the bookshelf.

In one move, you can choose some contiguous segment $[l; r]$ consisting of books (i.e. for each $i$ from $l$ to $r$ the condition $a_i = 1$ holds) and:  Shift it to the right by $1$: move the book at index $i$ to $i + 1$ for all $l \le i \le r$. This move can be done only if $r+1 \le n$ and there is no book at the position $r+1$.  Shift it to the left by $1$: move the book at index $i$ to $i-1$ for all $l \le i \le r$. This move can be done only if $l-1 \ge 1$ and there is no book at the position $l-1$. 

Your task is to find the minimum number of moves required to collect all the books on the shelf as a contiguous (consecutive) segment (i.e. the segment without any gaps).

For example, for $a = [0, 0, 1, 0, 1]$ there is a gap between books ($a_4 = 0$ when $a_3 = 1$ and $a_5 = 1$), for $a = [1, 1, 0]$ there are no gaps between books and for $a = [0, 0,0]$ there are also no gaps between books.

You have to answer $t$ independent test cases.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 200$) — the number of test cases. Then $t$ test cases follow.

The first line of the test case contains one integer $n$ ($1 \le n \le 50$) — the number of places on a bookshelf. The second line of the test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 1$), where $a_i$ is $1$ if there is a book at this position and $0$ otherwise. It is guaranteed that there is at least one book on the bookshelf.


-----Output-----

For each test case, print one integer: the minimum number of moves required to collect all the books on the shelf as a contiguous (consecutive) segment (i.e. the segment without gaps).


-----Example-----
Input
5
7
0 0 1 0 1 0 1
3
1 0 0
5
1 1 0 0 1
6
1 0 0 0 0 1
5
1 1 0 1 1

Output
2
0
2
4
1



-----Note-----

In the first test case of the example, you can shift the segment $[3; 3]$ to the right and the segment $[4; 5]$ to the right. After all moves, the books form the contiguous segment $[5; 7]$. So the answer is $2$.

In the second test case of the example, you have nothing to do, all the books on the bookshelf form the contiguous segment already.

In the third test case of the example, you can shift the segment $[5; 5]$ to the left and then the segment $[4; 4]$ to the left again. After all moves, the books form the contiguous segment $[1; 3]$. So the answer is $2$.

In the fourth test case of the example, you can shift the segment $[1; 1]$ to the right, the segment $[2; 2]$ to the right, the segment $[6; 6]$ to the left and then the segment $[5; 5]$ to the left. After all moves, the books form the contiguous segment $[3; 4]$. So the answer is $4$.

In the fifth test case of the example, you can shift the segment $[1; 2]$ to the right. After all moves, the books form the contiguous segment $[2; 5]$. So the answer is $1$.

Difficulty: EASY
Tags: Implementation

Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = 0
	an = 0
	p = []
	for i in range(n):
		if a[i] == 1:
			p.append(i)
			l += 1
	if l == 1:
		an = 0
	else:
		for i in range(l - 1):
			for j in range(p[i], p[i + 1]):
				if a[j] == 0:
					an += 1
	print(an)


t = int(input())
for k in range(0, t):
	n = int(input())
	lst = list(map(int, input().split()))
	count = 0
	ans = 0
	x = lst.index(1)
	for j in range(x, n):
		if lst[j] == 0:
			count = count + 1
		else:
			ans = ans + count
			count = 0
	print(ans)


from __future__ import division, print_function
import bisect
import math
import heapq
import itertools
import sys
from collections import deque
from atexit import register
from collections import Counter
from functools import reduce
if sys.version_info[0] < 3:
	from io import BytesIO as stream
else:
	from io import StringIO as stream
if sys.version_info[0] < 3:

	class dict(dict):

		def items(self):
			return dict.iteritems(self)

		def keys(self):
			return dict.iterkeys(self)

		def values(self):
			return dict.itervalues(self)
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def sync_with_stdio(sync=True):
	global input, flush
	if sync:
		flush = sys.stdout.flush
	else:
		sys.stdin = stream(sys.stdin.read())
		input = lambda : sys.stdin.readline().rstrip('\r\n')
		sys.stdout = stream()
		register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))

def main():
	for _ in range(int(input())):
		n = int(input())
		a = [int(o) for o in input().split()]
		while True:
			if a[-1] == 0:
				a.pop()
			else:
				break
		a = a[::-1]
		while True:
			if a[-1] == 0:
				a.pop()
			else:
				break
		ans = 0
		for i in range(len(a)):
			if a[i] == 0:
				ans += 1
		print(ans)
sync_with_stdio(False)
main()


for _ in range(int(input())):
	N = int(input())
	array = [int(x) for x in input().split()]
	while array[0] == 0:
		del array[0]
	while array[-1] == 0:
		del array[-1]
	N = len(array)
	counter = 0
	for i in array:
		if i == 0:
			counter += 1
	print(counter)


def solve(x):
	ones = x.count(1)
	if ones == 1:
		return 0
	mini = 0
	z = []
	for i in range(len(x)):
		if x[i] == 1:
			z.append(i)
	for i in range(1, len(z)):
		mini += z[i] - z[i - 1] - 1
	return mini
for _ in range(int(input())):
	x = int(input())
	l = list(map(int, input().split()))
	print(solve(l))


from sys import maxsize, stdout, stdin
mod = int(1000000000.0 + 7)

def I():
	return int(stdin.readline())

def lint():
	return [int(x) for x in stdin.readline().split()]

def S():
	return input().strip()

def grid(r, c):
	return [lint() for i in range(r)]
for _ in range(I()):
	n = I()
	ls = lint()
	cnt = 0
	flag = 0
	a = -1
	for i in range(n - 1):
		if ls[i] == 1 and ls[i + 1] == 0:
			a = i
			flag = 1
		elif flag == 1 and a != -1 and (ls[i] == 0) and (ls[i + 1] == 1):
			cnt += abs(a - i)
			flag = 0
			a = -1
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	list1 = [int(i) for i in input().split()]
	index = list1.index(1)
	count = 0
	s = n - list1[::-1].index(1) - 1
	for i in range(index, s):
		if list1[i] == 0:
			count += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	z = 0
	cnt = 0
	for i in range(n):
		if x[i]:
			for j in range(i + 1, n):
				if x[j]:
					z += cnt
					cnt = -1
				cnt += 1
			break
	print(z)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = a.count(1)
	c = 0
	d = 0
	if b == 1 or b == n or a.count(0) == n:
		print(0)
	else:
		for i in a:
			if i == 1 and c == 0:
				c = 1
			elif i == 0 and c == 1:
				d = d + 1
		for i in a[::-1]:
			if i == 0:
				d = d - 1
			else:
				break
		print(d)


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	ans = 0
	last_seen = -1
	for k in range(n):
		if arr[k] != 0:
			if last_seen == -1:
				last_seen = k
			else:
				ans += k - last_seen - 1
				last_seen = k
	print(ans)


testcases = int(input())
for i in range(testcases):
	n = int(input())
	a = [int(x) for x in input().split()]
	start = a.index(1)
	end = len(a) - a[::-1].index(1)
	count = a.count(1)
	print(end - start - count)


import copy
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ind = l.index(1)
	ind2 = -1
	for i in range(n - 1, -1, -1):
		if l[i] == 1:
			ind2 = i
			break
	ans = 0
	if l.count(1) > 1:
		for i in range(ind + 1, ind2):
			if l[i] == 0:
				ans += 1
	print(ans)


def problem_sol(x, n):
	l = n
	first = -1
	last = 0
	zeros_safe = 0
	zeros_unsafe = 0
	for i in range(0, l):
		if x[i] == 1 and first == -1:
			first = i
		if first != -1:
			if x[i] == 0:
				zeros_unsafe += 1
			if x[i] == 1:
				zeros_safe = zeros_unsafe
	print(zeros_safe)
no_inp = int(input())
while no_inp > 0:
	n = int(input())
	x = list(map(int, input().split()))
	problem_sol(x, n)
	no_inp -= 1


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True

def main():
	for _ in range(ii()):
		n = ii()
		arr = li()
		arr.insert(0, 0)
		ans = 0
		i = 0
		while i < n + 1:
			if arr[i] == 1:
				j = i + 1
				while j < n + 1:
					if arr[j] == 1:
						ans += j - i - 1
						break
					j += 1
				i = j - 1
			i += 1
		print(ans)
main()


for _ in range(int(input())):
	n = int(input())
	a = list((int(x) for x in input().split()))
	f = -1
	l = -1
	for i in range(n):
		if f == -1 and a[i] == 1:
			f = i
			break
	for i in range(n - 1, -1, -1):
		if l == -1 and a[i] == 1:
			l = i
			break
	c = a[f:l + 1]
	count = c.count(0)
	print(count)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	l = [j for j in range(n) if a[j] == 1]
	m = [l[k + 1] - l[k] - 1 for k in range(len(l) - 1)]
	print(sum(m))


t = int(input())
for ij in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	countf = 0
	start = 0
	end = 0
	i = 0
	while i < n:
		if arr[i] == 1 and i + 1 < n and (arr[i + 1] == 0):
			(start, end) = (i, 0)
			for j in range(i + 1, n):
				if arr[j] == 1 and j + 1 < n and (arr[j + 1] == 0):
					end = j
					break
				elif arr[j] == 1 and j + 1 == n:
					end = j
					break
			if end == 0:
				break
			else:
				countf += arr[start:end].count(0)
				i = end
		else:
			i += 1
	print(countf)


x = int(input())
for i in range(x):
	s = 0
	q = 0
	ch = int(input())
	y = list(map(int, input().split()))
	z = y.index(1)
	l = y[z:]
	h = l.count(1)
	for j in range(len(l)):
		if l[j] == 0:
			s += 1
		if l[j] == 1:
			q += 1
		if h == q:
			break
	print(s)


t = int(input())
for _ in range(t):
	size = int(input())
	shelf = list(map(int, input().split()))
	books = shelf.count(1)
	if books == 1:
		print(0)
		continue
	first_book = shelf.index(1)
	last_book = len(shelf) - shelf[::-1].index(1) - 1
	shelf = shelf[first_book:last_book + 1]
	moves = shelf.count(0)
	print(moves)


cases = int(input().strip())
for case in range(cases):
	shelf_len = int(input().strip())
	shelf = [int(x) for x in input().strip().split(' ')]
	left_book_idx = -1
	for (idx, book) in enumerate(shelf):
		if book:
			left_book_idx = idx
			break
	right_book_idx = -1
	for idx in range(shelf_len - 1, -1, -1):
		if shelf[idx]:
			right_book_idx = idx
			break
	empty_spots = sum([book == 0 for book in shelf[left_book_idx:right_book_idx]])
	print(empty_spots)


cases = int(input())
for _ in range(cases):
	n = int(input())
	ds = list(map(int, input().split()))
	gap = 0
	i = 0
	while i < n and ds[i] == 0:
		i += 1
	while i < n:
		while i < n and ds[i] == 1:
			i += 1
		count = 0
		while i < n and ds[i] == 0:
			count += 1
			i += 1
		if i < n:
			gap += count
	print(gap)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	p = -1
	c = 0
	for i in range(n):
		if arr[i] == 1:
			if p == -1:
				p = i
			else:
				c += i - p - 1
				p = i
	print(c)


for x in range(int(input())):
	n = int(input())
	l = input()
	l = l.strip('0 ')
	print(l.count('0'))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(start, end) = (-1, -1)
	for i in range(n):
		if a[i] == 1:
			start = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			end = i
			break
	if start == -1 and end == -1:
		print(0)
	elif start == end:
		print(0)
	else:
		print(end - start - sum(a[start:end + 1]) + 1)


def rindex(mylist, myvalue):
	return len(mylist) - mylist[::-1].index(myvalue) - 1
t = int(input())
fin = [0] * t
i = 0
if t <= 200 and t >= 1:
	while i < t:
		n = int(input())
		if n >= 1 and n <= 50:
			a = list(map(int, input().split()))
			ans = 0
			if a.count(1) > 1:
				for x in range(0, n):
					if a[x] == 1 and x != rindex(a, 1):
						y = a.index(1, x + 1, n)
						ans = ans + y - x - 1
		fin[i] = ans
		i = i + 1
for v in fin:
	print(v)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	space = 0
	first = False
	books = list(map(int, input().split()))
	for i in range(n):
		if not first:
			if books[i] == 1:
				first = True
			continue
		if books[i] == 0:
			space += 1
		if books[i] == 1:
			ans += space
			space = 0
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	x = []
	c = 0
	i = 0
	ans = 0
	while i < n - 1:
		if lst[i] == 1 and lst[i + 1] == 0:
			j = 0
			j = i + 1
			c = 0
			while j < n:
				if lst[j] == 1:
					ans += c
					break
				c += 1
				j += 1
			i = j - 1
		i += 1
	print(ans)


import sys

def rl():
	return sys.stdin.readline().strip()

def pr(something):
	sys.stdout.write(str(something) + '\n')

def pra(array):
	sys.stdout.write(' '.join([str(x) for x in array]) + '\n')

def solve(array):
	return array
NT = int(rl())
for ti in range(NT):
	_ = rl()
	array = [int(x) for x in rl().split(' ')]
	seen = False
	nz = 0
	nzend = 0
	for r in array:
		if r == 1:
			seen = True
			nzend = 0
		elif seen:
			nz += 1
			nzend += 1
	pr(nz - nzend)


import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		fl = 0
		(ans, cou) = (0, 0)
		for i in range(n):
			if a[i] == 1:
				fl = 1
			if fl:
				if not a[i]:
					cou += 1
				else:
					ans += cou
					cou = 0
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for ii in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	i = 0
	while a[i] == 0:
		i += 1
	j = n - 1
	while a[j] == 0:
		j -= 1
	d = 0
	for k in range(i, j + 1):
		if a[k] == 0:
			d += 1
	print(d)


t = int(input())
for _ in range(t):
	n = int(input())
	b = [*map(int, input().split(' '))]
	fb = -1
	gap = 0
	for i in range(len(b)):
		if b[i] == 1 and fb < 0:
			fb = i
		elif fb >= 0 and b[i] == 1:
			gap += i - fb - 1
			fb = i
	print(gap)


import os
import sys
import math
import collections
import itertools

def get_int():
	return int(input())

def get_ints():
	return map(int, input().split())

def get_strs():
	return input().split()

def get_float():
	return float(input())

def get_floats():
	return map(float, input().split())

def list_strs():
	return list(input().split())

def list_ints():
	return list(map(int, input().split()))

def list_floats():
	return list(map(float, input.split()))

def post(x):
	print(x, end=' ')
T = int(input())
for t in range(1, T + 1):
	n = get_int()
	a = list_ints()
	res = 0
	zero = 0
	flag = True
	for i in a:
		if i == 1 and flag:
			flag = False
		elif not flag and i == 0:
			zero += 1
		elif not flag and i == 1:
			res += zero
			zero = 0
	print(res)


for x in range(int(input())):
	n = int(input())
	k = list(input().split())
	s = ''
	for i in k:
		s += i
	r = s.strip('0')
	y = r.count('0')
	print(y)


def farr(s):
	all_freq = {}
	for i in s:
		if i in all_freq:
			all_freq[i] += 1
		else:
			all_freq[i] = 1
	return all_freq

def nextInt():
	return int(input())

def intArr():
	arr = input().split(' ')
	return [int(x) for x in arr]
t = nextInt()
ans = []
for tt in range(t):
	n = nextInt()
	arr = intArr()
	t = 0
	for x in arr:
		if x == 1:
			t += 1
	if t == 1 or t == 0:
		ans.append(0)
	else:
		s = False
		c = 0
		for x in range(len(arr)):
			if arr[x] == 1:
				s = True
			if arr[x] == 0 and s == True and (1 in arr[x:]):
				c += 1
		ans.append(c)
for x in ans:
	print(x)


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
import threading
import sys
import time

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def solve():
	n = get_int()
	ls = get_list()
	a = ls.index(1)
	b = a
	for (i, v) in enumerate(reversed(ls)):
		if v == 1:
			b = n - i - 1
			break
	c = 0
	for i in range(a, b):
		if ls[i] == 0:
			c += 1
	print(c)

def main():
	solve()
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


import math
for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	(c, f) = (0, 0)
	ans = 0
	for i in range(n):
		if ar[i] == 1:
			f = 1
			ans += c
			c = 0
		if ar[i] == 0 and f == 1:
			c += 1
	print(ans)


from math import *
from collections import deque
from copy import deepcopy
import sys

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def multi():
	return map(int, input().split())

def strmulti():
	return map(str, inp().split())

def lis():
	return list(map(int, inp().split()))

def lcm(a, b):
	return a * b // gcd(a, b)

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def stringlis():
	return list(map(str, inp().split()))

def out(var):
	sys.stdout.write(str(var))

def printlist(a):
	print(' '.join((str(a[i]) for i in range(len(a)))))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	a = lis()
	ans = 0
	temp = 0
	flag = False
	flag2 = False
	for i in range(n):
		if a[i] == 1:
			flag = True
		if a[i] == 1 and flag:
			flag2 = True
		if a[i] == 0 and flag:
			temp += 1
		if flag and flag2:
			ans = max(ans, temp)
			flag2 = False
	print(ans)


t = int(input().split()[0])
for _ in range(t):
	n = input()
	aa = [int(i) for i in input().split()]
	sum = 0
	started = False
	bag = 0
	for a in aa:
		if a == 0 and started:
			bag += 1
		if a == 1:
			sum += bag
			bag = 0
			started = True
	print(sum)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a.count(1) == 1:
		print('0')
		continue
	for i in range(n):
		if a[i] == 1:
			j = i
			break
	for x in range(n - 1, -1, -1):
		if a[x] == 1:
			z = x
			break
	print(a[j:z + 1].count(0))


t = int(input())
for q in range(t):
	n = input()
	s = input().split()
	z = 0
	temp = 0
	f = False
	for i in s:
		if i == '1' and f == False:
			f = True
			continue
		elif i == '1':
			z += temp
			temp = 0
			continue
		elif i == '0' and f == True:
			temp += 1
			continue
		else:
			continue
	print(z)


for _ in range(int(input())):
	(g, a) = (int(input()), list(map(int, input().split())))
	c = 0
	k = a.index(1)
	for i in range(k + 1, len(a)):
		if a[i] == 0 and a.count(1) > 1 and (sum(a[i:]) != 0):
			c += 1
	print(c)


t = int(input())
for t in range(t):
	n = int(input())
	positions = list(map(int, input().split(' ')))
	distances = []
	previousIndex = None
	for i in range(len(positions)):
		if positions[i] == 1:
			if previousIndex == None:
				previousIndex = i
			distances.append(i - previousIndex)
			previousIndex = i + 1
	totalSteps = 0
	for n in distances:
		totalSteps += n
	print(totalSteps)


t = int(input())
for i in range(t):
	k = int(input())
	n = ''.join((x for x in input().split()))
	n = n.strip('0')
	print(n.count('0'))


import sys
input = sys.stdin.readline
T = int(input())
for case in range(T):
	n = int(input())
	a = [int(x) for x in input().split()]
	d = [0] * n
	cnt = 0
	for i in range(n):
		if a[i] == 1:
			cnt += 1
	if cnt <= 1:
		print(0)
		continue
	found = False
	ans = 0
	now = 0
	for i in range(n):
		if found and a[i] == 0 and (now < cnt):
			ans += 1
		elif not found and a[i] == 1:
			found = True
			now += 1
		elif found and a[i] == 1:
			now += 1
	print(ans)


for s in [*open(0)][2::2]:
	print(s.strip('0 \n').count('0'))


try:
	for _ in range(int(input())):
		x = int(input())
		a = list(map(int, input().split()))
		z = a.count(1)
		v = 0
		if z == 0 or z == 1 or z == x:
			print(0)
		else:
			i = 0
			while v == 0:
				if a[i] == 0:
					a[i] = 2
				else:
					v = 1
				i += 1
			v = 1
			while v < z:
				if a[i] == 0:
					a[i] = 3
				else:
					v += 1
				i += 1
			print(a.count(3))
except:
	pass


t = int(input())
while t:
	nm = 0
	n = int(input())
	l = list(map(int, input().split()))
	pos = 0
	nm = 0
	fpos = l.index(1)
	for i in range(fpos + 1, n):
		if l[i]:
			npos = i
			diff = npos - fpos - 1
			if diff > 0:
				nm += diff
			fpos = npos
	print(nm)
	t -= 1


n = int(input())
for _ in range(n):
	_ = input()
	items = tuple(map(int, input().split()))
	(left, right) = (0, len(items) - 1)
	for i in range(len(items)):
		if items[i]:
			left = i
			break
	for i in range(len(items) - 1, -1, -1):
		if items[i]:
			right = i
			break
	if left == right:
		print(0)
		continue
	print(right - left + 1 - sum(items[left:right + 1]))


for _ in range(int(input())):
	c = 0
	q = False
	ans = 0
	n = int(input())
	books = list(map(int, input().split()))
	for j in books:
		if j == 1:
			q = True
			ans += c
			c = 0
		elif j == 0 and q:
			c += 1
	print(ans)


def shiftleft(arr, n):
	moves = 0
	j = n - 1
	while j >= 0:
		if arr[j] == 0:
			if j < n - 1 and arr[j + 1] == 1:
				arr = arr[:j] + arr[j + 1:] + [0]
				moves += 1
		j -= 1
	return moves

def shiftright(arr, n):
	moves = 0
	j = 0
	while j < n:
		if arr[j] == 0:
			if j > 0 and arr[j - 1] == 1:
				arr = [0] + arr[:j] + arr[j + 1:]
				moves += 1
		j += 1
	return moves

def solution(arr, n):
	i = 0
	j = n - 1
	moves = 0
	while i < n and j >= 0 and (i <= j):
		if arr[i] == 0:
			if i > 0 and arr[i - 1] == 1:
				arr = [0] + arr[:i] + arr[i + 1:]
				moves += 1
		if arr[j] == 0:
			if j < n - 1 and arr[j + 1] == 1:
				arr = arr[:j] + arr[j + 1:] + [0]
				moves += 1
		i += 1
		j -= 1
	return moves
tests = int(input())
for _ in range(tests):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	ans = arr.count(0)
	i = 0
	while i < n:
		if arr[i] == 0:
			ans -= 1
		elif arr[i] == 1:
			break
		i += 1
	j = n - 1
	while j >= 0:
		if arr[j] == 0:
			ans -= 1
		elif arr[j] == 1:
			break
		j -= 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))[:n]
	ans = 0
	pos = []
	for i in range(n):
		if a[i] == 1:
			pos.append(i)
	if len(pos) > 1:
		for j in range(0, len(pos) - 1):
			ans += pos[j + 1] - pos[j] - 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(z, o) = (0, 0)
	if len(set(l)) == 1:
		print(0)
	else:
		z = l.count(1)
		if z == 1:
			print(0)
			continue
		lst = []
		for i in range(n):
			if l[i] == 1:
				lst.append(i)
		s = 0
		for i in range(len(lst) - 1, 0, -1):
			s += abs(lst[i] - lst[i - 1] - 1)
		print(s)


for t in range(int(input())):
	input()
	s = input().replace(' ', '')
	left = s.find('1')
	right = s.rfind('1')
	ans = 0
	for i in range(left, right):
		if s[i] == '0':
			ans += 1
	print(ans)


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List
sys.setrecursionlimit(99999)

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	while arr and arr[0] == 0:
		arr.pop(0)
	while arr and arr[-1] == 0:
		arr.pop()
	return arr.count(0)
t = int(input())
for _ in range(t):
	print(solve())


for _ in range(int(input())):
	x = int(input())
	ll = input().split(' ')
	start = 9999999
	zero = 0
	ends = 0
	if ll.count('1') == 1:
		zero = 0
	else:
		for i in range(0, len(ll)):
			if start == 9999999 and ll[i] == '1':
				start = i
			if ll[i] == '1':
				ends = i
		for i in range(start, ends):
			if ll[i] == '0':
				zero += 1
	print(zero)


from functools import reduce
import collections
import math
import sys

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(delimiter=' '):
		return input().split(delimiter)

	@staticmethod
	def list_int(delimiter=' '):
		return list(map(int, input().split(delimiter)))

def main():
	t = Read.int()
	for _ in range(t):
		n = Read.int()
		a = ''.join(Read.list())
		s = a.find('1')
		e = a.rfind('1')
		if s == e:
			print(0)
		else:
			c = collections.Counter(a[s:e + 1])
			print(c['0'])
main()


import sys
si = sys.stdin.readline
t = int(si())
while t:
	t -= 1
	n = int(si())
	nums = [e for e in si().split()]
	(st, flag, cnt, tot) = (''.join(nums), False, 0, 0)
	for e in st:
		if not flag and e != '0':
			flag = True
		elif flag and e == '0':
			cnt += 1
		elif flag and e != '0':
			tot += cnt
			cnt = 0
	print(tot)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr.count(1) <= 1:
		print(0)
	else:
		first = arr.index(1)
		last = first
		for i in range(first + 1, n):
			if arr[i]:
				last = i
		cnt = 0
		for i in range(first, last + 1):
			if not arr[i]:
				cnt += 1
		print(cnt)


for _ in range(int(input())):
	x = int(input())
	r = [int(x) for x in input().split()]
	is_s = False
	last_z = 0
	tot = 0
	for i in r:
		if i == 1:
			if not is_s:
				is_s = True
				last_z = 0
			else:
				last_z = 0
		elif is_s:
			last_z += 1
			tot += 1
	print(tot - last_z)


a = int(input())
v = []
for i in range(1, a + 1):
	b = int(input())
	c = input().split(' ')
	count1 = 0
	l = c.count('1')
	g = []
	for i in c:
		if i == '1':
			count1 += 1
			k = g.append(i)
		elif count1 == l:
			break
		elif i == '0' and count1 >= 1:
			k = g.append(i)
	o = v.append(g.count('0'))
	g = []
for i in v:
	print(i)


for _ in range(int(input())):
	x = int(input())
	a = list(map(int, input().split()))
	ax = a.index(1)
	axx = x - a[-1::-1].index(1)
	result = 0
	for i in a[ax:axx]:
		if i == 0:
			result += 1
	print(result)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	start = arr.index(1)
	end = n - arr[::-1].index(1) - 1
	print(arr[start:end + 1].count(0))


t = int(input())
for i in range(0, t):
	n = int(input())
	l = list(map(int, input().split()))
	q = []
	for i in range(0, n):
		if l[i] == 1:
			q.append(i + 1)
	ans = 0
	if len(q) == 1:
		print(0)
	else:
		for i in range(0, len(q) - 1):
			p = abs(q[i] - q[i + 1])
			ans += p - 1
		print(ans)


import bisect

def solve(s, n):
	for j in range(n):
		if s[-1] == 0:
			s.pop()
		else:
			break
	s = s[::-1]
	for j in range(len(s)):
		if s[-1] == 0:
			s.pop()
		else:
			break
	return s.count(0)
t = int(input())
ans = []
for i in range(t):
	n = int(input())
	s = [int(x) for x in input().split()]
	ans.append(solve(s, n))
for test in ans:
	print(test)


for _ in range(int(input())):
	n = int(input())
	l = input().lstrip('0 ').rstrip(' 0')
	print(l.count('0'))


import sys
from collections import defaultdict
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	if lis.count(1) <= 1:
		print(0)
		continue
	i = lis.index(1)
	for j in range(n - 1, -1, -1):
		if lis[j] == 1:
			break
	c = 0
	for k in range(i, j + 1):
		if lis[k] == 0:
			c += 1
	print(c)


t = int(input())
while t > 0:
	prev = 0
	cur = 0
	count = 0
	l = int(input())
	a = input().split()
	flag = True
	for i in range(l):
		if a[i] == '1':
			if prev == 0 and cur == 0 and flag:
				(prev, cur) = (i, i)
				flag = False
			else:
				cur = i
				count += cur - prev - 1
				prev = i
	print(count)
	t -= 1


t = int(input())
while t > 0:
	n = int(input())
	books = input()
	s = books.replace(' ', '').split('1')
	sum = 0
	for i in s[1:-1]:
		sum += len(i)
	print(sum)
	t -= 1


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


t = int(input())
while t:
	n = int(input())
	a = input()
	a = a.replace(' ', '')
	x = a.find('1')
	y = a.rfind('1')
	a = a[x:y]
	a = a.replace('1', '')
	print(len(a))
	t -= 1


def first_1(A, start):
	for i in range(start, len(A)):
		if A[i] == '1':
			return i
	return -1

def solve(A):
	steps = 0
	end = first_1(A, 0)
	next_ = 0
	while next_ < len(A):
		next_ = first_1(A, end + 1)
		if next_ == -1:
			break
		steps += next_ - end - 1
		next_ += 1
		while next_ < len(A) and A[next_] != '0':
			next_ += 1
		end = next_ - 1
	return steps

def main(input_path=0):
	with open(input_path) as f:
		t = int(f.readline())
		for _ in range(t):
			f.readline()
			xs = f.readline().strip().split(' ')
			print(solve(xs))
main()


t = int(input())
while t > 0:
	n = int(input())
	l = list(map(int, input().split()))
	front = 0
	end = n - 1
	while l[front] == 0:
		front += 1
	while l[end] == 0:
		end -= 1
	if front == end:
		print('0')
	else:
		c = 0
		for i in range(front, end + 1):
			if l[i] == 0:
				c += 1
		print(c)
	t -= 1


import math as mt
import bisect
import sys
input = sys.stdin.readline
t = int(input())
import collections
import heapq
p = 10 ** 9 + 7

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def solve():
	cnt = 0
	fo = 0
	ans = 0
	for i in range(n):
		if l[i] == 1:
			fo = 1
			ans += cnt
			cnt = 0
		elif fo == 1:
			cnt += 1
	return ans
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(solve())


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	cnto = lst.count(1)
	if cnto == 1:
		print(0)
		continue
	one = False
	zer = 0
	for i in lst:
		if i == 1:
			one = True
			cnto -= 1
			continue
		if one and i == 0 and (cnto > 0):
			zer += 1
	print(zer)


from collections import Counter as cnt, defaultdict as dic
iin = lambda : int(input())
lin = lambda : list(map(int, input().rstrip().split()))
TEST_CASES = True

def main():
	n = iin()
	a = lin()
	i = 0
	while i < n and a[i] == 0:
		i += 1
	a = a[i:]
	n = len(a)
	while a and a[-1] == 0:
		a.pop()
	n = len(a)
	i = 0
	while i < len(a) - 1:
		if a[i] == 1 and a[i + 1] == 1:
			a.pop(i + 1)
		else:
			i += 1
	print(a.count(0))
if not TEST_CASES:
	main()
else:
	[main() for _ in range(int(input()))]


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	f = False
	c = 0
	for i in range(n):
		if f == True:
			if a[i] == 0:
				c += 1
			if a[i] == 1:
				ans += c
				c = 0
		if a[i] == 1:
			f = True
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	dic = {i + 1: arr[i] for i in range(n) if arr[i] == 1}
	if len(dic) == 1:
		print(0)
	else:
		moves = 0
		keys = list(dic.keys())
		m = len(keys)
		for i in range(1, m):
			if keys[i] == keys[i - 1] + 1:
				pass
			else:
				moves += keys[i] - keys[i - 1] - 1
		print(moves)


count = int(input())
for _ in range(count):
	r = 0
	count_each = int(input())
	books = list(map(int, input().split(' ')))
	books_count = books.count(1)
	if books_count == 1:
		print(r)
	else:
		first = books.index(1)
		second = 0
		while books_count > 1:
			second = books.index(1, first + 1)
			l = list(filter(lambda e: e == 0, books[first:second]))
			r += len(l)
			books_count -= 1
			first = second
		print(r)


test_cases = int(input())
for test_case in range(test_cases):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	e = 0
	while True:
		if s == 0:
			if a[0] == 1:
				s = 1
			else:
				a.pop(0)
		if e == 0:
			if a[-1] == 1:
				e = 1
			else:
				a.pop()
		if e == 1 and s == 1 or len(a) <= 1:
			break
	count = 0
	for i in a:
		if i == 0:
			count += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	j = n - 1
	i = 0
	if x[i] & x[j] == 1:
		while x[i] & x[j] == 1:
			count = 0
			for k in range(i + 1, j):
				if x[k] == 0:
					count += 1
			print(count)
			break
	elif x[i] & x[j] == 0:
		while x[i] & x[j] == 0:
			if x[i] == 1 and x[j] == 0:
				j = j - 1
			elif x[i] == 0 and x[j] == 1:
				i += 1
			elif x[i] == 0 and x[j] == 0:
				i += 1
				j -= 1
		count = 0
		for k in range(i + 1, j):
			if x[k] == 0:
				count += 1
		print(count)


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	m1 = 0
	m = 0
	count = 0
	for i in range(n):
		if ar[i] == 1:
			m = i
			break
	for i in range(n - 1, -1, -1):
		if ar[i] == 1:
			m1 = i
			break
	for i in range(m, m1 + 1):
		if ar[i] == 0:
			count += 1
	print(count)


def main_func(x: str):
	entries = x.split()
	cut_counter = 0
	for i in range(len(entries) - 1, -1, -1):
		if entries[i] == '1':
			cut_counter = i
			break
	first_one = False
	final_counter = 0
	for i in range(cut_counter + 1):
		if entries[i] == '1':
			first_one = True
		if first_one and entries[i] == '0':
			final_counter += 1
	return final_counter
t = input()
r = ''
for i in range(int(t)):
	r = input()
	l = input()
	print(main_func(l))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	k = 0
	g = 0
	sum = 0
	for j in range(len(a)):
		if a[j] == 0:
			k += 1
			if j == len(a) - 1:
				continue
		elif g == 0:
			g = 1
			k = 0
			continue
		else:
			sum += k
			b.append(k)
			k = 0
	print(sum)


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr.count(1) == 1:
		print(0)
	else:
		l = arr.index(1)
		r = 0
		for i in range(n - 1, -1, -1):
			if arr[i] == 1:
				r = i
				break
		print(arr[l:r + 1].count(0))


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]

def give(s):
	l = [[s[0], 1]]
	for i in range(1, len(s)):
		if s[i] == l[-1][0]:
			l[-1][1] += 1
		else:
			l.append([s[i], 1])
	return l[:]
for _ in range(val()):
	n = val()
	l = give(li())
	ans = 0
	for i in range(1, len(l) - 1):
		if l[i][0] == 0:
			ans += l[i][1]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(c, d) = (0, 0)
	for i in range(n):
		if l[i] == 1:
			c = i
			break
	for i in range(n):
		if l[n - i - 1] == 1:
			d = i
			break
	print(n - l.count(1) - c - d)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = []
	a = 0
	f = False
	for i in range(n):
		if l[i] == 1:
			f = True
		if f:
			if l[i] == 0:
				a += 1
			else:
				l1.append(a)
				a = 0
	print(sum(l1))


t = int(input())
for i in range(t):
	n = int(input())
	prim = False
	nr = 0
	ultim = 0
	cifre = input()
	cifre = cifre.replace(' ', '', n - 1)
	for j in cifre:
		if prim == False and j == '1':
			prim = True
		if prim == True and j == '0':
			nr += 1
		if j == '1':
			ultim = nr
	print(ultim)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	l = len(a)
	for i in range(l):
		if a[i] == 1 and 1 in a[i + 1:l]:
			for j in range(i + 1, l):
				if a[j] == 0:
					count += 1
				else:
					break
	print(count)


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	k = s.count(1)
	if k == 1:
		print(0)
		continue
	flag = False
	zero = 0
	ans = 0
	for i in s:
		if i == 1:
			flag = True
		if flag:
			if i == 0:
				zero += 1
		if flag:
			if i == 1:
				ans += zero
				zero = 0
	print(ans)


t = int(input())
for q in range(t):
	a = int(input())
	b = [int(i) for i in input().split()]
	c = True
	ans = 0
	cur = b.index(1) - 1
	for i in range(a):
		if b[i] == 1:
			if i == 0 or b[i - 1] != 1:
				ans += i - cur - 1
			cur = i
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split(' ')
	c = 0
	l = 0
	while a[l] == '0':
		l += 1
	r = n - 1
	while a[r] == '0':
		r -= 1
	for i in range(l, r + 1):
		if a[i] == '0':
			c += 1
	print(c)


for i in range(int(input())):
	input()
	s = input().split()
	lt = 0
	c = 0
	c1 = 0
	for i in s:
		if i == '1' and (not lt):
			lt = 1
		if i == '1':
			c += c1
			c1 = 0
		if lt and i != '1':
			c1 += 1
	print(c)


T = int(input())
for t in range(T):
	n = int(input())
	raw = input()
	tight = raw.replace(' ', '')
	mid = tight.strip('0')
	zero = mid.count('0')
	print(zero)


t = int(input())
i = 0
while i < t:
	n = int(input())
	start = False
	a = input().split(' ')
	z = 0
	count = 0
	for x in a:
		if x == '1':
			count += z
			z = 0
			start = True
		if start and x == '0':
			z += 1
	print(count)
	i += 1


res = ''
for _ in range(int(input())):
	n = int(input())
	x = tuple(map(int, input().split()))
	find = 0
	pos = 0
	start = False
	for i in x:
		if i == 1:
			start = True
			find += pos
			pos = 0
		elif i == 0:
			if start:
				pos += 1
	res += '%d\n' % find
print(res)


for i in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	while s[0] == 0 and len(s) != 0:
		s.remove(s[0])
	while s[-1] == 0 and len(s) != 0:
		s.pop()
	print(s.count(0))


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = a.count(1)
	p = 1
	i = a.index(1)
	moves = 0
	ans = 0
	while p <= x:
		try:
			j = a.index(1, i + 1)
		except:
			break
		if j - i == 1:
			p += 1
			i = j
			continue
		else:
			moves += j - i - 1
			i = j
			p += 1
	ans = moves
	a.reverse()
	p = 1
	moves = 0
	i = a.index(1)
	while p <= x:
		try:
			j = a.index(1, i + 1)
		except:
			break
		if j - i == 1:
			p += 1
			i = j
			continue
		else:
			moves += j - i - 1
			i = j
			p += 1
	print(min(ans, moves))


t = int(input())
cases = []
for i in range(t):
	n = int(input())
	cases.append(list(map(int, input().strip().split())))

def solve(case):
	(lo, hi) = (case.index(1), len(case) - case[::-1].index(1))
	stripped = case[lo:hi]
	print(stripped.count(0))
for case in cases:
	solve(case)


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	f = True
	c = 0
	p = set(l[1:])
	if len(p) == 1:
		print(0)
	else:
		while i < n:
			if l[i] == 1:
				i = i + 1
				while i < n and l[i] != 1:
					c = c + 1
					i = i + 1
					if i == n - 1 and l[i] == 0:
						f = False
						break
			else:
				i = i + 1
		if f == False:
			k = 0
			for i in range(len(l) - 1, -1, -1):
				if l[i] == 1:
					break
				else:
					k = k + 1
			print(c - k + 1)
		elif l[len(l) - 1] == 0 and l[len(l) - 2] == 1:
			print(c - 1)
		else:
			print(c)


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
t = ini()
for _ in range(t):
	n = ini()
	a = inl()
	if len(set(a)) != 1:
		print(a.count(0) - a.index(1) - a[::-1].index(1))
	else:
		print(0)


T = int(input())
while T != 0:
	n = int(input())
	v = [int(i) for i in input().split()]
	ind = [i for i in range(n) if v[i] == 1]
	least = min(ind)
	most = max(ind)
	count = 0
	for i in v[least:most]:
		if i == 0:
			count += 1
	print(count)
	T -= 1


test_count = int(input())
tests = []
for _ in range(test_count):
	x = int(input())
	y = list(map(int, input().split()))
	tests.append((x, y))
for test in tests:
	(count, lst) = test
	new_lst = []
	last_one = lst[0]
	new_lst.append(last_one)
	for x in lst[1:]:
		if x == 1:
			if last_one == 1:
				continue
			else:
				new_lst.append(1)
				last_one = 1
		else:
			new_lst.append(0)
			last_one = 0
	first_one_idx = new_lst.index(1)
	last_one_idx = len(new_lst) - 1 - new_lst[::-1].index(1)
	new_lst = new_lst[first_one_idx:last_one_idx + 1]
	print(new_lst.count(0))


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	a = a.lstrip('0 ').rstrip(' 0')
	print(a.count('0'))


for i in range(int(input())):
	n = input()
	ip = list(map(int, input().lstrip('0 ').rstrip(' 0').split()))
	print(ip.count(0))


from collections import Counter
import string
import math
import sys
from fractions import Fraction

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))

def printDivisors(n):
	divisors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				divisors.append(i)
			else:
				divisors.extend((i, n // i))
		i = i + 1
	return divisors

def countTotalBits(num):
	binary = bin(num)[2:]
	return len(binary)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
for _ in range(vary(1)):
	n = vary(1)
	num = array_int()
	if len(set(num)) == 1:
		print(0)
		continue
	count = 0
	if num.count(1) == 1:
		print(0)
		continue
	count = num.count(0)
	for i in range(n):
		if num[i] == 0:
			count -= 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if num[i] == 0:
			count -= 1
		else:
			break
	print(count)


a = int(input())
d = []
j = 0
for i in range(a):
	b = int(input())
	c = ''.join(input().split())
	l = b
	while c[j] != '1':
		j += 1
	while c[l - 1] != '1':
		l -= 1
	for k in range(j, l):
		d.append(c[k])
	d = ''.join(d)
	print(d.count('0'))
	d = list(d)
	d.clear()
	j = 0


from sys import stdin, stdout

def II():
	return int(stdin.readline())

def LI():
	return list(map(int, stdin.readline().split()))

def solve():
	n = II()
	a = LI()
	ones = [i for i in range(n) if a[i] == 1]
	n1 = len(ones)
	r1 = ones[-1] - ones[0] + 1
	ans = r1 - n1
	stdout.write(str(ans) + '\n')
t = II()
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	k = s.count(1)
	if k <= 1:
		print(0)
	else:
		f = 0
		ans = 0
		for i in range(n):
			if s[i] and k:
				k -= 1
				f = 1
			if k and f and (s[i] != 1):
				ans += 1
			if k == 0:
				break
		print(ans)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
import bisect
from types import GeneratorType
BUFSIZE = 8192

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections as col
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7
mod = 10 ** 9 + 7
t = int(input())
p = 10 ** 9 + 7

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def z_array(s1):
	n = len(s1)
	z = [0] * n
	(l, r, k) = (0, 0, 0)
	for i in range(1, n):
		if i > r:
			(l, r) = (i, i)
			while r < n and s1[r - l] == s1[r]:
				r += 1
			z[i] = r - l
			r -= 1
		else:
			k = i - l
			if z[k] < r - i + 1:
				z[i] = z[k]
			else:
				l = i
				while r < n and s1[r - l] == s1[r]:
					r += 1
				z[i] = r - l
				r -= 1
	return z

def solve():
	(cnt, ans) = (0, 0)
	for i in range(n):
		if l[i] == 1:
			ind = i
			break
	for i in range(ind + 1, n):
		if l[i] == 1:
			ans += cnt
			cnt = 0
		else:
			cnt += 1
	return ans
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(solve())


n = int(input())
for i in range(n):
	t = int(input())
	y = input()
	y = y.replace(' ', '')
	q = y.find('1')
	u = y.rfind('1')
	b = y[q:u]
	f = b.count('0')
	print(f)


import math
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	a = False
	ans = 0
	curr = 0
	for j in range(n):
		if l[j] == 1 and (not a):
			a = True
			curr = 0
		if l[j] == 1:
			if a:
				ans += curr
				curr = 0
		else:
			curr += 1
	print(ans)


for _ in range(0, int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	c = b.index(1)
	d = a - b[::-1].index(1)
	e = b[c:d]
	print(e.count(0))


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if l.count(1) == 1:
		print(0)
	else:
		f = l.index(1)
		for i in range(f, len(l)):
			if l[i] == 1:
				x = i
		ind = x
		k = l[f:ind + 1].count(0)
		print(k)


for i in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	count = 0
	c = x.index(1)
	x.reverse()
	c1 = x.index(1)
	c2 = n - c1 - 1
	x.reverse()
	for i in range(c, c2 + 1):
		if x[i] == 0:
			count = count + 1
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	gaps = []
	flag = False
	for j in range(n):
		if arr[j] == 1:
			while j < n and arr[j] == 1:
				j += 1
			if j < n:
				flag = True
		elif arr[j] == 0 and flag:
			gap = 0
			while j < n and arr[j] == 0:
				gap += 1
				j += 1
			if j < n:
				gaps.append(gap)
				flag = False
	pregaps = []
	summ = 0
	for num in gaps:
		summ += num
		pregaps.append(summ)
	postgaps = []
	for num in gaps:
		summ -= num
		postgaps.append(summ)
	minn = 100000000
	if len(pregaps) == 0:
		print(0)
	else:
		for i in range(len(pregaps)):
			if pregaps[i] + postgaps[i] < minn:
				minn = pregaps[i] + postgaps[i]
		print(minn)


t = int(input())
for i in range(t):
	(n, k) = (int(input()), 0)
	a = [int(s) for s in input().split()]
	s = 0
	for j in range(n):
		if a[j] == 1:
			s += 1
	for j in range(n):
		if a[j] == 1:
			l = j
			break
	for j in range(n - 1, -1, -1):
		if a[j] == 1:
			r = j
			break
	if s == 1:
		print(0)
	elif s == 2:
		print(r - l - 1)
	else:
		print(r - l - (s - 1))


t = int(input())
for i in range(t):
	n = int(input())
	x = input().replace(' ', '').strip('0').count('0')
	print(x)


caseNum = int(input())
for i in range(caseNum):
	allSum = 0
	length = int(input())
	vector = map(int, input().split())
	tempSum = 0
	one = False
	for j in vector:
		if j == 1:
			one = True
		if j == 1 and one == True:
			allSum += tempSum
			tempSum = 0
		if one == True and j == 0:
			tempSum += 1
	print(allSum)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	c = 0
	i = 0
	j = 0
	f = 0
	while i < len(a):
		if a[i] == 1:
			j = i + 1
			s = 0
			while j < len(a):
				if a[j] == 1:
					f = 1
					i = j
					break
				s = s + 1
				j = j + 1
		if f == 1:
			f = 0
			c = c + s
		else:
			i = i + 1
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	ans = []
	flag = False
	for i in range(n):
		if a[i] == 1:
			flag = True
		if a[i] == 0 and flag:
			j = i
			c = 0
			while j < n and a[j] == 0:
				c += 1
				j += 1
			if j == n:
				ans.append(0)
			elif a[j] == 1:
				ans.append(c)
				flag = False
	print(sum(ans))


t = int(input())
for i in range(t):
	n = int(input())
	s = ''.join(input().split())
	print(s[s.find('1'):s.rfind('1') + 1].count('0'))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 0
	res = 0
	i = 0
	j = 1
	while j < n:
		if a[i] == 1:
			if a[j] == 1:
				i = j
				j += 1
				res += cnt
				cnt = 0
				continue
			else:
				cnt += 1
				j += 1
				continue
		else:
			i += 1
			j += 1
	print(res)


n = int(input())
for i in range(n):
	x = int(input())
	seq = ''.join(input().split('0')).split(' ')
	met1 = False
	c1 = 0
	c2 = 0
	for i in seq:
		if i == '1' and (not met1):
			met1 = True
		elif met1 and i == '':
			c2 += 1
		elif i == '1':
			c1 += c2
			c2 = 0
	print(c1)


for _ in range(int(input())):
	n = int(input())
	s = list(map(str, input().split()))
	ans = s.count('0')
	i = 0
	while s[i] == '0':
		ans -= 1
		i += 1
	i = -1
	while s[i] == '0':
		ans -= 1
		i -= 1
	print(ans)


for t in range(int(input())):
	n = int(input())
	a = input().split()
	a = ''.join(a)
	a = a.strip('0')
	print(a.count('0'))


for _ in range(int(input())):
	_ = input()
	num_list = list(map(int, input().split()))
	while num_list[0] == 0:
		del num_list[0]
	while num_list[-1] == 0:
		del num_list[-1]
	print(num_list.count(0))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(i, j) = (0, n - 1)
	while a[i] != 1:
		i = i + 1
		if i == n:
			break
	while a[j] != 1:
		j = j - 1
		if j == -1:
			break
	ans = 0
	for x in range(i, j + 1):
		if a[x] == 0:
			ans = ans + 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = a.copy()
	b.reverse()
	i1 = a.index(1)
	i2 = b.index(1)
	i2 = n - i2 - 1
	cnt = 0
	for i in range(i1, i2 + 1):
		if a[i] == 0:
			cnt += 1
	print(cnt)


t = int(input())
for _ in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	ans = 0
	pre = -1
	for i in range(n):
		if lst[i] == 1:
			if pre == -1:
				pre = i
			else:
				ans += i - pre - 1
				pre = i
	print(ans)


t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = 0
	r = 0
	c = 0
	for i in range(n):
		if a[i] == 1:
			l = i
			break
	for i in range(n):
		if a[i] == 1:
			r = i
	for i in range(l + 1, r):
		if a[i] == 0:
			c += 1
	print(c)


for ct in range(int(input())):
	n = int(input())
	v = [int(i) for i in input().split()]
	res = 10 ** 9
	for c in range(n):
		if v[c] == 1:
			r = 0
			flag = False
			for i in range(0, c):
				if v[i] == 1 and (not flag):
					flag = True
				elif v[i] == 0 and flag:
					r += 1
			flag = False
			for i in range(n - 1, c, -1):
				if v[i] == 1 and (not flag):
					flag = True
				elif v[i] == 0 and flag:
					r += 1
			res = min(res, r)
	print(res)


T = int(input())
while T > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	segment = []
	prev = -1
	for i in range(n):
		if arr[i] == 1:
			if prev == -1:
				prev = i
		else:
			if prev != -1:
				segment.append([prev, i - 1])
			prev = -1
	if prev != -1:
		segment.append([prev, n - 1])
	res = 0
	for i in range(1, len(segment)):
		res += segment[i][0] - segment[i - 1][1] - 1
	print(res)
	T -= 1


for i in range(int(input())):
	n = int(input())
	s = list(input().split())
	a = s.index('1')
	b = 0
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			b = i
			break
	print(s[a:b].count('0'))


a = int(input())
for i in range(a):
	input()
	tests = input().split()
	while tests[-1] == '0':
		tests.pop()
	tests.reverse()
	while tests[-1] == '0':
		tests.pop()
	print(tests.count('0'))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = [int(x) for x in input().split()]
	count = 0
	ans = 0
	for i in range(n):
		if arr[i] == 1:
			break
		else:
			count += 1
	for i in range(n):
		if arr[n - 1 - i] == 1:
			break
		else:
			count += 1
	for i in range(n):
		if arr[i] == 0:
			ans += 1
	print(ans - count)


t = int(input())
for _ in range(t):
	input()
	li = list(map(int, input().split()))
	res = 0
	state = False
	temp = 0
	for i in li:
		if state and i == 0:
			temp += 1
		elif i == 1:
			state = True
			res += temp
			temp = 0
	print(res)


for _ in range(int(input())):
	n = int(input())
	shelf = list(map(int, input().split()))
	shelf = shelf[shelf.index(1):]
	while shelf[-1] == 0:
		shelf.pop(-1)
	print(shelf.count(0))


T = int(input())
for z in range(T):
	n = int(input())
	s = input()
	ones = 0
	for e in s.split():
		if e == '1':
			ones += 1
	l = []
	count = 0
	for e in s.split():
		if e == '0':
			if len(l) != 0 and ones > 0:
				l.append(0)
				count += 1
		else:
			ones -= 1
			if len(l) == 0:
				l.append(1)
			elif l[-1] == 0:
				l.append(1)
	print(count)


for _ in ' ' * int(input()):
	n = int(input())
	s = list(input())
	s = s[s.index('1'):]
	s = s[::-1]
	s = s = s[s.index('1'):]
	print(s.count('0'))


def ans(a):
	(i, j) = (0, len(a) - 1)
	while i <= j and a[i] == 0:
		i += 1
	while j >= i and a[j] == 0:
		j -= 1
	ans = 0
	while i < j:
		if a[i] == 0:
			ans += 1
		i += 1
	return ans
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(ans(a))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	stays = []
	for (ind, i) in enumerate(a):
		if i == 1:
			stays.append(ind)
	count1 = len(stays)
	do = stays[0]
	posle = len(a) - 1 - stays[-1]
	print(len(a) - count1 - do - posle)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	x = 0
	y = 0
	for i in range(n):
		if l[i] == 1:
			x = i
			break
	for i in range(n - 1, -1, -1):
		if l[i] == 1:
			y = i
			break
	l = l[x:y + 1]
	count = 0
	for i in l:
		if i == 0:
			count += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	shelf = [int(item) for item in input().split()]
	segCount = 0
	start = False
	moves = 0
	for a in shelf:
		if a == 1 and start == False:
			start = True
			segCount += 1
		if a == 0 and start == True:
			start == False
		if segCount >= 1 and a == 0:
			moves += 1
	numZeros = 0
	for a in shelf[::-1]:
		if a == 1:
			break
		else:
			numZeros += 1
	moves -= numZeros
	print(moves)


import sys

def solve(a):
	res = 0
	is1 = False
	for i in a:
		if i == 1 and (not is1):
			is1 = True
		elif i == 0 and is1:
			res += 1
	return res
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	l = 0
	r = n - 1
	while a[l] == 0:
		l += 1
	while a[r] == 0:
		r -= 1
	s = None
	if l <= r:
		s = solve(a[l:r + 1])
	print(s)


t = input()
for i in range(int(t)):
	k = 0
	n = int(input())
	ch = input()
	L = ch.split('1')
	nb = 0
	for i in range(1, len(L) - 1):
		nb += L[i].count('0')
	print(nb)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	for i in range(n):
		if arr[i] == 1:
			k = i
			break
	for i in range(1, n + 1):
		if arr[-i] == 1:
			q = n - i
			break
	ans = 0
	for i in range(k, q):
		if arr[i] == 0:
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	q = 0
	gap = 0
	for i in range(n):
		if l[i] == 1:
			if c == 0:
				c = i + 1
			q = i
	while c < q:
		if l[c] == 0:
			gap += 1
		c += 1
	print(gap)


def get_moves(arr, n):
	b = []
	for i in range(n - 1):
		if arr[i] == 1 and arr[i + 1] == 1:
			continue
		b.append(arr[i])
	b.append(arr[-1])
	count = 0
	pos_1 = []
	for i in range(len(b)):
		if b[i] == 1:
			pos_1.append(i)
			count += 1
	if count == 1:
		return 0
	ans = 0
	for i in range(len(pos_1) - 1):
		ans += pos_1[i + 1] - pos_1[i] - 1
	return ans
t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	print(get_moves(arr, n))
	t -= 1
get_moves([1, 1, 0, 0, 1, 1], 6)


t = int(input())
for i in range(t):
	n = int(input())
	s = input().split()
	for j in range(len(s)):
		if s[j] == '0':
			s[j] = 2
		else:
			break
	s.reverse()
	for j in range(len(s)):
		if s[j] == '0':
			s[j] = 2
		else:
			break
	print(s.count('0'))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().strip().split(' ')))
	val = 0
	for i in range(n):
		if l[i] == 0:
			val += 1
	for i in l:
		if i == 0:
			val -= 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if l[i] == 0:
			val -= 1
		else:
			break
	print(val)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = []
	d = 0
	b = len(a)
	for k in range(b):
		if a[k] == 1:
			c.append(k)
	b = len(c)
	if b > 1:
		for k in range(1, b):
			d = d + (c[k] - c[k - 1])
			d -= 1
	else:
		d = 0
	print(d)


t = int(input())
while t != 0:
	n = int(input())
	book = list(map(int, input().split()))
	count = 0
	first_book = book.index(1)
	book_arr = book[first_book:]
	count = 0
	fre = 0
	while len(book_arr) != 0:
		booknum = book_arr.pop(0)
		if booknum == 0:
			count += 1
		elif booknum == 1:
			fre = count
	print(fre)
	t -= 1


def bookshelf(li):
	front = False
	back = False
	while not front:
		if li[0] == 1:
			front = True
		else:
			li.pop(0)
	while not back:
		if li[-1] == 1:
			back = True
		else:
			li.pop()
	return li.count(0)
n = int(input())
ans_lst = []
for i in range(n):
	m = int(input())
	lst = list(map(int, input().split()))
	ans_lst.append(bookshelf(lst))
for i in range(n):
	print(ans_lst[i])


n = int(input())
for i in range(n):
	t = int(input())
	l = list(map(int, input().split()))
	lCopy = l.copy()
	lCopy.reverse()
	for i in range(len(l)):
		if l[i] == 1:
			i = i
			break
	for j in range(len(lCopy)):
		if lCopy[j] == 1:
			j = t - j - 1
			break
	if i == j:
		print(0)
	else:
		sum = 0
		for k in l[i + 1:j]:
			sum += k
		print(j - i - sum - 1)


t = int(input())
while t > 0:
	x = int(input())
	n = input().split()
	s = ''.join(n)
	n = int(s)
	n = str(n)
	n1 = [i for i in n]
	n1 = n1[::-1]
	s1 = ''.join(n1)
	n1 = int(s1)
	n1 = str(n1)
	print(n1.count('0'))
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	ans = a.count(0)
	l = 0
	while a[l] == 0:
		ans -= 1
		l += 1
	r = n - 1
	while a[r] == 0:
		ans -= 1
		r -= 1
	print(ans)


n = int(input())
ls = []
for m in range(n):
	jkkj = int(input())
	f = list(map(str, input().split()))
	ls.append(f)
for i in ls:
	r = -1
	l = 0
	res = 0
	while True:
		for j in i:
			if j == '1':
				break
			else:
				l += 1
		for df in range(len(i)):
			if i[r] == '1':
				break
			else:
				r -= 1
		if r == -1:
			xls = i[l:]
		else:
			xls = i[l:r + 1]
		for k in xls:
			if k == '0':
				res += 1
		break
	print(res)


tc = int(input())
for _ in range(tc):
	n = int(input())
	arr = list(map(int, input().split()))
	count = 0
	prev = 0
	for i in range(n):
		if arr[i] == 1:
			prev = 1
		elif prev == 1:
			count += 1
	for i in range(n - 1, -1, -1):
		if arr[i] == 0:
			count -= 1
		else:
			break
	print(count)


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	l1 = []
	for i in range(len(l)):
		if l[i] == 1:
			l1.append(i)
		else:
			continue
	if len(l1) <= 1:
		print(0)
	else:
		s = 0
		if len(l1) == 2:
			if l1[1] - l1[0] == 1:
				print(0)
			else:
				print(l1[1] - l1[0] - 1)
		else:
			for i in range(1, len(l1)):
				if l1[i] - l1[i - 1] == 1:
					s += 0
				else:
					s += l1[i] - l1[i - 1] - 1
			print(s)
	t = t - 1


tests = int(input())
for t in range(tests):
	n = input()
	ls = list(map(int, input().split()))
	res = 0
	start = None
	check = False
	last_one = 0
	first_zero = 0
	for (idx, item) in enumerate(ls):
		if item == 1:
			if start is None:
				start = True
			last_one = idx
		if item == 0:
			if start:
				first_zero = idx
				start = False
				check = True
			if check:
				res += 1
	if last_one > first_zero:
		res -= len(ls) - last_one - 1
	else:
		res = 0
	print(res)


for i in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	print(abs(n - lst[::-1].index(1) - lst.index(1)) - lst.count(1))


def solution():
	n = int(input())
	a = list(map(int, input().split()))
	while a[-1] != 1:
		a.pop()
	a.reverse()
	while a[-1] != 1:
		a.pop()
	ans = 0
	for i in range(len(a)):
		if a[i] == 0:
			ans += 1
	print(ans)

def main():
	testcase = int(input())
	for i in range(testcase):
		solution()
	return
main()


import sys
test_case_num = int(input())
for i in range(test_case_num):
	num = int(input())
	shelf = list(map(int, input().split()))
	result = 0
	start_index = 0
	end_index = len(shelf) + 1
	for l in range(len(shelf)):
		if shelf[l] == 1:
			start_index = l
			break
	for l in range(len(shelf) - 1, -1, -1):
		if shelf[l] == 1:
			end_index = l
			break
	for data in shelf[start_index:end_index + 1]:
		if data == 0:
			result += 1
	print(result)


for _ in range(int(input())):
	b = int(input())
	a = list(map(int, input().split()))
	if a.count(1) == 1:
		print(0)
	else:
		k1 = a.index(1)
		k2 = len(a) - a[::-1].index(1)
		print(a[k1:k2].count(0))


numcases = int(input())
for i in range(numcases):
	cnt = 0
	start = 0
	end = 0
	size = int(input())
	info = input().split()
	for i in range(size):
		curr = info[i]
		if curr == '1':
			start = i
			break
	for j in range(size):
		curr = info[size - j - 1]
		if curr == '1':
			end = size - j - 1
			break
	for k in range(start, end + 1):
		if info[k] == '0':
			cnt += 1
	print(cnt)


t = int(input())
l = []
temp = []
n = 0
for i in range(t):
	n = int(input())
	temp = list(map(int, input().split()))
	l.append(temp)
	temp = []
count = []
c = 0
for i in range(t):
	s = -1
	e = -1
	for j in range(len(l[i])):
		if l[i][j] == 1 and s == -1:
			s = j
		elif l[i][j] == 1 and s != -1:
			e = j
		elif l[i][j] != 1 and s != -1 and (1 in l[i][j:]):
			e = j - 1
			t1 = l[i][j]
			temp = l[i][s:e + 1]
			l[i][s] = t1
			l[i][s + 1:j + 1] = temp
			s += 1
			c += 1
	count.append(c)
	c = 0
	s = -1
	e = -1
for i in count:
	print(i)


from itertools import groupby

def solve(n):
	f = False
	z = 0
	groups = 0
	for (k, v) in groupby(n):
		if k == 1:
			f = True
		if f:
			if not k:
				z += len(list(v))
		groups += 1
	return 0 if groups <= 2 else z

def main():
	TT = int(input())
	for i in range(TT):
		_ = int(input())
		print(solve(map(int, input().strip('0 ').split())))
main()


def cal(n, arr):
	index = 0
	res = 0
	stack = []
	last_one = None
	for i in range(n):
		if arr[i] == 1:
			last_one = i
			index = i + 1
			break
	while index < n:
		if arr[index] == 0:
			stack.append(i)
		elif arr[index] == 1:
			res += len(stack)
			stack = []
		index += 1
	return res
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(cal(n, arr))


import sys
sys.setrecursionlimit(3000)
import re
import math
import itertools
import collections
import bisect
import fractions
mod = 1000000007
pi = 3.141592653589793
IS = float('inf')
xy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
bs = [(-1, -1), (-1, 1), (1, 1), (1, -1)]

def niten(a, b):
	return abs(a - b) if a >= 0 and b >= 0 else a + abs(b) if a >= 0 else abs(a) + b if b >= 0 else abs(abs(a) - abs(b))

def fib(n):
	return [(seq.append(seq[i - 2] + seq[i - 1]), seq[i - 2])[1] for seq in [[0, 1]] for i in range(2, n)]

def lcm(a, b):
	return a * b // fractions.gcd(a, b)

def eucl(x1, y1, x2, y2):
	return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5

def choco(xa, ya, xb, yb, xc, yc, xd, yd):
	return 1 if abs((yb - ya) * (yd - yc) + (xb - xa) * (xd - xc)) < 1e-10 else 0

def eof(t):
	print(t)
	exit()
t = int(input())
for i in range(t):
	ans = f = 0
	n = int(input())
	a = [int(i) for i in input().split()]
	while a[-1] == 0:
		a.pop()
	for i in a:
		if i == 1:
			f = 1
		if f == 1 and i == 0:
			ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(count, ans) = (0, 0)
	z = 0
	while a:
		k = a.pop()
		if k == 0 and z == 1:
			count += 1
		elif k == 1:
			z = 1
			ans += count
			count = 0
	if k == 1 and z == 1:
		ans += count
	print(ans)


T = int(input())
for t in range(T):
	n = int(input())
	books = input()
	leftmostOne = books.index('1')
	rightmostOne = books.rindex('1')
	print(books[leftmostOne:rightmostOne].count('0'))


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c
for xyz in range(0, int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	g = []
	while i < n:
		if l[i] == 0:
			t = countcon(l, i)
			i += t
			g.append(t)
		else:
			i += 1
	if l[0] == 0:
		g.pop(0)
	if l[-1] == 0:
		g.pop()
	print(sum(g))


count = int(input())
while count:
	l = int(input())
	n = input().split()
	step = 0
	ck = 0
	for i in range(l):
		if n[i] == '1':
			for j in range(i + 1, l):
				if n[j] == '0':
					ck += 1
				elif n[j] == '1':
					step += ck
					ck = 0
					break
	print(step)
	count -= 1


for _ in range(0, int(input())):
	n = int(input())
	l = input().split()
	m = ''.join(l)
	m = m.strip('0')
	print(m.count('0'))


for _ in range(int(input())):
	n = int(input())
	s = input()
	s = ''.join(s.split())
	s = s.split('1')
	s = '1'.join(s)
	s = s.strip('0')
	print(s.count('0'))


tests = int(input())
for test in range(tests):
	n = int(input())
	l = ''.join([x for x in input().split(' ')])
	l = l.strip('0')
	print(l.count('0'))


from math import *
from bisect import *
from collections import *
from random import *
from decimal import *
from itertools import *
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return list(map(int, input().split()))
t = inp()
while t:
	t -= 1
	n = inp()
	a = lis()
	while len(a) and a[-1] == 0:
		a.pop()
	a = a[::-1]
	while len(a) and a[-1] == 0:
		a.pop()
	print(a.count(0))


a = int(input())
for i in range(a):
	qwerty = 1
	b = int(input())
	massiv = list(map(int, input().split()))
	lg = 0
	answer = 0
	for k in range(len(massiv)):
		i = massiv[k]
		if i == 1 and lg == 0:
			lg = 1
		if i == 0 and lg == 1 and (1 in massiv[k:]):
			answer += 1
	print(answer)


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	for i in range(0, n):
		if ar[i] == 1:
			left = i
			break
	for i in range(n - 1, -1, -1):
		if ar[i] == 1:
			right = i
			break
	ans = 0
	for i in range(left, right):
		if ar[i] == 0:
			ans += 1
	print(ans)


for _ in range(int(input())):
	N = int(input())
	numbers = list(map(int, input().split()))
	answer = 0
	flag = False
	cnt = 0
	for n in numbers:
		if n:
			if flag:
				answer += cnt
				cnt = 0
			else:
				flag = True
		elif flag:
			cnt += 1
	print(answer)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	start = 0
	end = 0
	flag = 1
	for i in range(n):
		if a[i] == 1 and flag:
			flag = 0
			start = i
		if a[i] == 1:
			end = i
	ans = 0
	for i in range(start, end):
		if a[i] == 0:
			ans += 1
	print(ans)


from sys import stdout, stdin
from collections import defaultdict, deque
import math
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	l = list(map(int, stdin.readline().split()))
	(ind, indd) = (-1, -1)
	for i in range(n):
		if l[i] == 1:
			ind = i
			break
	for i in range(n - 1, -1, -1):
		if l[i] == 1:
			indd = i
			break
	count = 0
	for i in range(ind, indd + 1):
		if l[i] == 0:
			count += 1
	print(count)


t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	li = [int(i) for i in l]
	z = []
	start = -1
	end = -1
	done = 0
	for i in range(n):
		if li[i] == 1:
			if done:
				end += 1
			else:
				done = 1
				start = i
				end = i
		elif done:
			z.append((start, end))
			done = 0
	if done:
		z.append((start, end))
	ans = 0
	for i in range(1, len(z)):
		ans = ans + (z[i][0] - z[i - 1][1] - 1)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = [int(x) for x in input().split()]
	l = []
	for i in range(n):
		if s[i] == 1:
			l.append(i)
	p = 0
	for i in range(len(l) - 1):
		k = l[i + 1] - l[i] - 1
		p += k
	print(p)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if a.count(1) == 1:
		print(0)
	else:
		f = 0
		(c, x) = (0, 0)
		for i in range(n):
			if a[i] == 1:
				f = 1
				x += c
				c = 0
			elif f == 1:
				c += 1
		print(x)


n = int(input())
for _ in range(n):
	m = int(input())
	a = [int(i) for i in input().split()]
	if 1 not in a:
		print(0)
	elif a.count(1) == 1:
		print(0)
	else:
		b = a.index(1)
		c = len(a) - 1 - a[::-1].index(1)
		d = 0
		for j in range(b, c + 1):
			if a[j] == 0:
				d = d + 1
		print(d)


import heapq as hq
from heapq import heappop, heappush
from collections import deque, defaultdict, Counter
from sys import stdin, stdout

def inp():
	return int(stdin.readline())

def inlt():
	return list(map(int, stdin.readline().split()))

def insr():
	return list(stdin.readline().strip())

def invr():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def subset_sum_count(arr, n, sum):
	dp = [[0 for _ in range(sum + 1)] for _ in range(n + 1)]
	for i in range(n + 1):
		for j in range(sum + 1):
			if j == 0:
				dp[i][j] = 1
			elif arr[i - 1] <= j:
				dp[i][j] = dp[i - 1][j - arr[i - 1]] + dp[i - 1][j]
			else:
				dp[i][j] = dp[i - 1][j]
	return dp[n][sum]

def binary_search(func, lo, hi, abs_prec=1e-07):
	while abs(hi - lo) > abs_prec:
		mi = lo + (hi - lo) / 2
		if func(mi):
			hi = mi
		else:
			lo = mi
	return (lo + hi) / 2

def ternary_search(func, lo, hi, abs_prec=1e-07):
	while abs(hi - lo) > abs_prec:
		lo_third = lo + (hi - lo) / 3
		hi_third = hi - (hi - lo) / 3
		if func(lo_third) < func(hi_third):
			lo = lo_third
		else:
			hi = hi_third
	return (lo + hi) / 2

def discrete_binary_search(func, lo, hi):
	while lo < hi:
		mi = lo + (hi - lo) // 2
		if func(mi):
			hi = mi
		else:
			lo = mi + 1
	return lo

def discrete_ternary_search(func, lo, hi):
	while lo <= hi:
		lo_third = lo + (hi - lo) // 3
		hi_third = lo + (hi - lo) // 3 + (1 if 0 < hi - lo < 3 else (hi - lo) // 3)
		if func(lo_third) < func(hi_third):
			lo = lo_third + 1
		else:
			hi = hi_third - 1
	return lo
	return -1

def right_rotate(a, s):
	return a[s:] + a[:s]

def dec_to_bin(x):
	return int(bin(x)[2:])

def str_to_integer_list(n):
	a = []
	for i in range(len(n)):
		a.append(int(n[i]))
	return a

def list_to_str(l):
	s = ''
	for i in l:
		s += str(i)
	return s

def dijkstra(s, N, E):
	visited = set()
	dist = {}
	for i in range(1, N + 1):
		dist[i] = 1 << 29
	queue = [(dist[i], i) for i in range(1, N + 1)]
	hq.heappush(queue, (0, s))
	dist[s] = 0
	while queue:
		(d, u) = hq.heappop(queue)
		if u in visited:
			continue
		for t in E[u]:
			(v, r) = t
			if dist[v] > d + r:
				dist[v] = d + r
				hq.heappush(queue, (dist[v], v))
		visited.add(u)
	return dist

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def dijkstra(n, graph, start):
	(dist, parents) = ([float('inf')] * n, [-1] * n)
	dist[start] = 0
	queue = [(0, start)]
	while queue:
		(path_len, v) = heappop(queue)
		if path_len == dist[v]:
			for (w, edge_len) in graph[v]:
				if edge_len + path_len < dist[w]:
					(dist[w], parents[w]) = (edge_len + path_len, v)
					heappush(queue, (edge_len + path_len, w))
	return (dist, parents)

def path(start, end, parent):
	path = [end]
	while path[-1] != start:
		path.append(parent[path[-1]])
	path.reverse()
	return path

def bfs(graph, start, goal):
	if start == goal:
		return [start]
	visited = {start}
	queue = deque([(start, [])])
	while queue:
		(current, path) = queue.popleft()
		visited.add(current)
		for neighbor in graph[current]:
			if neighbor == goal:
				return path + [current, neighbor]
			if neighbor in visited:
				continue
			queue.append((neighbor, path + [current]))
			visited.add(neighbor)
	return None

def fillPrefixSum(arr, n, prefixSum):
	prefixSum[0] = arr[0]
	for i in range(1, n):
		prefixSum[i] = prefixSum[i - 1] + arr[i]

def check(a, ind, d1):
	beg = a[:ind + 1]
	end = a[ind + 1:]
	d = []
	c = 0
	for i in end:
		if i - d1 in beg:
			c += 1
	return c
import os
import sys
from io import BytesIO, IOBase

def DecimalToBinary(n):

	def helper(n):
		if n == 0:
			return ''
		else:
			if n % 2 == 1:
				binaryDigit = '1'
			else:
				binaryDigit = '0'
			return helper(n // 2) + binaryDigit
	if n == 0:
		result = '0'
	else:
		result = helper(n)
	return result

def p(board):
	for i in range(8):
		s = ''
		for j in range(8):
			s += board[i][j]
		print(s)

def binaryToDecimal(n):
	return int(n, 2)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def solve(a, b):
	x = DecimalToBinary(a)
	y = DecimalToBinary(b)
	z = x + y
	l = y + x
	r = binaryToDecimal(z) - binaryToDecimal(l)
	return r

def mostFrequent(arr, n):
	arr.sort()
	max_count = 1
	res = arr[0]
	curr_count = 1
	for i in range(1, n):
		if arr[i] == arr[i - 1]:
			curr_count += 1
		else:
			if curr_count > max_count:
				max_count = curr_count
				res = arr[i - 1]
			curr_count = 1
	if curr_count > max_count:
		max_count = curr_count
		res = arr[n - 1]
	return res
from bisect import bisect_right, bisect_left

def lds(arr, n):
	lds = [0] * n
	max = 0
	for i in range(n):
		lds[i] = 1
	for i in range(1, n):
		for j in range(i):
			if arr[i] < arr[j] and lds[i] < lds[j] + 1:
				lds[i] = lds[j] + 1
	for i in range(n):
		if max < lds[i]:
			max = lds[i]
	return max
import math

def prefix(a):
	pre = []
	pre.append(a[0])
	for i in range(1, len(a)):
		pre.append(pre[i - 1] + a[i])
	return pre

def main():
	for _ in range(inp()):
		n = inp()
		a = inlt()
		if a.count(1) == 1:
			print(0)
		else:
			c = 0
			id1 = a.index(1)
			id2 = n - 1 - a[::-1].index(1)
			for i in range(id1, id2):
				if a[i] == 0:
					c += 1
			print(c)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import maxsize, stdout, stdin
mod = int(1000000000.0 + 7)

def I():
	return int(stdin.readline())

def lint():
	return [int(x) for x in stdin.readline().split()]

def S():
	return input().strip()

def grid(r, c):
	return [lint() for i in range(r)]

def main():
	n = I()
	ls = lint()
	(x1, x2) = (-1, -1)
	for i in range(n):
		if ls[i] == 1:
			x1 = i
			break
	for j in range(n - 1, -1, -1):
		if ls[j] == 1:
			x2 = j
			break
	if x1 == x2:
		print(0)
	else:
		print(ls[x1:x2 + 1].count(0))
for _ in range(I()):
	main()


n = int(input())
l = list()
ln = list()
for i in range(n):
	ln.append(int(input()))
	l.append(list(map(int, input().rstrip().split())))
for ml in l:
	b = False
	l = r = result = mr = 0
	for i in ml:
		if i == 1:
			if not b:
				b = True
				continue
			else:
				result += mr
				mr = 0
		elif b:
			mr += 1
	print(result)


for T in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	i = 0
	while i < len(arr) and arr[i] == 0:
		i += 1
	arr = arr[i:]
	i = len(arr) - 1
	while i >= 0 and arr[i] == 0:
		i -= 1
	arr = arr[:i + 1]
	right = 0
	left = 0
	count = 0
	for i in range(len(arr)):
		if arr[i] == 0:
			count += 1
		else:
			right += count
			count = 0
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] == 0:
			count += 1
		else:
			left += count
			count = 0
	print(min(left, right))


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from itertools import accumulate

def Int():
	return int(sys.stdin.readline())

def Mint():
	return map(int, sys.stdin.readline().split())

def Lstr():
	return list(sys.stdin.readline().strip())

def Str():
	return sys.stdin.readline().strip()

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

def List():
	return list(map(int, sys.stdin.readline().split()))

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def Lcm(x, y):
	return x * y // gcd(x, y)

def dtob(n):
	return bin(n).replace('0b', '')

def btod(n):
	return int(n, 2)

def common(l1, l2):
	return set(l1).intersection(l2)

def solution():
	for _ in range(Int()):
		n = Int()
		a = List()
		for i in range(n):
			if a[i] == 1:
				s = i
				break
		for i in range(n - 1, -1, -1):
			if a[i] == 1:
				e = i
				break
		c = e - s
		for i in range(s, e):
			if a[i] == 1:
				c = c - 1
		print(c)
solution()


n = int(input())
for i in range(n):
	m = int(input())
	books = [int(i) for i in input().split()]
	ans = 0
	kol = 0
	s = books.index(1)
	for i in range(s + 1, m):
		if books[i] == 1:
			ans += kol
			kol = 0
		elif books[i] == 0:
			kol += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = A[::-1]
	k = 0
	for i in range(A.index(1), n - B.index(1)):
		if A[i] == 0:
			k += 1
	print(k)


import sys, threading
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def rl(type):
	return [type(w) for w in input().split()]

def reverse(arr):
	return arr[-1::-1]

def mod(a, m):
	return (a % m + m) % m

def check_prime(n):
	temp = int(math.sqrt(n) + 1)
	for i in range(2, temp):
		if n % i == 0:
			return False
	return True

def create_graph(n):
	graph = {}
	for _ in range(n):
		(x, y) = map(int, input().split())
		graph[x].append(y)
		graph[y].append(x)
	return graph

def solve(arr):
	result = 0
	for i in arr:
		if i == 0:
			result += 1
	return result

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = rl(int)
		(fz, lz) = (0, 0)
		if arr.count(arr[0]) == len(arr):
			print(0)
		else:
			for i in arr:
				if i == 1:
					break
				else:
					fz += 1
			for i in arr[-1::-1]:
				if i == 1:
					break
				else:
					lz += 1
			print(solve(arr) - fz - lz)
sys.setrecursionlimit(10 ** 6)
threading.stack_size(10 ** 8)
t = threading.Thread(target=main)
t.start()
t.join()


import sys
t = int(sys.stdin.readline().strip())
for _ in range(t):
	n = int(sys.stdin.readline().strip())
	shelf = ''.join(sys.stdin.readline().split())
	shelf = shelf.strip('0')
	shelf = list(map(int, [c for c in shelf]))
	start = False
	gaps = 0
	for b in shelf:
		if b == 1 and (not start):
			start = True
		if b == 0 and start:
			gaps += 1
	print(gaps)


def ans(a, n):
	i = 0
	while a[i] == 0:
		i += 1
	b = a[i:]
	j = len(b) - 1
	while b[j] == 0:
		j -= 1
	c = b[:j + 1]
	x = 0
	for i in c:
		if i == 0:
			x += 1
	return x
m = int(input())
for j in range(m):
	n = int(input())
	arr = input().split()
	a = []
	for i in arr:
		a.append(int(i))
	print(ans(a, n))


import sys
try:
	(sys.stdin, sys.stdout) = (open('in.txt', 'r'), open('out.txt', 'w'))
except:
	pass
ii1 = lambda : int(sys.stdin.readline().strip())
is1 = lambda : sys.stdin.readline().strip()
iia = lambda : list(map(int, sys.stdin.readline().strip().split()))
isa = lambda : sys.stdin.readline().strip().split()
mod = int(1000000000.0 + 7)
from collections import *
from math import *
for _ in range(ii1()):
	n = ii1()
	arr = iia()
	start = 0
	for i in range(n):
		if arr[i] == 1:
			start = i
			break
	count = 0
	ans = 0
	for i in range(start, n):
		if arr[i] == 0:
			count += 1
		else:
			if count > 0:
				ans += count
			count = 0
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	books = [int(i) for i in input().split()]
	a = -1
	b = -1
	for i in range(len(books)):
		if books[i] == 1:
			a = i
			break
	for i in range(len(books)):
		if books[len(books) - i - 1] == 1:
			b = len(books) - i - 1
			break
	res = 0
	for i in range(a, b + 1):
		if books[i] == 0:
			res += 1
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	s = 0
	e = n - 1
	while s < e:
		if l[s] != 1:
			s = s + 1
		if l[e] != 1:
			e = e - 1
		if l[s] == 1 and l[e] == 1:
			break
	print(l[s + 1:e].count(0))


from sys import stdin
for _ in range(int(stdin.readline())):
	_ = input()
	num_list = list(map(int, stdin.readline().split()))
	while num_list[0] == 0:
		del num_list[0]
	while num_list[-1] == 0:
		del num_list[-1]
	print(num_list.count(0))


t = int(input())
for _ in range(t):
	n = int(input())
	p = [int(i) for i in input().split()]
	sum_p = sum(p)
	count = 0
	for i in range(len(p)):
		if p[i] == 1:
			index = i
			break
	for k in range(len(p) - 1, -1, -1):
		if p[k] == 1:
			l_index = k
			break
	raw = 0
	max_raw = 0
	for j in range(index, l_index + 1):
		if p[j] == 0:
			count += 1
			raw = 0
		else:
			raw += 1
			if raw > max_raw:
				max_raw = raw
	if max_raw == sum(p):
		print(0)
	elif sum(p) <= 1:
		print(0)
	else:
		print(count)


t = int(input())
res = []
for _ in range(t):
	n = int(input())
	a = input().split()
	i = a.index('1')
	count = 0
	ncount = 0
	for i in range(i + 1, n):
		if a[i] == '0':
			ncount += 1
		else:
			count += ncount
			ncount = 0
	res.append(count)
for r in res:
	print(r)


t = int(input())
for i in range(t):
	count = 0
	n = int(input())
	arr = input().split(' ')
	leftptr = 0
	rightptr = n - 1
	while arr[leftptr] == '0':
		leftptr += 1
	while arr[rightptr] == '0':
		rightptr -= 1
	for i in range(leftptr, rightptr + 1):
		if arr[i] == '0':
			count += 1
	print(count)


for _ in range(int(input())):
	_ = int(input())
	(*books,) = map(int, input().split())
	left = 0
	right = len(books) - 1
	while books[left] != 1:
		left += 1
	while books[right] != 1:
		right -= 1
	print(right + 1 - left - books.count(1))


for _ in range(int(input())):
	n = int(int(input()))
	c = 0
	x = []
	l = list(map(int, input().split()))
	for i in range(n):
		if l[i] == 1:
			x.append(i)
	for i in range(len(x) - 1):
		c += x[i + 1] - x[i] - 1
		i += 1
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	x = s.index(1)
	s.reverse()
	y1 = s.index(1)
	y = len(s) - y1
	s.reverse()
	print(s[x:y].count(0))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if a.count(1) < 2:
		print(0)
	else:
		l = a.index(1)
		r = n - 1 - a[::-1].index(1)
		print(a[l:r + 1].count(0))


from sys import stdin, stdout

def INI():
	return int(stdin.readline())

def INL():
	return [int(_) for _ in stdin.readline().split()]

def INS():
	return stdin.readline()

def OPS(ans):
	stdout.write(str(ans) + '\n')

def OPL(ans):
	[stdout.write(str(_) + ' ') for _ in ans]
	stdout.write('\n')
for _ in range(INI()):
	n = INI()
	A = INL()
	i = A.index(1)
	f = 1
	X = []
	for _ in range(i, n):
		if A[_] == 1:
			X.append(_)
	ans = 0
	for _ in range(len(X) - 1):
		ans += X[_ + 1] - X[_] - 1
	OPS(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	while l[i] != 1:
		i += 1
	j = n - 1
	while l[j] != 1:
		j -= 1
	ans = 0
	for k in range(i + 1, j):
		if l[k] == 0:
			ans += 1
	print(ans)


for o in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	c = 0
	p = 0
	q = 0
	for i in range(n):
		if c == 1:
			if s[i] == 0:
				p = p + 1
			elif s[i] == 1:
				q = q + p
				p = 0
		if s[i] == 1:
			c = 1
	print(q)


p = int(input())
for i in range(p):
	n = int(input())
	m = input().split()
	nach = -1
	kon = 0
	for i in range(n):
		if nach == -1 and m[i] == '1':
			nach = i
		if m[i] == '1':
			kon = i
	otv = 0
	for i in range(nach + 1, kon):
		if m[i] == '0':
			otv += 1
	print(otv)


t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	count = 0
	for i in l:
		if i == 1:
			count += 1
	if count == 0 or count == 1:
		res = 0
	else:
		for i in range(n):
			if l[i] == 1:
				break
		start = i
		for i in range(n):
			if l[n - i - 1] == 1:
				break
		end = n - i - 1
		res = end - start - count + 1
	print(res)


for __ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	ans = ar.count(0)
	i = 0
	while ar[i] == 0:
		ans -= 1
		i += 1
	j = n - 1
	while ar[j] == 0 and i != j:
		ans -= 1
		j -= 1
	print(max(0, ans))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	res = 0
	i = 0
	while i < n:
		if arr[i]:
			i += 1
			var = 0
			one = 0
			while i < n:
				if arr[i]:
					one = 1
					break
				else:
					var += 1
				i += 1
			if one:
				res += var
		else:
			i += 1
	print(res)


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(n - (arr.index(1) + arr[::-1].index(1)) - arr.count(1))


from queue import Queue
t = int(input())
for _ in range(t):
	books = int(input())
	line = list(map(int, input().split()))
	start = None
	end = None
	queue = Queue()
	counter = 0
	firstone = None
	lastone = None
	for (indx, x) in enumerate(line):
		if x == 1 and firstone is None:
			firstone = indx
		elif x == 1:
			lastone = indx
	if lastone is None:
		print('0')
		continue
	for x in range(firstone, lastone + 1):
		if line[x] == 0:
			counter += 1
	print(counter)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	a = 0
	mode = 0
	for i in range(n):
		if l[i] == 0 and mode == 1:
			c += 1
		elif l[i] == 1:
			mode = 1
			a += c
			c = 0
	b = 0
	c = 0
	mode = 0
	for i in reversed(range(n)):
		if l[i] == 0 and mode == 1:
			c += 1
		elif l[i] == 1:
			mode = 1
			b += c
			c = 0
	print(min(a, b))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	z = 0
	l = -1
	c = 0
	for i in range(n):
		if a[i] == 0:
			z += 1
		else:
			if l != -1:
				c += z
			l = i
			z = 0
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(str, input().split()))
	k = ''.join(a)
	k = k.strip('0')
	print(k.count('0'))


from itertools import groupby
for _ in range(int(input())):
	n = input()
	a = list(map(int, input().split()))
	groups = [(k, len(list(g))) for (k, g) in groupby(a)]
	if groups[0][0] == 0:
		ans = sum([v for (_, v) in groups[2::2]])
	else:
		ans = sum([v for (_, v) in groups[1::2]])
	if groups[-1][0] == 0:
		ans -= groups[-1][1]
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	l = -1
	for i in range(n):
		if a[i] == 1:
			l = i
			break
	r = -1
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			r = i
			break
	res = 0
	for i in range(l, r + 1):
		if a[i] == 0:
			res += 1
	print(res)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	i = 0
	index = []
	while i < n:
		j = i + 1
		while arr[i] == 1 and j < n and (arr[i] == arr[j]):
			j += 1
		if arr[i] == 1:
			index.append((i + 1, j))
		i = j
	ans = 0
	for k in range(1, len(index)):
		ans += index[k][0] - index[k - 1][1] - 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	list_s = list(map(int, input().split()))
	if sum(list_s) == 1:
		print(0)
		continue
	arr = []
	for i in range(n):
		if list_s[i] == 1:
			arr.append(i)
	sum_ = 0
	for i in range(1, len(arr)):
		sum_ += arr[i] - arr[i - 1] - 1
	print(sum_)


def f():
	n = int(input())
	s = str(input().split())
	c = 0
	for i in range(s.find('1'), s.rfind('1')):
		if s[i] == '0':
			c += 1
	print(c)
t = int(input())
for i in range(t):
	f()


for _ in range(int(input())):
	n = input()
	s = input().replace(' ', '').lstrip('0').rstrip('0')
	print(s.count('0'))


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 0
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			last = i
			break
	flg = 0
	for i in range(last):
		if a[i] == 0 and flg == 0:
			continue
		else:
			flg = 1
			if a[i] == 0:
				cnt += 1
	print(cnt)


for t in range(int(input())):
	n = int(input())
	num = list(map(str, input().split()))
	num = ''.join(num)
	num = num.lstrip('0')
	num = num.rstrip('0')
	num = list(num)
	print(num.count('0'))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	p = list()
	for i in range(n):
		if a[i] == 1:
			p.append(i + 1)
	f = 1
	for i in range(len(p) - 1):
		if p[i] + 1 == p[i + 1]:
			continue
		else:
			c += p[i + 1] - p[i] - 1
	print(c)


def yabs(li):
	start = li.index('1')
	end = li.rindex('1')
	x = li[start:end + 1].count('0')
	print(x)
tc = int(input())
for i in range(tc):
	input()
	li = input()
	yabs(li)


t = int(input())
for k in range(0, t):
	n = int(input())
	lst = list((int(num) for num in input().split()))[:n]
	count = 0
	intial = -1
	final = -1
	for i in range(0, n):
		if lst[i] == 1 and intial == -1:
			intial = i
		elif lst[i] == 1:
			final = i
	if final != 0:
		for i in range(intial, final):
			if lst[i] == 0:
				count += 1
	print(count)


t = int(input())
for i in range(t):
	c = int(input())
	a = list(map(str, input().split()))
	b = ''
	for x in a:
		b += x
	b = str(int(b))
	b = str(int(b[::-1]))
	print(b.count('0'))


for k in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	pos = a.index(1)
	steps = 0
	if a.count(1) > 1:
		for i in range(pos + 1, n):
			if a[i] == 1:
				steps += i - pos - 1
				pos = i
	print(steps)


def solve(n, s):
	first = s.index('1')
	s.reverse()
	last = n - s.index('1') - 1
	s.reverse()
	zero = 0
	for i in range(first + 1, last + 1):
		if s[i] == '0':
			zero += 1
	return zero
t = int(input())
for i in range(0, t):
	print(solve(int(input()), input().split()))


for _ in range(int(input())):
	n = int(input())
	list1 = [int(i) for i in input().split()]
	while list1[0] == 0:
		del list1[0]
	while list1[-1] == 0:
		del list1[-1]
	coun = list1.count(0)
	print(coun)


t = int(input())
for i in range(t):
	n = int(input())
	s = input().replace(' ', '')
	if not '0' in s[s.find('1'):s.rfind('1') + 1]:
		print(0)
	elif not '1' in s[s.find('0'):s.rfind('0') + 1]:
		print(len(s[s.find('0'):s.rfind('0') + 1]))
	else:
		print(s[s.find('1'):s.rfind('1') + 1].count('0'))


n = int(input())
for i in range(n):
	x = int(input())
	ar = list(map(int, input().split()))
	sum = 0
	ans = []
	while x > 0:
		if ar[0] == 0:
			ar.remove(ar[0])
		else:
			x = 0
	x1 = len(ar)
	while x1 > 0:
		if ar[x1 - 1] == 0:
			ar.pop(x1 - 1)
			x1 = x1 - 1
		else:
			x1 = 0
	y = ar.count(0)
	print(y)


def f():
	n = int(input())
	arr = list(map(int, input().split()))
	arr2 = []
	f = 0
	for i in range(n):
		if arr[i] == 0 and f == 1:
			arr2.append(arr[i])
		if arr[i] == 1:
			arr2.append(arr[i])
			f = 1
	arr2 = arr2[::-1]
	arr = []
	f = 0
	for i in range(len(arr2)):
		if arr2[i] == 0 and f == 1:
			arr.append(arr2[i])
		if arr2[i] == 1:
			arr.append(arr2[i])
			f = 1
	print(arr.count(0))
for i in range(int(input())):
	f()


t = int(input())
while t:
	n = int(input())
	l = [int(x) for x in input().split()]
	for i in range(n):
		if l[i] == 1:
			break
	pos = i + 1
	c = 0
	while pos < n - 1:
		for j in range(pos, n):
			if l[j] == 1:
				break
		else:
			break
		c = c + j - pos
		pos = j + 1
	print(c)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	x = 0
	y = 0
	for j in range(0, n):
		if l[j] == 1:
			x = j
			break
	for m in range(0, n):
		if l[m] == 1:
			y = m
	for k in range(x, y):
		if l[k] == 0:
			ans = ans + 1
	print(ans)


T = int(input())
for _ in range(T):
	n = input()
	book_shelf = input().split(' ')
	gap = 0
	moves = 0
	has_books = False
	for book in book_shelf:
		if book == '0' and has_books:
			gap += 1
		elif book == '1':
			moves += gap
			gap = 0
			has_books = True
	print(moves)


t = int(input())
n = []
s = []
for i in range(t):
	n.append(int(input()))
	s.append(input().split())
s2 = []
for i in s:
	s2.append(''.join(i))

def movDer(s):
	x = 1
	cont = 0
	while x < len(s) - 1:
		cont += 1
		x += 1
	return cont
for i in s2:
	x = 0
	cont = 0
	while x < len(i) - 1:
		if i[x] == '1':
			j = 1
			while x + j < len(i) - 1 and i[x + j] == '0':
				j += 1
			if x + j < len(i) - 1:
				cont += movDer(i[x:x + j + 1])
			elif x + j == len(i) - 1 and i[x + j] == '1':
				cont += movDer(i[x:x + j + 1])
		x += 1
	print(cont)


from sys import stdin, stdout
ans = []

def main():
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	start = arr.index(1)
	end = n - arr[::-1].index(1)
	count = 0
	for item in arr[start:end]:
		if item == 0:
			count += 1
	ans.append(str(count))
	return
for i in range(int(stdin.readline())):
	main()
stdout.write('\n'.join(ans))


t = int(input())
for j in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	(s, l) = (0, n - 1)
	for ele in arr:
		if ele == 1:
			break
		s += 1
	for j in range(n - 1, -1, -1):
		if arr[j] == 1:
			break
		l -= 1
	c = 0
	for ele in arr[s:l]:
		if ele == 0:
			c += 1
	print(c)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	l = list(map(int, stdin.readline().split()))
	shan = []
	for i in range(n):
		if l[i] != 0:
			shan = l[i:]
			break
	for j in range(len(shan) - 1, -1, -1):
		if shan[j] != 0:
			shan = shan[:j + 1]
			break
	print(shan.count(0))


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	n = inp()
	a = inara()
	one = 0
	for i in range(n):
		one += a[i]
	first = 0
	for i in range(n):
		if a[i] == 1:
			first = i
			break
	last = n
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			last = i
			break
	one -= 1
	print(last - first - one)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for j in range(n):
		if a[j] == 1:
			break
	for k in range(n - 1, -1, -1):
		if a[k] == 1:
			break
	c = 0
	for l in range(j, k):
		if a[l] == 0:
			c = c + 1
	print(c)


def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	n = read_int()
	a = list(read_ints())
	l = 0
	while l < n and a[l] == 0:
		l += 1
	r = n - 1
	while r >= 0 and a[r] == 0:
		r -= 1
	if l > r:
		print(0)
		continue
	ones = sum(a[l:r + 1])
	print(r - l + 1 - ones)


for _ in range(int(input())):
	n = int(input())
	a = [x for x in map(int, input().split())]
	i = 0
	j = n - 1
	while i < j:
		if a[i] == 0:
			i += 1
		if a[j] == 0:
			j -= 1
		if a[i] == 1 and a[j] == 1:
			break
	print(a[i:j].count(0))


t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	if 1 not in l:
		print(0)
	else:
		fi = l.index(1)
		while fi < n and l[fi] != 0:
			fi += 1
		ans = 0
		while fi < n:
			inc = 0
			fl = 0
			while l[fi] != 1:
				inc += 1
				fi += 1
				if fi >= n:
					fl = 1
					break
			if fl == 1:
				break
			else:
				ans += inc
				while fi < n and l[fi] != 0:
					fi += 1
		print(ans)


for i in range(int(input())):
	n = int(input())
	l = [int(num) for num in input().split()]
	(j, c) = (0, 0)
	p = []
	for j in range(n):
		if l[j] == 1:
			p.append(j)
	if len(p) > 1:
		for k in range(len(p) - 1):
			c = c + p[k + 1] - p[k] - 1
	print(c)


t = int(input())
for y_qtr in range(t):
	n = int(input())
	s = list(map(int, input().rstrip().split()))
	a = []
	b = 0
	for i in range(n):
		if s[i] == 1:
			a.append(i)
	for j in range(0, len(a) - 1):
		c = a[j + 1] - a[j] - 1
		if c > 0:
			b = b + c
	print(b)


t = int(input())
for i10 in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	k = 0
	s = 0
	e = 0
	for i in range(n):
		if a[i] == 1:
			if e == 1:
				s += k
			e = 1
			k = 0
		else:
			k += 1
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	k = a[::-1]
	for i in range(0, n):
		if a[i] == 1:
			lim = i
			break
	for l in range(0, n):
		if k[l] == 1:
			last = l
			break
	cnt = 0
	for new in range(lim, n - last):
		if a[new] == 0:
			cnt += 1
	print(cnt)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	last = -1
	ans = 0
	for (i, v) in enumerate(a):
		if v == 1:
			if last > -1:
				ans += i - last - 1
			last = i
	print(ans)

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()

def __starting_point():
	main()
__starting_point()


T = int(input())
for t in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	s = []
	try:
		x = a[::-1].index(1)
	except ValueError:
		x = -1
	try:
		y = a.index(1)
	except ValueError:
		y = -1
	if x != -1:
		x = n - 1 - x
		if x == y:
			print('0')
		else:
			s = a[y:x]
			d = s.count(0)
			print('{}'.format(d))
	else:
		print('0')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	flag = 0
	now = 0
	ans = 0
	for i in range(len(a)):
		if a[i] == 1:
			flag = 1
			ans = now
		elif flag == 1:
			now += 1
	print(ans)


for i in range(int(input())):
	n = int(input())
	Str = input()
	a = Str.index('1')
	b = Str.rindex('1')
	new = Str[a:b + 1]
	print(new.count('0'))


for test in range(int(input())):
	n = input()
	arr = list(map(int, input().split()))
	l = []
	for i in range(len(arr)):
		if arr[i] == 1:
			l.append(i)
	if len(l) == 1 or not l:
		print(0)
		continue
	s = 0
	for i in range(1, len(l)):
		s += l[i] - l[i - 1] - 1
	print(s)


t = int(input())
natija = []
for i in range(t):
	n = int(input())
	satr = input()
	ruyhat = satr.split(' ')
	for j in range(n):
		ruyhat[j] = int(ruyhat[j])
	chap_bir = 0
	ung_bir = n - 1
	for j in range(n):
		if ruyhat[j] == 1:
			chap_bir = j
			break
	for j in range(n - 1, -1, -1):
		if ruyhat[j] == 1:
			ung_bir = j
			break
	nollar_soni = 0
	for j in range(chap_bir + 1, ung_bir):
		if ruyhat[j] == 0:
			nollar_soni += 1
	natija.append(nollar_soni)
for i in range(t):
	print(natija[i])


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	past = -1
	gaps = 0
	for i in range(n):
		if arr[i] == 1:
			if past >= 0:
				gaps += i - past - 1
				past = i
			else:
				past = i
	print(gaps)


n = int(input())
for i in range(n):
	k = int(input())
	m = input()
	m = m.replace(' ', '')
	k1 = 0
	for i in range(len(m)):
		if m[i] != '0':
			break
		else:
			k1 += 1
	k2 = 0
	for i in range(len(m) - 1, -1, -1):
		if m[i] != '0':
			break
		else:
			k2 += 1
	print(len(''.join(m.split('1'))) - k1 - k2)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	start = a.index(1)
	b = a[::-1]
	end = b.index(1)
	end = n - end - 1
	total = a.count(1)
	print(end - start + 1 - total)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	while i < len(a):
		if a[i] == 0:
			a.remove(0)
			i -= 1
		else:
			break
		i += 1
	i = len(a) - 1
	while a[i] == 0:
		a.pop(i)
		i -= 1
	ans = 0
	for i in a:
		if i == 0:
			ans += 1
		else:
			pass
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	while l:
		if l[0] == 1:
			break
		if l[0] == 0:
			l.pop(0)
	while l:
		if l[-1] == 1:
			break
		if l[-1] == 0:
			l.pop()
	p = l.count(0)
	print(p)


t = input()
t = int(t)
for tt in range(t):
	n = input()
	n = int(n)
	arr = list()
	k = input()
	arr = k.split()
	for i in range(n):
		arr[i] = int(arr[i])
	s = sum(arr)
	fpos = -1
	lpos = -1
	for i in range(n):
		if arr[i] == 1:
			lpos = i
			if fpos == -1:
				fpos = i
	print(lpos - fpos + 1 - s)


test_cases = int(input())
for _ in range(test_cases):
	n = int(input())
	a = input()
	left = a.find('1')
	right = a.rfind('1')
	if right == left:
		print(0)
	else:
		print(a.count('0', left, right))


T = int(input())
for _ in range(T):
	n = int(input())
	ls = list(map(int, input().split()))
	starting_one = -1
	endding_one = -1
	for (index, value) in enumerate(ls):
		if value == 1 and starting_one == -1:
			starting_one = index
			endding_one = starting_one
		elif value == 1:
			endding_one = index
	ans = ls[starting_one:endding_one].count(0)
	print(ans)


t = int(input())
for i in range(t):
	number = int(input())
	a = list(map(int, input().split()))
	begin = a.index(1)
	a.reverse()
	a.index(1)
	print(int(a[a.index(1):number - begin].count(0)))


import sys
input = lambda : sys.stdin.readline().rstrip()
from collections import deque
from queue import LifoQueue

def binary_search(a, n):
	L = 0
	R = len(a) - 1
	while L <= R:
		mid = L + (R - L) // 2
		if a[mid] == n:
			return mid
		elif a[mid] < n:
			L = mid + 1
		else:
			R = mid - 1
	return -1
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	zero = 0
	one = 0
	for i in a:
		if i == 1:
			one += 1
		else:
			zero += 1
	for i in range(len(a)):
		if (a[i] == 1 or i == len(a) - 1) and one:
			zero -= i
			break
	for i in range(len(a)):
		if (a[-i - 1] == 1 or i == len(a) - 1) and one:
			zero -= i
			break
	if one == 0:
		print(0)
	else:
		print(zero)


number_tests = int(input())
n = []
books = []
for i in range(number_tests):
	n.append(int(input()))
	books.append(input().split())
for i in range(len(n)):
	start_position = 0
	end_position = n[i] - 1
	total_perm = 0
	while books[i][start_position] == '0':
		start_position += 1
	while books[i][end_position] == '0':
		end_position -= 1
	for j in range(start_position, end_position + 1, 1):
		if books[i][j] == '0':
			total_perm += 1
			j += 1
		else:
			j += 1
	print(total_perm)


for _ in range(int(input())):
	n = int(input())
	arr = input().split()
	arr = ''.join(arr)
	fst = arr.index('1')
	lst = n - (arr[::-1].index('1') + 1)
	if fst == lst:
		print(0)
	else:
		print(arr[fst:lst + 1].count('0'))


def solve():
	n = int(input())
	S = input().split()
	ones = spaces = 0
	last = -1
	for (i, c) in enumerate(S):
		if ones > 0 and c == '0':
			spaces += 1
		if c == '1':
			ones += 1
			last = i
	spaces -= sum([c == '0' for c in S[last + 1:]])
	return 0 if ones == 1 else spaces
N = int(input())
for _ in range(N):
	print(solve())


import sys
input = sys.stdin.readline
from collections import defaultdict as dc
from bisect import bisect_right
import math
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = []
	c = 0
	if l[0] == 0:
		c -= 1
	else:
		c = 1
	s = 0
	for i in range(1, n):
		if l[i] == l[i - 1]:
			if l[i] == 0:
				c -= 1
			else:
				c += 1
		else:
			x.append(c)
			if l[i] == 0:
				c = -1
			else:
				c = 1
	x.append(c)
	for i in range(len(x)):
		if x[i] > 0:
			break
	for j in range(len(x) - 1, -1, -1):
		if x[j] > 0:
			break
	s = 0
	for k in range(i + 1, j):
		if x[k] < 0:
			s += abs(x[k])
	print(s)


for s in [*open(0)][2::2]:
	print(sum(map(len, s[::2].strip('0').split('1'))))


import sys
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	(pre, state, ans) = (0, 1, 0)
	for i in range(n):
		if arr[i] == 1 and state == 1:
			pre = i
			state = 0
		elif arr[i] == 1 and state == 0:
			ans += i - pre - 1
			pre = i
	print(ans)


import sys
sysinput = sys.stdin.readline
import time
start_time = time.time()

def inp():
	return int(sysinput())

def inlt():
	return list(map(int, sysinput().split()))

def insr():
	s = sysinput()
	return list(s[:len(s) - 1])

def invr():
	return map(int, sysinput().split())
t = inp()
while t > 0:
	t -= 1
	n = inp()
	a = inlt()
	flg = 0
	s = 0
	ans = 0
	for (i, num) in enumerate(a):
		if flg == 1:
			s += 1
		if num == 1:
			ans += s
			flg = 1
			s = -1
	print(ans)


a = int(input())
i = 0
while i < a:
	b = int(input())
	n1 = [int(i) for i in input().split()]
	n = ''
	for u in n1:
		n += str(u)
	i = i + 1
	n = n[n.find('1'):n.rfind('1')]
	k = len(n) - sum(n1) + 1
	print(k)


import typing

def rl(*args) -> typing.Iterable:
	(func, funcs) = (int, (int, float, str))
	(itr, itrs) = (iter, (iter, list, tuple))
	sep = ' '
	for a in args:
		if a in funcs:
			func = a
		elif a in itrs:
			itr = a
		elif isinstance(a, str):
			sep = a
	return itr(map(func, input().strip().split(sep)))
T = int(input())
while T:
	T -= 1
	n = int(input())
	xs = rl()
	total = 0
	current = 0
	counting = False
	for x in xs:
		if x == 1:
			if counting:
				total += current
				current = 0
			else:
				counting = True
		elif counting:
			current += 1
	print(total)


import itertools

def solution():
	n = int(input())
	data = input().split(' ')
	cols = itertools.groupby(data)
	to_check = False
	res = 0
	lst_group = None
	for (key, group) in cols:
		if key == '1':
			if to_check:
				res += lst_group
			else:
				to_check = True
		lst_group = len(list(group))
	return res

def main():
	T = int(input().strip())
	for t in range(1, T + 1):
		print(solution())
main()


T = int(input())
for t in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	if a.count(1) < 2:
		print(0)
		continue
	b = a[::-1]
	f = a.index(1)
	l = len(a) - b.index(1)
	print(a[f:l].count(0))


import sys
input = sys.stdin.readline

def solve():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		temp = []
		prev = 0
		for i in range(n):
			if prev != 1 or a[i] != 1:
				temp.append(a[i])
			prev = a[i]
		first_one = last_one = -1
		prev = 0
		for i in range(len(temp)):
			if temp[i] == 1 and prev != 1:
				if first_one == -1:
					first_one = i
				last_one = i
			prev = temp[i]
		print(last_one - first_one + 1 - sum(temp))
solve()


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	a = arr.index(1)
	c = arr.count(1)
	b = 0
	k = a
	m = 0
	for j in range(n):
		if arr[j] == 1:
			b = j
	while a != b - c + 1:
		for n in range(k + 1, len(arr)):
			if arr[n] == 1:
				m = m + (n - k - 1)
				a += n - k - 1
				k = n
	print(m)


for x in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	ans = 0
	count_zeros = 0
	j = n - 1
	last_one = 0
	while j > -1:
		if a[j] == 1:
			last_one = j
			break
		j -= 1
	if a.count(1) >= 2:
		while i < last_one:
			if a[i] == 1:
				ans = 1
			if a[i] == 0:
				if ans == 1:
					count_zeros += 1
			i += 1
		print(count_zeros)
	else:
		print(0)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
sys.setrecursionlimit(100000000)
ii = lambda : int(input())
si = lambda : input()
jn = lambda x, l: x.join(map(str, l))
sl = lambda : list(map(str, input().strip()))
mi = lambda : map(int, input().split())
mif = lambda : map(float, input().split())
lii = lambda : list(map(int, input().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
mod = 1000000007
for _ in range(ii()):
	n = ii()
	arr = lii()
	z = 0
	o = 0
	one = 0
	i = 0
	for ele in arr:
		if ele == 1 and one >= 1:
			one += 1
			z += abs(i - o - 1)
			o = i
		elif ele == 1:
			one += 1
			o = i
		i += 1
	print(z)


t = int(input())
for t in range(t):
	q = int(input())
	lst = list(map(int, input().split()))
	p = q1 = 0
	for i in lst:
		if q1 == 1:
			if i == 0:
				p += 1
		elif i == 1:
			q1 = 1
	for i in range(len(lst) - 1, -1, -1):
		if lst[i] == 0:
			p -= 1
		else:
			break
	print(p)


import string
loopnumber = int(input())
while loopnumber > 0:
	books = int(input())
	a = list(map(int, input().split()))
	tempshift = 0
	shift = 0
	i = 0
	while i < books:
		if a[i] == 1:
			if i == books - 1:
				break
			i += 1
			while a[i] == 0:
				tempshift += 1
				i += 1
				if i == books:
					break
			if i < books:
				if a[i] == 1:
					shift = shift + tempshift
					tempshift = 0
		else:
			i += 1
	print(shift)
	loopnumber -= 1


t = int(input())
for z in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = []
	cnt = 0
	for i in range(n):
		if a[i] == 0:
			cnt += 1
		elif i == 0 or cnt != 0:
			b.append(cnt)
			cnt = 0
	b.append(cnt)
	sm = 0
	for i in range(1, len(b) - 1):
		sm += b[i]
	print(sm)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	l = r = -1
	for i in range(n):
		if arr[i] == 1:
			l = i
			break
	for i in range(n - 1, -1, -1):
		if arr[i] == 1:
			r = i
			break
	if l == -1 or l == r:
		print(0)
	else:
		cnt = 0
		for i in range(l, r + 1):
			if arr[i] == 0:
				cnt += 1
		print(cnt)


import sys
input = sys.stdin.buffer.readline

def solution():
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	ans = 0
	while i < n and l[i] == 0:
		i += 1
	j = n - 1
	while j > 0 and l[j] == 0:
		j -= 1
	while i < j:
		while i < j and l[i] == 1:
			i += 1
		while i < j and l[i] == 0:
			ans += 1
			i += 1
	print(ans)
t = int(input())
for _ in range(t):
	solution()


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	l = []
	for i in range(n):
		if s[i] == 1:
			l.append(i)
	if len(l) == 1:
		print(0)
	else:
		sum = 0
		a = l[0]
		for i in range(1, len(l)):
			sum += l[i] - a - 1
			a = l[i]
		print(sum)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	ind = l.index(1)
	for i in range(ind + 1, n):
		if l[i] == 1:
			ans += i - ind - 1
			ind = i
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	flag = False
	while not flag:
		if a[0] == 1:
			flag = True
		else:
			a.pop(0)
	flag = False
	while not flag:
		if a[-1] == 1:
			flag = True
		else:
			a.pop(-1)
	n = len(a)
	count = 0
	for i in range(n):
		if a[i] == 0:
			count += 1
	print(count)


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	ans = 0
	c1 = sum((i == 0 for i in a))
	cb = 0
	for i in a:
		if i == 0:
			cb += 1
		if i == 1:
			break
	for i in reversed(a):
		if i == 0:
			cb += 1
		else:
			break
	print(c1 - cb)


num = int(input())
for el in range(num):
	n = int(input())
	s = input().split()
	one = False
	lastone = -1
	lastzero = -1
	count = 1
	gap = 0
	for c in s:
		if c == '0' and one:
			gap += 1
			lastzero = count
		if c == '1':
			one = True
			lastone = count
		count += 1
	if lastone == -1 or lastzero == -1:
		print(0)
	else:
		print(gap - (n - lastone))


def solve():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		l = a.index(1)
		r = n - 1 - a[::-1].index(1)
		print(a[l:r].count(0))
solve()


def solve(arr):
	l = 0
	r = len(arr) - 1
	while arr[l] == 0:
		l += 1
	while arr[r] == 0:
		r -= 1
	cnt = 0
	for v in arr[l:r + 1]:
		if not v:
			cnt += 1
	return cnt

def main():
	t = int(input())
	for q_itr in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		print(solve(arr))
main()


t = int(input())
for i in range(t):
	n = input()
	l1 = input()
	l1 = l1.replace(' ', '')
	l = l1.strip('0')
	p = l.count('0')
	print(p)


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	a = a[a.find('1'):a.rfind('1')].split()
	print(a.count('0'))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = 0
	r = n - 1
	while a[l] != 1:
		l += 1
	while a[r] != 1:
		r -= 1
	if r - l < 2:
		print(0)
		continue
	ans = 0
	for i in range(l, r):
		if a[i] == 0:
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	ch = input()
	L = ch.split()
	p = L.index('1')
	L = L[p:]
	c = L.count('1')
	while True:
		k = L.pop()
		if k == '1':
			L.append('1')
			break
	print(L.count('0'))


t = int(input())
for _ in range(t):
	n = int(input())
	a = ''.join(input().split())
	l = a.index('1')
	r = a.rindex('1')
	print(r - l + 1 - a.count('1'))


t = int(input())
polcok = []
for i in range(t):
	_ = input()
	s = input().split()
	polcok.append(s)

def kereses2(polc):
	count = 0
	for i in polc[elso(polc):utolso(polc)]:
		if i == '0':
			count += 1
	return count

def elso(polc):
	var = 0
	for (index, item) in enumerate(polc):
		if item == '1':
			return index

def utolso(polc):
	for (index, item) in enumerate(polc[::-1]):
		if item == '1':
			return len(polc) - index - 1
for polc in polcok:
	print(kereses2(polc))


from sys import stdin, stdout
n = int(stdin.readline())
for i in range(n):
	k = int(stdin.readline())
	lst = [int(i) for i in stdin.readline().split()]
	cur = 0
	s = 10 ** 100
	e = -1
	for i in lst:
		if i == 1:
			s = min(s, cur)
			e = max(e, cur)
		cur += 1
	lst2 = lst[s:e]
	stdout.write(str(lst2.count(0)) + '\n')


t = int(input())
for i in range(t):
	n = int(input())
	nums = input().split()
	achei = False
	cont = 0
	seq = 0
	for num in nums:
		if num == '1':
			achei = True
			seq = 0
		elif achei:
			cont += 1
			seq += 1
	print(cont - seq)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	c = 0
	flag = 0
	final = 0
	for i in s:
		if i == '1':
			flag = 1
		if flag == 1 and i == '0':
			c += 1
		if flag == 1 and i == '1':
			final = c
	print(final)


import sys
input = sys.stdin.readline

def solve(n, books):
	gaps = []
	nm = n - 1
	i = 0
	while i < n:
		if i < nm and books[i] == 1 and (books[i + 1] == 0):
			start = i + 1
			end = start
			while end < n and books[end] == 0:
				end += 1
			if end < n and books[end] == 1:
				gaps.append((start, end - 1))
			i = end
		else:
			i += 1
	return sum((e - s + 1 for (s, e) in gaps))
t = int(input())
for _ in range(t):
	n = int(input())
	books = list(map(int, input().split()))
	print(solve(n, books))


def minMoves(shelf):
	c = 0
	a = shelf.count(1)
	if a == 1 or a == 0:
		return 0
	else:
		x = shelf.index(1)
		for i in range(len(shelf) - 1, x, -1):
			if shelf[i] == 1:
				b = i
				break
		for j in range(x + 1, b):
			if shelf[j] == 0:
				c += 1
	return c
n = int(input())
for _ in range(n):
	m = int(input())
	statusOfShelf = list(map(int, input().split()))
	print(minMoves(statusOfShelf))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
t = int(input())
for ti in range(t):
	n = int(input())
	li = [int(i) for i in input().split()]
	f = False
	cnt = 0
	ans = 0
	for i in li:
		if i == 1:
			if f:
				ans += cnt
			cnt = 0
			f = True
		else:
			cnt += 1
	print(ans)


def swap_books(arr):
	result = []
	for shelf in arr:
		start = -1
		for i in range(0, len(shelf)):
			if shelf[i] == '1':
				start = i
				break
		end = -1
		for i in range(len(shelf) - 1, -1, -1):
			if shelf[i] == '1':
				end = i
				break
		new_shelf = shelf[start + 1:end]
		ans = 0
		for i in range(0, len(new_shelf)):
			if new_shelf[i] == '0':
				ans += 1
		result.append(ans)
	return result
t = int(input())
arr = []
res = []
for i in range(0, t):
	length = input()
	num = input()
	arr.append(num)
res = swap_books(arr)
for num in res:
	print(num)


a = int(input())
for i in range(a):
	r = int(input())
	z = list(map(int, input().split()))
	ans = []
	cnt = 1
	for i in range(1, len(z)):
		if z[i] == z[i - 1]:
			cnt += 1
		else:
			ans.append(cnt)
			cnt = 1
	ans.append(cnt)
	if z[0] == 0:
		ans.pop(0)
	if z[-1] == 0 and len(ans) > 0:
		ans.pop(len(ans) - 1)
	print(sum(ans[1::2]))


t = int(input())
for i in range(t):
	n = int(input())
	x = input()
	books = 0
	for j in range(0, len(x), 2):
		if x[j] == '1':
			books = books + 1
	begin = 0
	k = 0
	while x[k] != '1':
		begin = begin + 1
		k = k + 2
	end = 0
	m = (n - 1) * 2
	while x[m] != '1':
		end = end + 1
		m = m - 2
	print(n - books - begin - end)


a = []
t = int(input())
for i in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	if len(l) == n:
		count = 1
		for i in range(len(l)):
			if l[i] == 1:
				a.append(i)
		s = 0
		for i in range(1, len(a)):
			if a[i] - a[i - 1] > 1:
				s += a[i] - a[i - 1] - 1
		print(s)
		a.clear()


import sys
input = sys.stdin.readline
for test in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	ones = [i for (i, j) in enumerate(a) if j == 1]
	low = min(ones)
	high = max(ones)
	ans = 0
	for i in range(low, high + 1):
		if a[i] == 0:
			ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	count = 0
	moves = 0
	from_last = n
	for i in range(n - 1, -1, -1):
		if arr[i] == 1:
			break
		else:
			from_last -= 1
	if arr.count(1) == 1:
		print(0)
	else:
		for i in arr:
			if i == 1:
				break
			else:
				count += 1
		for j in range(count, from_last):
			if arr[j] == 0:
				moves += 1
		print(moves)


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = 0
	y = n - 1
	for i in range(n):
		if a[i] == 1:
			x = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			y = i
			break
	c = 0
	for i in range(x, y + 1):
		if a[i] == 0:
			c += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = [i for i in input().split()]
	a = ''.join(a)
	a = a.strip('0')
	print(a.count('0'))


import sys
import math
from math import *
from collections import Counter, defaultdict, deque
from bisect import bisect
lip = lambda : list(map(int, input().split()))
ip = lambda : int(input())
sip = lambda : input().split()
mod = 10 ** 9 + 7

def main():
	n = ip()
	arr = lip()
	s = -1
	for i in range(n):
		if arr[i] == 1:
			s = i
			break
	if s == -1:
		print(0)
		return
	for i in range(n - 1, -1, -1):
		if arr[i] == 1:
			e = i
			break
	print(arr[s:e + 1].count(0))
for i in range(ip()):
	main()


t = int(input())
for i in range(t):
	n = int(input())
	f = False
	opop = -1
	kol = 0
	op = [int(i) for i in input().split()]
	for i in range(n):
		if opop == -1 and op[i] == 1:
			opop = i
			kol += 1
		elif op[i] == 1:
			kol += 1
	popo = -1
	for i in range(n - 1, -1, -1):
		if popo == -1 and op[i] == 1:
			popo = i
	print(popo - opop - kol + 1)


for i in range(int(input())):
	a = int(input())
	b = str(input())
	b = b.replace(' ', '')
	b = b.strip('0')
	b = b.replace('1', '')
	print(len(b))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	fi = a.index(1)
	a.reverse()
	sec = n - a.index(1) - 1
	a.reverse()
	print(a[fi:sec + 1].count(0))


import bisect
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	left = 0
	for i in range(n):
		if l[i] == 1:
			left = i
			break
	right = 0
	for j in range(n - 1, -1, -1):
		if l[j] == 1:
			right = j
			break
	temp = l[left:right + 1]
	print(temp.count(0))


for _ in range(int(input())):
	n = int(input())
	string = input()
	zero = 0
	answ = 0
	is_one = False
	for i in string:
		if i == '1':
			is_one = True
			answ += zero
			zero = 0
		if i == '0' and is_one:
			zero += 1
	print(answ)


test_cases = int(input())
for i in range(test_cases):
	num = int(input())
	count = 0
	lst = list(map(str, input().split()))
	last_occurrence1 = len(lst) - 1 - lst[::-1].index('1')
	first_occurrence = lst.index('1')
	if last_occurrence1 == first_occurrence:
		print('0')
	else:
		for i in range(first_occurrence, last_occurrence1 + 1):
			if lst[i] == '0':
				count += 1
			else:
				pass
		print(count)


game = int(input())
for i in range(game):
	n = int(input())
	k = list(map(int, input().split()))
	z = sorted(k)
	initial = 0
	final = 0
	count = 0
	if z[n - 1] != z[n - 2]:
		print(0)
	else:
		for j in range(len(k) - 1, -1, -1):
			if k[j] == 1:
				final = j
				break
		for l in range(len(k)):
			if k[l] == 1:
				initial = l
				break
		for m in range(initial, final):
			if k[m] == 0:
				count += 1
		print(count)


a = int(input())
for k in range(a):
	c = int(input())
	b = list(input().split())
	s = ''
	for t in b:
		s += t
	r = s.strip('0')
	print(r.count('0'))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	for i in range(n - 1, -1, -1):
		if l[i] == 1:
			f = i
			break
	for i in range(n):
		if l[i] == 1:
			g = i
			break
	for i in range(g, f):
		if l[i] == 0:
			c += 1
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ai1 = a.index(1)
	ai2 = a[::-1].index(1)
	z = a[ai1:len(a) - ai2]
	print(z.count(0))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	idx_left = -1
	for i in range(n - 1):
		if a[i] == 1 and a[i + 1] == 0:
			idx_left = i
			break
	idx_right = -1
	for i in range(n - 1, 0, -1):
		if a[i] == 1 and a[i - 1] == 0:
			idx_right = i
			break
	if min(idx_left, idx_right) == -1:
		print(0)
	else:
		print(a[idx_left:idx_right + 1].count(0))


n = int(input())
for i in range(n):
	t = input()
	s = input()
	s = s.strip('0 ')
	print(s.count('0'))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	count = 0
	temp = 0
	latest = 0
	for (i, elem) in enumerate(arr):
		if elem == 1:
			if latest == 1:
				count += temp
			latest = arr[i]
			temp = 0
		if elem == 0:
			temp += 1
	print(count)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	n = int(inputi())
	aa = [int(a) for a in inputi().split()]
	zc = aa.count(0)
	s = aa.index(1)
	aa.reverse()
	e = aa.index(1)
	print(zc - s - e)

def main():
	t = int(inputi())
	for _ in range(t):
		solve()
main()


cases = int(input())
for _ in range(cases):
	n = int(input())
	c = list(map(int, input().split()))
	res = 0
	a = -1
	b = -1
	for i in range(len(c)):
		if c[i] == 1:
			a = i
			break
	for i in range(len(c) - 1, -1, -1):
		if c[i] == 1 and i != a:
			b = i
			break
	if a == -1 or b == -1:
		print(0)
	else:
		cnt = 0
		for i in range(a, b + 1):
			if c[i] == 0:
				cnt += 1
		print(cnt)


t = int(input())
for j in range(1, t + 1):
	S = 0
	lenX = int(input())
	x = [int(i) for i in input().split(' ')]
	while x[0] != 1:
		x = x[1:]
	while x[-1] != 1:
		x = x[:-1]
	for i in range(0, len(x)):
		if x[i] == 0:
			S += 1
	print(S)


tc = int(input())
for case in range(tc):
	input()
	array = input().split(' ')
	l = 0
	while True:
		if array[l] == '1':
			break
		else:
			l += 1
	r = len(array) - 1
	while True:
		if array[r] == '1':
			break
		else:
			r -= 1
	count = 0
	for i in array[l:r]:
		if i == '0':
			count += 1
	print(count)


from collections import Counter
from collections import OrderedDict
from collections import defaultdict
import bisect

def freq_count(mylist):
	return Counter(mylist)
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	con = 0
	for i in range(n):
		if arr[i] == 0:
			con += 1
		else:
			break
	arr = arr[con:]
	con = len(arr) - 1
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] == 0:
			con -= 1
		else:
			break
	arr = arr[:con]
	count = 0
	for i in range(len(arr)):
		if arr[i] == 0:
			count += 1
	print(count)


import math
import sys, bisect
from heapq import *
from itertools import *
from collections import *
sys.setrecursionlimit(10 ** 6)
I = lambda : int(sys.stdin.readline())
neo = lambda : map(int, sys.stdin.readline().split())
Neo = lambda : list(map(int, sys.stdin.readline().split()))
for _ in range(I()):
	n = I()
	A = Neo()
	Ans = [len(list(j)) for (_, j) in groupby(A)]
	if A[0] == 0:
		Ans = Ans[1:]
	if A[-1] == 0:
		Ans = Ans[:-1]
	Ans = Ans[1::2]
	print(sum(Ans))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	f = 0
	cnt = 0
	for i in l:
		if i == 0 and f == 0:
			continue
		if i == 0 and f == 1:
			cnt = cnt + 1
			continue
		if i == 1 and f == 0:
			f = 1
	l = l[::-1]
	for i in l:
		if i == 0:
			cnt -= 1
		if i == 1:
			break
	print(cnt)


import sys as _sys

def main():
	t = int(input())
	for i_t in range(t):
		(n,) = _read_ints()
		a = tuple(_read_ints())
		s = ''.join(map(str, a))
		s = s.strip('0')
		result = sum(map(len, s.replace('1', ' ').split()))
		print(result)

def _read_line():
	result = _sys.stdin.readline()
	assert result[-1] == '\n'
	return result[:-1]

def _read_ints():
	return map(int, _read_line().split())
main()


from sys import stdin, stdout

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		for i in range(int(R())):
			n = int(R())
			a = [int(x) for x in R().split()]
			cnt = 0
			pos = None
			for j in range(n):
				if a[j]:
					if pos != None:
						cnt += j - pos - 1
					pos = j
			ans.append(str(cnt))
		W('\n'.join(ans))
		return 0

def main():
	s = SOLVE()
	s.solve()
main()


T = int(input())
for t in range(T):
	n = int(input())
	x = [int(i) for i in input().split()]
	(i, j, ans) = (0, n - 1, 0)
	while i < n and x[i] == 0:
		i += 1
	while j >= 0 and x[j] == 0:
		j -= 1
	print(len(list(filter(lambda y: y == 0, x[i:j + 1]))))


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
from collections import *
for _ in range(ii()):
	n = ii()
	a = il()
	d = 0
	g = n
	for i in range(0, n):
		if a[i] == 1:
			s = i
			if s - g - 1 > 0:
				d = d + s - g - 1
			g = s
	print(d)


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	lis = []
	(on, ze) = (0, 0)
	for i in range(n):
		if arr[i] == 1:
			for j in range(i, n):
				if arr[j] == 0:
					on += 1
			break
	for k in range(n - 1, -1, -1):
		if arr[k] == 0:
			ze += 1
		else:
			break
	print(on - ze)


t = int(input())
for _ in range(t):
	n = int(input())
	lst = ''.join(input().split())
	lst = lst.strip('0')
	print(lst.count('0'))


for _ in range(int(input())):
	n = int(input())
	lst = input().split()
	for i in range(n):
		if lst[i] == '1':
			i1 = i
			break
	else:
		print(0)
		exit()
	for i in range(n - 1, -1, -1):
		if lst[i] == '1':
			i2 = i
			break
	else:
		print(0)
		exit()
	print(lst[i1:i2].count('0'))


def verif(array, l):
	x = 0
	for i in range(l):
		if array[i] == 1:
			x += 1
		else:
			pass
	return x

def count(array, l):
	if verif(array, l) == 1:
		return 0
	tab = []
	for i in range(l):
		if array[i] == 1:
			tab.append(i + 1)
	tab.sort()
	return tab[-1] - tab[0] - len(tab) + 1
T = int(input())
for i in range(T):
	l = int(input())
	array = list(map(int, input().split()))
	print(count(array, l))


from collections import defaultdict

class Solution:

	def __init__(self):
		pass

	def run(self):
		n = int(input())
		a = [int(x) for x in input().split()]
		groups = []
		m = []
		i = 0
		j = 0
		while i < n:
			if a[i] == 1:
				j = i + 1
				while j < n and a[j] == 1:
					j += 1
				groups.append((i, j - 1))
				m.append((i, j - 1))
				i = j + 1
			else:
				i += 1
		mid = m[int(len(m) / 2)]
		idx = groups.index(mid)
		result = 0
		left = mid[0]
		for i in range(idx - 1, -1, -1):
			result += left - groups[i][1] - 1
			left = groups[i][0]
		right = mid[1]
		for i in range(idx + 1, len(groups)):
			result += groups[i][0] - right - 1
			right = groups[i][1]
		return result
t = int(input())
s = Solution()
for i in range(t):
	print(s.run())


from collections import deque
from math import ceil, sqrt
import sys
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	j = 0
	ans = 0
	e = n - 1
	while a[j] < 1:
		j += 1
	while a[e] < 1:
		e -= 1
	while j <= e:
		if a[j] == 0:
			ans += 1
		j += 1
	print(ans)


for j in range(int(input())):
	n = int(input())
	vals = list(map(int, input().split()))
	gap = 0
	count = 0
	check = False
	for s in range(n):
		if vals[s] == 0:
			if check == True:
				count += 1
		elif check == True:
			gap += count
			count = 0
		else:
			check = True
	print(gap)


t = int(input())
b = []
for j in range(t):
	r = 0
	n = int(input())
	a = list(map(int, input().split()))
	indices = [i for (i, x) in enumerate(a) if x == 1]
	if len(indices) <= 1:
		r = 0
	else:
		d = [x - indices[k - 1] for (k, x) in enumerate(indices)][1:]
		for l in range(len(d)):
			r = r + d[l] - 1
	b.append(r)
for j in range(len(b)):
	print(b[j])


tc = int(input())
for _ in range(tc):
	n = int(input())
	lst = list(map(int, input().split()))
	cnt = 0
	f = 0
	ones = lst.count(1)
	if ones == 1:
		print(0)
	else:
		for i in range(n):
			if lst[i] == 1:
				f = 1
				ones -= 1
			elif f == 1 and ones > 0:
				cnt += 1
		print(cnt)


import sys
import math
input = sys.stdin.readline

def algo(n, arr):
	li = arr.index(1)
	ri = n - arr[::-1].index(1) - 1
	xn = arr.count(1)
	avg = (xn + 1) // 2
	t = 0
	for i in range(n):
		if arr[i] == 1:
			t += 1
		if t == avg:
			t = i
			break
	ans = 0
	j = 0
	for i in range(t - 1, li - 1, -1):
		if arr[i] == 0:
			j += 1
		if arr[i] == 1:
			ans += j
			j = 0
	j = 0
	for i in range(t + 1, ri + 1):
		if arr[i] == 0:
			j += 1
		if arr[i] == 1:
			ans += j
			j = 0
	return ans
for _ in range(int(input())):
	n = int(input().strip())
	arr = list(map(int, input().split()))
	res = algo(n, arr)
	print(res)


def find():
	l = int(input())
	n = list(map(int, input().split()))
	c = 0
	ans = 0
	flag = 0
	for i in n:
		if i == 1:
			flag = 1
			ans += c
			c = 0
		elif flag == 1 and i == 0:
			c += 1
	return ans
t = int(input())
while t > 0:
	print(find())
	t -= 1


import math
try:
	t = int(input())
	for i in range(t):
		n = int(input())
		s = list(map(int, input().split()))
		l = []
		k = 0
		while k < n:
			if s[k] == 1:
				p = k
				break
			k += 1
		k = n - 1
		while k >= 0:
			if s[k] == 1:
				p1 = n - (k + 1)
				break
			k -= 1
		var = 0
		var1 = n - 1
		while p > 0:
			del s[var]
			p -= 1
		while p1 > 0:
			del s[len(s) - 1]
			p1 -= 1
		print(s.count(0))
except:
	pass


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	prev = -1
	for i in range(len(arr)):
		if arr[i] == 1:
			if prev == -1:
				prev = i - 1
			ans += i - prev - 1
			prev = i
	print(ans)


def moves(arr):
	start = False
	count = 0
	last = None
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] == 1:
			last = i
			break
	for i in range(last):
		if arr[i] == 1 and start == False:
			start = True
		if arr[i] == 0 and start == True:
			count += 1
	return count
T = int(input())
for t in range(T):
	n = int(input())
	arr = [int(i) for i in input().split(' ')]
	print(moves(arr))


def funk(books):
	p = books.index(1)
	for i in range(0, p):
		books.pop(0)
for i in range(int(input())):
	n = int(input())
	books = list(map(int, input().split(' ')))
	funk(books)
	books.reverse()
	funk(books)
	print(books.count(0))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	flag1 = flag2 = total = cnt = 0
	for i in a:
		if i != 0:
			flag1 = 1
			if flag2:
				total += cnt
				cnt = 0
		elif i == 0 and flag1:
			flag2 = 1
			cnt += 1
	print(total)


def listRightIndex(alist, value):
	return len(alist) - alist[-1::-1].index(value) - 1
t = int(input())
for i in range(t):
	n = int(input())
	bookorder = list(map(int, input().split()))
	count = bookorder.count(1)
	ind = bookorder.index(1)
	if count == 1:
		print(0)
	else:
		ind2 = listRightIndex(bookorder, 1)
		count0 = bookorder[ind:ind2 + 1].count(0)
		print(count0)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] == 1:
			b = i
			break
	else:
		print(0)
		continue
	a.reverse()
	for i in range(n):
		if a[i] == 1:
			c = i
			break
	else:
		print(0)
		break
	ans = 0
	c = n - c
	a.reverse()
	for i in range(b, c):
		if a[i] == 0:
			ans = ans + 1
	print(ans)


def solve(lst):
	flag = False
	ret = 0
	for l in lst:
		if l < 0:
			ret += abs(l)
	if lst[0] < 0:
		ret -= abs(lst[0])
	if lst[-1] < 0:
		ret -= abs(lst[-1])
	return ret
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	groups = []
	tmp = 0
	zeros = 0
	for n in A:
		if n == 1:
			if zeros != 0:
				groups.append(zeros)
				zeros = 0
			tmp += 1
		elif n == 0:
			if tmp != 0:
				groups.append(tmp)
				tmp = 0
			zeros -= 1
	if tmp != 0:
		groups.append(tmp)
	if zeros != 0:
		groups.append(zeros)
	print(min(solve(groups), solve(groups[::-1])))


for _ in range(int(input())):
	a = 0
	b = 0
	c = 0
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(n):
		if not l[i] and a == 1:
			b += 1
		elif l[i]:
			a = 1
			c = b
	print(int(c))


n = int(input())
for i in range(n):
	k = int(input())
	a = list(map(int, input().split()))
	k = list(map(str, a))
	b = ''.join(k).split('1')
	if a[0] != 1:
		b.pop(0)
	if a[-1] != 1:
		b.pop(-1)
	b = ''.join(b)
	print(len(b))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split(' ')))
	idx = 0
	prev = arr[0]
	ans = []
	if prev == 1:
		ans.append(prev)
	else:
		while idx < len(arr) and arr[idx] == 0:
			idx += 1
	if idx == len(arr):
		print(0)
		continue
	for i in range(idx, len(arr)):
		if arr[i] != prev:
			ans.append(arr[i])
			prev = arr[i]
		elif arr[i] == 0:
			ans.append(arr[i])
	zeros = 0
	ans = ans[::-1]
	for i in range(len(ans)):
		if ans[i] == 0:
			zeros += 1
		else:
			break
	print(len([i for i in ans if i == 0]) - zeros)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = []
	c = 0
	for i in range(len(l)):
		if l[i] == 1:
			s.append(i)
	sum = 0
	for i in range(len(s) - 1):
		sum += abs(s[i] - s[i + 1]) - 1
	print(sum)


n = int(input())
t = 0
p = 0
for i in range(n):
	l = int(input())
	a = list(map(int, input().split()))
	p = a.count(1)
	t = 0
	j = 0
	while j < l - 1:
		if p == 0:
			break
		if a[j] == 1:
			p -= 1
			if a[j + 1] == 0 and p > 0:
				while a[j + 1] == 0:
					t += 1
					j += 1
		j += 1
	print(t)


import os
import sys
from io import BytesIO, IOBase
import math
from itertools import permutations
from decimal import *
getcontext().prec = 25
MOD = pow(10, 9) + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split(' ')))
	ans = 0
	z = []
	for i in range(n):
		if l[i] == 1:
			z.append(i)
	for i in range(len(z) - 1):
		ans = ans + z[i + 1] - z[i] - 1
	print(ans)


def lis():
	return [int(x) for x in input().split()]

def intt():
	return int(input())

def st():
	return str(input())
t = intt()
for i in range(t):
	n = intt()
	l = lis()
	if l.count(1) == 1:
		print(0)
	else:
		s = ''.join((str(x) for x in l))
		a = s.index('1')
		b = n - 1 - s[::-1].index('1')
		s = s[a:b + 1]
		print(s.count('0'))


def zip_sorted(a, b):
	(a, b) = zip(*sorted(zip(a, b)))
	sorted(zip(a, b), key=lambda x: x[1])
	return (a, b)
t = int(input())
for t1 in range(t):
	n = int(input())
	a = [int(n1) for n1 in input().split()]
	left = -1
	right = -1
	count = 0
	for k1 in range(len(a)):
		if a[k1] == 1:
			left = k1
			break
	for k1 in range(len(a)):
		if a[n - 1 - k1] == 1:
			right = n - 1 - k1
			break
	for k1 in range(left, right + 1):
		if a[k1] == 0:
			count = count + 1
	if left == right:
		print(0)
	else:
		print(count)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
from collections import defaultdict
sys.setrecursionlimit(300000)

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

def solve():
	n = N()
	ar = lis()
	temp = []
	c = 0
	for i in range(n):
		if ar[i] == 1 and ar[i - 1] == 0:
			temp.append(c)
			c = 0
		if ar[i] == 0:
			c += 1
	if ar[0] == 0:
		temp = temp[1:]
	print(sum(temp))
testcase(int(inp()))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	end = n - a.index(1)
	a.reverse()
	start = a.index(1)
	for i in range(start, end):
		if a[i] == 0:
			count += 1
	print(count)


for _ in range(int(input())):
	input()
	seq = ''.join(input().split())
	seq = seq.strip('0')
	print(seq.count('0'))


import sys
infile = sys.stdin
next(infile)
for line in infile:
	n = int(line)
	a = list(map(int, infile.readline().split()))
	i = 0
	cou1 = 0
	cou0 = 0
	while i < n:
		if a[i] == 1:
			while i < n:
				if a[i] == 0:
					cou0 += 1
				else:
					cou1 += 1
				i += 1
		else:
			i += 1
	if cou1 == 1:
		cou0 = 0
	j = n - 1
	temp = 0
	while a[j] != 1:
		temp += 1
		j -= 1
	if cou0 != 0:
		cou0 -= temp
	print(cou0)


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	lst = []
	for j in range(len(arr)):
		if arr[j] == 1:
			lst.append(int(j))
	cnt = val = res = 0
	for items in lst:
		cnt = cnt + 1
		if cnt > 1:
			res = res + (items - val - 1)
			val = items
		val = items
	print(res)


for i in range(int(input())):
	n = int(input())
	l = list(map(str, input().split()))
	s = ''.join(l)
	s = s.strip('0')
	print(s.count('0'))


t = int(input())
for _ in range(t):
	n = int(input())
	shelf = list(map(int, input().split()))
	moves = 0
	prev = -1
	for i in range(n):
		if shelf[i] == 1:
			if prev == -1:
				prev = i
			else:
				moves += i - prev - 1
				prev = i
	print(moves)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	for x in range(n):
		if a[x] == 1:
			break
	c = d = 0
	for y in range(x, n):
		if a[y] == 1:
			c += d
			d = 0
		else:
			d += 1
	print(c)
	t -= 1


t = int(input())
for q in range(0, t):
	n = int(input())
	a = [int(i) for i in input().split()]
	count = 0
	start1 = 0
	for i in range(0, n):
		if a[i] == 1:
			start1 = i
			break
	i = start1 + 1
	while i < n:
		if a[i] == 1:
			count += i - start1 - 1
			start1 = i
		i += 1
	print(count)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	s = s.replace(' ', '')
	print(s[s.index('1'):s.rindex('1') + 1].count('0'))


rr = lambda : input().strip()
rri = lambda : int(rr())
rrm = lambda : [int(x) for x in rr().split()]
from sys import stdin, stdout, setrecursionlimit
from math import ceil
from heapq import *

def sol():
	n = rri()
	nums = rrm()
	(i, j) = (0, n - 1)
	while nums[i] == 0:
		i += 1
	while nums[j] == 0:
		j -= 1
	tmp = nums.count(1)
	res = j - i - tmp + 1
	print(res)
	return

def main():
	T = rri()
	for t in range(1, T + 1):
		ans = sol()
main()


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] == 1:
			z = i
			break
	c = a[::-1]
	for i in range(n):
		if c[i] == 1:
			p = n - 1 - i
			break
	ans = 0
	for i in range(z, p + 1):
		if a[i] == 0:
			ans += 1
	print(ans)


n = int(input())
for i in range(n):
	a = int(input())
	A = list(map(int, input().split()))
	st = -1
	end = -1
	for j in range(len(A)):
		if A[j] == 1:
			if end == -1:
				st = j
			end = j + 1
	A = A[st:end]
	o = 0
	for el in A:
		if el == 0:
			o += 1
	print(o)


import math
import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] == 1:
			l = i - 1
			break
	a = a[::-1]
	for i in range(n):
		if a[i] == 1:
			r = n - i - 1
			break
	a = a[::-1]
	ans = 0
	for i in range(l + 1, r + 1):
		if a[i] == 0:
			ans += 1
	print(ans)


t = int(input())
while t:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	c = a.count(1)
	if c == 1:
		print(0)
	else:
		d = 0
		for i in range(n):
			if a[i] == 1:
				j = i
				break
		for i in range(j, n):
			if a[i] == 1:
				c = c - 1
			else:
				d = d + 1
			if c == 0:
				break
		print(d)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	a = l.index(1)
	b = n - l[::-1].index(1) - 1
	zero = 0
	for j in range(a + 1, b):
		if l[j] == 0:
			zero += 1
	print(zero)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	i1 = 0
	i2 = len(a) - 1
	while i1 < n:
		if a[i1] == 1:
			break
		i1 += 1
	while i2 < n:
		if a[i2] == 1:
			break
		i2 -= 1
	a1 = a[i1:i2 + 1]
	print(a1.count(0))


for t in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	s = a.index(1)
	e = len(a) - a[::-1].index(1) - 1
	count = 0
	for i in range(s, e + 1):
		if a[i] == 0:
			count += 1
	print(count)


t = int(input())
for tc in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	st = 0
	for i in range(n):
		if arr[i] == 1:
			st = i
			break
	ed = 0
	for i in range(n):
		if arr[i] == 1:
			ed = i
	ans = 0
	for i in range(st, ed + 1):
		if arr[i] == 0:
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	l = []
	i = 0
	j = 0
	while i < n and j < n:
		if arr[i] == 0:
			i = i + 1
			j = j + 1
		else:
			while j < n and arr[j] == 1:
				j = j + 1
			l.append((i, j - 1))
			i = j
	x = len(l)
	cnt = 0
	for i in range(x - 1):
		cnt = cnt + (l[i + 1][0] - l[i][1] - 1)
	print(cnt)


t = int(input())
for i in range(t):
	totalLen = int(input())
	totalArr = list(map(int, input().split()))
	firstCo = -1
	firstPos = totalArr.index(1)
	lastPos = len(totalArr) - 1 - totalArr[::-1].index(1)
	co = 0
	if firstPos == lastPos:
		print(0)
		continue
	for i in range(firstPos, lastPos + 1, 1):
		if firstCo == 1 and totalArr[i] == 0:
			co += 1
		if totalArr[i] == 1:
			firstCo = 1
	print(co)


from sys import stdin, stdout
input = stdin.readline
from collections import defaultdict as dd
import math

def geti():
	return map(int, input().strip().split())

def getl():
	return list(map(int, input().strip().split()))

def gets():
	return input()

def geta():
	return int(input())

def print_s(s):
	stdout.write(s + '\n')

def solve():
	for _ in range(geta()):
		n = geta()
		a = getl()
		count = 0
		first = -1
		last = -1
		for i in range(n):
			if a[i] == 1 and first == -1:
				first = i
			if a[i] == 1:
				last = i
		for j in range(first + 1, last):
			if a[j] == 0:
				count += 1
			if a[j] == 1:
				ok = True
		print(count)
solve()


for _ in ' ' * int(input()):
	input()
	s = ''.join(input().split())
	print(s[s.find('1'):s.rfind('1')].count('0'))


for _ in range(int(input())):
	n = int(input())
	s = [str(x) for x in input().split()]
	l = []
	c = 0
	j = 0
	for i in s:
		if i == '1':
			j += 1
		if j == 2:
			l.append(c)
			j = 1
			c = 0
		if j == 1 and i == '0':
			c += 1
	print(sum(l))


for tt in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	while l[i] != 1:
		i += 1
	j = n - 1
	while l[j] != 1:
		j -= 1
	cnt = 0
	for k in range(i, j):
		if l[k] == 0:
			cnt += 1
	print(cnt)


def solve(n, l):
	for i in range(n):
		if l[i] == 1:
			break
	for j in range(n - 1, -1, -1):
		if l[j] == 1:
			break
	return l[i:j + 1].count(0)
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	print(solve(n, l))


a = int(input())
for k in range(a):
	b = int(input())
	c = [int(i) for i in input().split()]
	i = 0
	j = 1
	ans = 0
	while c[-1] == 0:
		c.pop()
	if len(c) == 1:
		print(0)
	else:
		while i < len(c) - 1:
			if c[i] == 1 and c[j] == 0:
				j += 1
				ans += 1
			else:
				i += 1
				j = i + 1
		print(ans)


import sys
try:
	import os
	f = open('input.txt', 'r')
	sys.stdin = f
except FileNotFoundError:
	None
from math import sqrt, ceil
input = lambda : sys.stdin.readline().strip()
o = int(input())
for _ in range(o):
	n = int(input())
	A = list(map(int, input().split()))
	dou = -1
	las = -1
	for i in range(n):
		if dou == -1 and A[i] == 1:
			dou = i
		if A[i] == 1:
			las = i
	l = A[dou:las + 1]
	print(l.count(0))


n = int(input())
for _ in range(n):
	a = int(input())
	shelf = input().split()
	count = 0
	cur = 0
	edge = False
	for book in shelf:
		if book == '1':
			edge = True
			count += cur
			cur = 0
		if book == '0' and edge:
			cur += 1
	print(count)


def f(arr, n):
	l = arr.index(1)
	r = n - list(reversed(a)).index(1)
	return arr[l:r].count(0)
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(f(a, n))


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	while a[0] == 0:
		del a[0]
	while a[-1] == 0:
		del a[-1]
	print(a.count(0))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split(' ')))
	cnt = 0
	res = 0
	last = -1
	for i in range(n):
		if a[i] == 1:
			if last != -1:
				res += cnt
			cnt = 0
			last = i
		else:
			cnt += 1
	print(res)


t = int(input())
i = 0
while i < t:
	n = int(input())
	x = list(map(int, input().split()))
	answer = 0
	index = 0
	valid = 0
	last_null = 0
	while index < n:
		if x[index] == 1:
			valid = 1
			last_null = 0
		if x[index] == 0 and valid:
			answer += 1
			last_null += 1
		index += 1
	print(answer - last_null)
	i += 1


import sys
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def print(x):
	sys.stdout.write(str(x) + '\n')
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	ans = 0
	flag = 0
	for j in range(n):
		if a[j] == 0:
			c += 1
		else:
			if flag == 1:
				ans += c
			c = 0
			flag = 1
	print(ans)


def bookshelf(A):
	a = ''.join((i for i in A))
	a = a.replace('0', ' ').strip()
	a = a.replace(' ', '0')
	return a.count('0')
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(str, input().split()))
	res = bookshelf(A)
	print(res)


for t in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l2 = l[::-1]
	z = l.count(0)
	ans = 0
	for i in range(n):
		if l[i] == 0:
			ans += 1
		else:
			break
	for i in range(n):
		if l2[i] == 0:
			ans += 1
		else:
			break
	print(z - ans)


for _ in range(int(input())):
	n = int(input())
	s = ''.join([i for i in input().split()])
	min_idx = 0
	max_idx = 0
	result = 0
	for i in range(n):
		if s[i] == '1':
			min_idx = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			max_idx = i
			break
	for i in range(min_idx, max_idx):
		if s[i] == '0':
			result += 1
	print(result)


import math
T = int(input())
for t in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	d = False
	s = False
	cum = [0] * n
	for i in range(n):
		if not s and a[i]:
			s = True
		elif s and (not a[i]):
			cum[i] = cum[i - 1] + 1
		elif s:
			cum[i] = cum[i - 1]
	s = False
	cum2 = [0] * n
	ans = [0] * n
	for i in range(n - 1, -1, -1):
		if not s and a[i]:
			s = True
		elif s and (not a[i]):
			cum2[i] = cum2[i + 1] + 1
		elif s:
			cum2[i] = cum2[i + 1]
		ans[i] = cum2[i] + cum[i]
	print(min(ans))


test_cases = range(int(input()))
for test_case in test_cases:
	n = int(input())
	books = list(map(int, input().split()))
	while books[-1] == 0:
		books.pop(-1)
	books.reverse()
	while books[-1] == 0:
		books.pop(-1)
	print(books.count(0))


t = int(input())
while t:
	n = int(input())
	nl = list(map(int, input().split()))
	ans = 0
	flag = False
	start = False
	end = False
	(s, e) = (0, 0)
	for j in range(n):
		if start:
			break
		elif nl[j] == 1:
			start = True
			s = j
	nl.reverse()
	for k in range(n):
		if end:
			break
		elif nl[k] == 1:
			end = True
			e = n - k
	nl.reverse()
	for i in range(s, e):
		if nl[i] == 0:
			flag = True
		else:
			flag = False
		if flag:
			ans += 1
	print(ans)
	t -= 1


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = []
	z = 0
	i2 = -1
	if l[0] == 1:
		l1.append(0)
		i2 = 1
	else:
		z = 1
	for j in l[1:]:
		if j == 0:
			z = z + 1
		elif j == 1:
			if z != 0:
				l1.append(z)
				z = 0
				l1.append(0)
				i2 = len(l1)
	if i2 != -1:
		print(sum(l1[l1.index(0):i2]))
	else:
		print(0)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = k = inc = 0
	for i in range(n):
		if a[i]:
			ans += k
			k = 0
		else:
			k += inc
		inc |= a[i]
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	cnt = 0
	ans = 0
	for i in arr:
		if i == 1 and cnt == 0:
			cnt += 1
		elif i == 0 and cnt + ans > 0:
			cnt += 1
		elif i == 1:
			ans += cnt - 1
			cnt = 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	s = s.split()
	j = 0
	k = 0
	e = 0
	while j <= len(s) - 1:
		if s[j] == '1':
			j = j + 1
			while j <= len(s) - 1 and s[j] != '1':
				k = k + 1
				j = j + 1
			if j <= len(s) - 1 and s[j] == '1':
				e = e + k
				k = 0
		else:
			j = j + 1
	print(e)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	line = input().split(' ')
	previous = -1
	count = 0
	for i in range(0, n):
		if line[i] == '1':
			if previous == -1:
				previous = i
				continue
			count += i - previous - 1
			previous = i
	print(count)


import sys, os.path
from collections import *
from heapq import *
from copy import *
import math
mod = 10 ** 9 + 7
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a.count(1) == 1:
		print(0)
	else:
		c = 0
		res = []
		for i in range(n):
			if a[i] == 1:
				res.append(i + 1)
		n1 = len(res)
		for i in range(1, n1):
			c += res[i] - res[i - 1] - 1
		print(c)


t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	p = q = 0
	for i in range(len(a)):
		if a[i] == 1:
			p = i
			break
	for j in range(len(a) - 1, -1, -1):
		if a[j] == 1:
			q = j
			break
	b = a[p:q + 1]
	for i in b:
		if i == 0:
			c += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a.count(1) == 0 or a.count(1) == 1 or a.count(1) == n:
		print(0)
		continue
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			p = i
			break
	for i in range(0, n):
		if a[i] == 1:
			np = i
			break
	ans = 0
	for i in range(np, p):
		if a[i] == 0:
			ans = ans + 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(arr[arr.index(1):n - arr[::-1].index(1)].count(0))


t = int(input())
for _ in range(t):
	n = int(input())
	inp = list(map(int, input().split()))
	ans = 0
	for i in range(len(inp)):
		if inp[i] == 1:
			break
	start = i
	k = 0
	for i in range(start, len(inp)):
		if inp[i] == 0:
			k += 1
		else:
			ans += k
			k = 0
	print(ans)


t = int(input())
f = 0
e = []
for i in range(t):
	p = int(input())
	a = list(map(int, input().split(' ')))
	b = [a[0]]
	c = [a[-1]]
	for j in range(1, len(a)):
		b.append(b[j - 1] + a[j])
		c.append(c[j - 1] + a[p - 1 - j])
	c.reverse()
	for j in range(p):
		if b[j] != 0 and c[j] != 0 and (a[j] == 0):
			f += 1
	e.append(f)
	f = 0
for i in range(len(e)):
	print(e[i])


import os
import sys
from math import *
from collections import *
from fractions import *
from heapq import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	a = array()
	i = 0
	while i < n and a[i] == 0:
		i += 1
	a = a[i:]
	j = len(a) - 1
	while j >= 0 and a[j] == 0:
		j -= 1
	a = a[:j + 1]
	print(a.count(0))


for _ in range(int(input())):
	am = int(input())
	arr = list(map(int, input().split()))
	fl = False
	l = 0
	r = am
	for i in range(am):
		if arr[i] == 1:
			l = i
			break
	for i in range(am - 1, -1, -1):
		if arr[i] == 1:
			r = i
			break
	print(arr[l:r].count(0))


from sys import stdin, stdout
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = 0
	ans = 0
	p = -1
	for i in range(n):
		if a[i]:
			p = i
	for i in range(n):
		if i == p:
			break
		if a[i]:
			b = 1
		if b and a[i] == 0:
			ans += 1
	print(ans)


import re
t = int(input())
for _ in range(t):
	n = int(input())
	cnt = 0
	c = list(map(int, input().rstrip().split()))
	for i in range(len(c)):
		c[i] = str(c[i])
	s = ''.join(c)
	r = re.findall('1.+1', s)
	if len(r) == 0:
		print(cnt)
	if len(r) == 1:
		q = str(r[0])
		for j in range(len(q)):
			if q[j] == '0':
				cnt += 1
		print(cnt)


t = int(input())
for i in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	count = 0
	for k in range(len(l)):
		if l[k] == 1:
			start = k
			break
	for k in range(len(l) - 1, -1, -1):
		if l[k] == 1:
			end = k
			break
	for k in range(start, end):
		if l[k] == 0:
			count += 1
	print(count)


for i in range(0, int(input())):
	n = int(input())
	k = list(map(int, input().split()))
	p = k.count(0)
	q = k.index(1)
	k.reverse()
	r = k.index(1)
	print(p - q - r)


t = int(input())
for i in range(t):
	x = int(input())
	l = list(map(int, input().split()))
	s = 0
	r = 0
	for i in range(x):
		if l[i] == 1:
			break
		r += 1
	l = l[r:]
	x = len(l)
	for i in range(1, x + 1):
		if l[-i] == 1:
			break
		s += 1
	if s != 0:
		l = l[:-s]
	print(l.count(0))


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()[::2]
	count = 0
	flag = 0
	for i in range(len(a)):
		if a[i] == '0' and flag == 1:
			count += 1
		if a[i] == '1':
			if '1' in a[i + 1:]:
				flag = 1
			else:
				flag = 0
	print(count)


import math

def dtb(n):
	return bin(n).replace('0b', '')

def btd(n):
	return int(n, 2)
t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))[:n]
	i = 0
	count = 0
	(x, y) = (0, 0)
	for i in range(n):
		if a[i] == 1:
			x = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			y = i
			break
	for i in range(x, y):
		if a[i] == 0:
			count += 1
	print(count)


test_case = int(input())
for _ in range(test_case):
	n = int(input())
	a = list(map(int, input().split()))
	(first, last) = (-1, -1)
	for i in range(n):
		if a[i] == 1:
			first = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			last = i
			break
	print(a[first:last + 1].count(0))


for _ in range(int(input())):
	n = int(input())
	list1 = [int(x) for x in input().split()]
	total = 0
	for i in range(n):
		if list1[i] == 1:
			count = 0
			flag = 0
			for j in range(i + 1, n):
				if list1[j] == 1:
					flag = 1
					break
				else:
					count += 1
			if flag == 1:
				total += count
	print(total)


def apt(n, arr):
	moves = 0
	temp = 0
	Found = False
	for i in range(n):
		if arr[i] == 1:
			Found = True
		if i == 0:
			continue
		elif arr[i] == 1 and arr[i - 1] == 0:
			moves += temp
			temp = 0
		elif arr[i] == 0 and Found:
			temp += 1
	return moves
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(apt(n, arr))


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()

def RLE(s):
	cc = []
	ww = []
	pc = s[0]
	w = 0
	for c in s:
		if c == pc:
			w += 1
		else:
			cc.append(pc)
			ww.append(w)
			w = 1
			pc = c
	cc.append(pc)
	ww.append(w)
	return (cc, ww)
for _ in range(II()):
	n = II()
	aa = LI()
	(cc, ww) = RLE(aa)
	m = len(cc)
	si = 1 if cc[0] else 2
	ei = m - 1 if cc[-1] else m - 2
	ans = sum(ww[si:ei:2])
	print(ans)


def solver(arr, n):

	def iscontiguous():
		(i, j) = (0, 0)
		while i < n:
			if arr[i] == 1:
				j = i
				break
			i += 1
		while i < n and arr[i] == 1:
			i += 1
		k = i
		while i < n:
			if arr[i] == 1:
				return [False, j, k]
			i += 1
		return [True, 0, 0]

	def shift(i, j):
		if j == n:
			return
		temp = arr[i]
		arr[i] = 0
		for k in range(i, j):
			x = arr[k + 1]
			arr[k + 1] = temp
			temp = x
	ops = 0
	while True:
		(x, i, j) = iscontiguous()
		if x:
			return ops
		ops += 1
		shift(i, j)
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solver(arr, n))


import sys
from math import gcd, sqrt, ceil, log2
from collections import defaultdict, Counter, deque
from bisect import bisect_left, bisect_right
import math
import heapq
from itertools import permutations
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def get_sum(bit, i):
	s = 0
	i += 1
	while i > 0:
		s += bit[i]
		i -= i & -i
	return s

def update(bit, n, i, v):
	i += 1
	while i <= n:
		bit[i] += v
		i += i & -i

def modInverse(b, m):
	g = math.gcd(b, m)
	if g != 1:
		return -1
	else:
		return pow(b, m - 2, m)

def primeFactors(n):
	sa = set()
	sa.add(n)
	while n % 2 == 0:
		sa.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			sa.add(i)
			n = n // i
	return sa

def seive(n):
	pri = [True] * (n + 1)
	p = 2
	while p * p <= n:
		if pri[p] == True:
			for i in range(p * p, n + 1, p):
				pri[i] = False
		p += 1
	return pri

def check_prim(n):
	if n < 0:
		return False
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def getZarr(string, z):
	n = len(string)
	(l, r, k) = (0, 0, 0)
	for i in range(1, n):
		if i > r:
			(l, r) = (i, i)
			while r < n and string[r - l] == string[r]:
				r += 1
			z[i] = r - l
			r -= 1
		else:
			k = i - l
			if z[k] < r - i + 1:
				z[i] = z[k]
			else:
				l = i
				while r < n and string[r - l] == string[r]:
					r += 1
				z[i] = r - l
				r -= 1

def search(text, pattern):
	concat = pattern + '$' + text
	l = len(concat)
	z = [0] * l
	getZarr(concat, z)
	ha = []
	for i in range(l):
		if z[i] == len(pattern):
			ha.append(i - len(pattern) - 1)
	return ha

def mergeIntervals(arr):
	arr.sort(key=lambda x: x[0])
	m = []
	s = -10000
	max = -100000
	for i in range(len(arr)):
		a = arr[i]
		if a[0] > max:
			if i != 0:
				m.append([s, max])
			max = a[1]
			s = a[0]
		elif a[1] >= max:
			max = a[1]
	if max != -100000 and [s, max] not in m:
		m.append([s, max])
	return m
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	la = []
	while i < n:
		cnt = 0
		z = l[i]
		while i < n and l[i] == z:
			cnt += 1
			i += 1
		la.append([z, cnt])
	i = 0
	st = -1
	end = -1
	ans = 0
	for i in range(len(la)):
		if la[i][0] == 1:
			st = i
			break
	for i in range(len(la) - 1, -1, -1):
		if la[i][0] == 1:
			end = i
			break
	for i in range(st, end + 1):
		if la[i][0] == 0:
			ans += la[i][1]
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	books = [int(x) for x in input().split()]
	zeros = 0
	for i in books:
		if i == 0:
			zeros += 1
	count = 0
	index = 0
	while books[index] == 0:
		count += 1
		index += 1
	index = len(books) - 1
	while books[index] == 0:
		index -= 1
		count += 1
	print(zeros - count)


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	L = list(map(int, input().split()))
	flag = 0
	cnt = 0
	ans = 0
	for i in range(n):
		if L[i] == 1 and flag == 0:
			flag = 1
		elif L[i] == 0 and flag == 1:
			cnt += 1
		elif L[i] == 1 and flag == 1:
			ans += cnt
			cnt = 0
	print(ans)
for _ in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if 1 not in a or 0 not in a:
		print(0)
		continue
	ans = 0
	i = 0
	flag = False
	one = a.count(1)
	while i < n and one:
		if a[i] == 1:
			flag = True
			while i < n and a[i] == 1:
				i += 1
				one -= 1
		else:
			if flag:
				ans += 1
			i += 1
	print(ans)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from collections import Counter
from bisect import bisect_left
import sys
from queue import PriorityQueue
import operator as op
from functools import reduce
mod = 1000000007

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())

def printIn(ob):
	return stdout.write(str(ob) + '\n')

def powerLL(n, p):
	result = 1
	while p:
		if p & 1:
			result = result * n % mod
		p = int(p / 2)
		n = n * n % mod
	return result

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def isPrime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def rindex(mylist, myvalue):
	return len(mylist) - mylist[::-1].index(myvalue) - 1

def myCode():
	n = int(input())
	s = input()
	print(s[s.index('1'):s.rindex('1')].count('0'))

def main():
	for t in range(I()):
		myCode()
main()


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	s = ''.join((str(e) for e in a))
	s = s.strip('0')
	print(s.count('0'))


for _ in range(int(input())):
	n = int(input())
	l = [int(i) for i in input().split()]
	(ans, first, last) = (0, False, False)
	for i in range(n):
		if l[i] == 1:
			a = i
			first = True
			break
	for i in reversed(range(n)):
		if l[i] == 1:
			b = i
			last = True
			break
	if first and last:
		for i in range(a, b):
			if l[i] == 0:
				ans += 1
	print(ans)


def check(shelf):
	open = False
	count = result = 0
	for item in shelf:
		if item == 1 and (not open):
			open = True
		elif item == 0 and open:
			count += 1
		elif item == 1 and open:
			result += count
			count = 0
	return result
n = int(input())
for _ in range(n):
	__ = int(input())
	print(check(list(map(int, input().split()))))


def solve(n, arr):
	first = -1
	last = -1
	res = 0
	for i in range(0, n):
		if arr[i] != 1:
			continue
		if first == -1:
			first = i
		last = i
	for i in range(first, last + 1):
		if arr[i] == 0:
			res += 1
	return res
t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	print(solve(n, arr))


for j in range(int(input())):
	a = int(input())
	l = [int(x) for x in input().split()]
	p = []
	m = []
	v = 0
	for i in range(len(l)):
		if l[i] == 1:
			m.append(i)
			v = v + 1
		else:
			if v > 0:
				p.append(m)
			v = 0
			m = []
	if v > 0:
		p.append(m)
	v = 0
	for t in range(len(p) - 1):
		y = p[t + 1][0] - p[t][-1] - 1
		v = v + y
	print(v)


T = int(input())
for _ in range(T):
	n = int(input())
	s = input().split()
	l = [int(x) for x in s]
	if l.count(1) <= 1:
		print(0)
	else:
		print(l[l.index(1):len(l) - l.copy()[::-1].index(1)].count(0))


for _ in range(int(input())):
	t = int(input())
	l = [int(i) for i in input().split(' ')]
	i = 0
	while l[i] == 0:
		i += 1
	s = i
	i = len(l) - 1
	while l[i] == 0:
		i -= 1
	e = i + 1
	print(l[s:e].count(0))


query = int(input())
while query > 0:
	n = int(input())
	a = input()
	a = a.replace(' ', '').strip('0').count('0')
	print(a)
	query -= 1


t = int(input())
for ggwp in range(t):
	a = int(input())
	b = list(map(int, input().split()))
	count = 0
	el = 0
	for i in range(a):
		if b[i] == 1:
			el = i
			break
	for j in range(el + 1, a):
		if b[j] == 1:
			count += j - el - 1
			el = j
	print(count)


def printanswer(k, bookshelf):
	gaps = 0
	hadBook = False
	consGaps = 0
	for (i, book) in enumerate(bookshelf):
		if book and (not hadBook):
			hadBook = True
			consGaps = 0
		elif book:
			if i > 0 and (not bookshelf[i - 1]):
				gaps += consGaps
			consGaps = 0
		elif not book:
			consGaps += 1
	print(gaps)
n = int(input())
for _ in range(n):
	k = input()
	bookshelf = list(map(int, input().split()))
	printanswer(k, bookshelf)


for t in range(int(input())):
	input()
	x = str(input())
	x = x.replace(' ', '')
	res = 0
	uns = x.count('1')
	p_uns = [i for i in range(len(x)) if x.startswith('1', i)]
	for i in range(len(p_uns)):
		if i + 1 < len(p_uns) and p_uns[i] + 1 != p_uns[i + 1]:
			res += p_uns[i] + 1 - p_uns[i + 1]
	res = abs(res)
	print(res)


for test in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	li = []
	(l, r) = (0, 0)
	while l < n:
		r = l
		while r < n and a[l] == a[r]:
			r += 1
		if a[l] == 1:
			li.append((l, r - 1))
		l = r
	ans = n + n
	for (l, r) in li:
		t = 0
		for x in range(li[0][1] + 1, li[-1][0]):
			t += 1 if a[x] == 0 else 0
		ans = min(ans, t)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(input().split())
	print(l[l.index('1'):n - l[::-1].index('1') - 1].count('0'))


for _ in range(int(input())):
	n = int(input())
	s = [int(i) for i in input().split()]
	r = 0
	c = -1
	for i in s:
		if i == 1:
			r += c if c != -1 else 0
			c = 0
		elif c != -1:
			c += 1
	print(r)


t = int(input())
for _ in range(t):
	n = int(input())
	lst = input().split()
	cnt = 0
	ls = 0
	st = False
	for i in range(n - 1, 0, -1):
		if lst[i] == '1':
			ls = i
			break
	for i in range(n):
		if i == ls:
			break
		if st:
			if lst[i] == '0':
				cnt += 1
		elif lst[i] == '1':
			st = True
	print(cnt)


t = int(input())
while t:
	t -= 1
	r = int(input()) - 1
	s = list(map(int, input().strip().split()))
	if sum(s) <= 1:
		print('0')
		continue
	l = 0
	while l < r and s[l] == 0:
		l += 1
	while l < r and s[r] == 0:
		r -= 1
	ans = 0
	for i in range(l, r + 1):
		if s[i] == 0:
			ans += 1
	print(ans)


t1 = int(input())
for hi in range(t1):
	n = int(input())
	l = 0
	p = 0
	a = list(map(int, input().split()))
	o = False
	for i in a:
		if i == 0:
			p += 1
		if i == 1 and o == False:
			o = True
			p = 0
		if i == 1 and o:
			l += p
			p = 0
	print(l)


T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	moves = 0
	encountered_first_1 = False
	temp_count = 0
	for i in range(n):
		if not encountered_first_1 and A[i] == 1:
			encountered_first_1 = True
		elif encountered_first_1 and A[i] == 1:
			moves += temp_count
			temp_count = 0
		elif encountered_first_1 and A[i] == 0:
			temp_count += 1
	print(moves)


def sol(l, n):
	if sum(l) == 0:
		return 0
	ans = []
	z = 0
	cond = False
	for i in range(n):
		if l[i] == 1 and cond:
			ans.append(z)
			z = 0
			cond = False
		elif l[i] == 0:
			z += 1
			cond = True
	if not l[-1]:
		ans.append(z)
	if l[0] == l[-1]:
		if l[0] == 1:
			return sum(ans)
		elif len(ans) < 3:
			return 0
		else:
			return sum(ans[1:-1])
	elif l[-1] == 0:
		return sum(ans[:-1])
	else:
		return sum(ans[1:])
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(sol(l, n))


t = int(input())
for j in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	i1 = -1
	i2 = -1
	for i in range(n):
		if a[i] == 1:
			i1 = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			i2 = i
			break
	k = 0
	for i in range(i1, i2):
		if a[i] == 0:
			k += 1
	print(k)


from itertools import groupby
t = int(input())
for _ in range(0, t):
	n = int(input())
	aa = [int(i) for i in input().split()]
	gbb = [list(g) for (s, g) in groupby(aa)]
	ans = 0
	if len(gbb) == 1 or len(gbb) == 2:
		ans = 0
	elif gbb[0][0] == 1:
		for i in range(1, len(gbb) - 1, 2):
			ans += len(gbb[i])
	else:
		for i in range(2, len(gbb) - 1, 2):
			ans += len(gbb[i])
	print(ans)


for i in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	(fir, sec) = (-1, -1)
	cnt = 0
	lastC = -1
	for i in range(n):
		if li[i] == 1 and fir == -1:
			fir = i
		elif li[i] == 1:
			sec = i
	for i in range(n):
		if fir < i < sec:
			if li[i] == 0:
				cnt += 1
	if sec != -1:
		print(cnt)
	else:
		print(0)


t = int(input())
for _ in range(t):
	n = list(input())
	xs = list(map(int, input().split()))
	result = []
	for (ind, x) in enumerate(xs):
		if x == 1:
			result.append(ind + 1)
	print(sum([y - x - 1 for (x, y) in zip(result, result[1:])]))


t = int(input())
while t:
	t -= 1
	n = input()
	a = [int(i) for i in input().split()]
	fb = -1
	lb = -1
	c = 0
	for i in range(len(a)):
		if a[i] == 1:
			if fb == -1:
				fb = i
			lb = i
			c += 1
	print(lb - fb - c + 1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
readint = lambda : int(sys.stdin.readline().rstrip('\r\n'))
readints = lambda : map(int, sys.stdin.readline().rstrip('\r\n').split())
readstr = lambda : sys.stdin.readline().rstrip('\r\n')
readstrs = lambda : map(str, sys.stdin.readline().rstrip('\r\n').split())
readarri = lambda : [int(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]
readarrs = lambda : [str(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]

def main():
	for _ in range(readint()):
		n = readint()
		arr = readarri()
		if arr.count(1) <= 1:
			print(0)
		else:
			for i in range(n):
				if arr[i]:
					f = i
					break
			for i in range(n - 1, -1, -1):
				if arr[i]:
					l = i
					break
			ans = 0
			for i in range(f, l + 1):
				if arr[i] == 0:
					ans += 1
			print(ans)
main()


for _ in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	zo = []
	for i in range(n):
		if b[i] == 1:
			zo.append(i)
	if zo == []:
		print(0)
	else:
		res = 0
		for i in range(1, len(zo)):
			res += zo[i] - zo[i - 1] - 1
		print(res)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = []
	for i in range(n):
		if a[i]:
			d.append(i)
	print(d[-1] - d[0] - len(d) + 1)


for t__ in range(int(input())):
	n = int(input())
	s = input()
	print(s[s.index('1'):s.rindex('1')].count('0'))


import sys
import math as m

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans
mod = int(1000000000.0) + 7

def sinp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

def ninp():
	return map(int, sys.stdin.readline().strip().split())

def llinp():
	return list(map(int, sys.stdin.readline().strip().split()))

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
for _ in range(iinp()):
	n = iinp()
	a = llinp()
	flag = 0
	ans = 0
	cnt = 0
	for c in a:
		if flag == 0 and c == 0:
			pass
		elif flag == 0 and c == 1:
			flag = 1
		elif flag == 1 and c == 0:
			cnt += 1
			flag = 2
		elif flag == 1 and c == 1:
			pass
		elif flag == 2 and c == 0:
			cnt += 1
		elif flag == 2 and c == 1:
			ans = ans + cnt
			cnt = 0
			flag = 1
	print(ans)


for j in range(int(input())):
	m = int(input())
	l = list(map(int, input().split()))
	p = []
	c = 0
	d = 0
	for i in range(m):
		if l[i] == 1:
			if d == 0:
				p.append(i)
				d += 1
			else:
				y = i - p[-1] - 1
				c += y
				p.append(i)
				d += 1
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	if l.count(1) == 1:
		print(0)
	else:
		f_ind = l.index(1)
		for i in range(f_ind, len(l)):
			if l[i] == 1:
				x = i
		l_ind = x
		k = l[f_ind:l_ind + 1]
		tot = k.count(0)
		print(tot)


t = int(input())
ans_sp = []

def obrabotka(sp):
	count = 0
	for i in range(1, len(sp)):
		if sp[i] == 0 and sum(sp[:i]) > 0 and (sum(sp[i + 1:]) > 0):
			count += 1
	return count
for i in range(t):
	x = int(input())
	l_x = list(map(int, input().split()))
	ans_sp.append(obrabotka(l_x))
for elem in ans_sp:
	print(elem)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = a[::-1]
	x = a.index(1)
	y = b.index(1)
	y = n - y
	z = a[x:y]
	print(z.count(0))


for z in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = l.index(1)
	b = l[::-1].index(1)
	c = l[a:n - b].count(0)
	print(c)


for o in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a.count(1) == 1:
		print(0)
	else:
		c1 = a.count(1)
		if list(set(a[a.index(1):a.index(1) + c1]))[0] == 1 and len(list(set(a[a.index(1):a.index(1) + c1]))) == 1:
			print(0)
		else:
			s = str(a[a.index(1):])
			ans = list(s[:s.rfind('1')])
			print(ans.count('0'))


t = int(input())
for _ in range(t):
	n = int(input())
	books = list(input().split())
	index = books.index('1')
	ans = 0
	zeroes = 0
	for item in books[index + 1:]:
		if item == '0':
			zeroes += 1
		else:
			ans += zeroes
			zeroes = 0
	print(ans)


for q_ in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	w = []
	left = 0
	for i in range(n):
		if b[i] == 1:
			if left == 0:
				left = i
			if i == n - 1 or b[i + 1] == 0:
				w.append((left, i))
				left = 0
	total = 0
	while len(w) != 1:
		total += abs(w[0][1] - w[1][0]) - 1
		del w[0]
	print(total)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	z = 0
	move = 0
	s = False
	for i in a:
		if i == 0 and s:
			z += 1
		if i == 1:
			if not s:
				s = True
			else:
				move += z
				z = 0
	print(move)


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	(vl, vr) = (-1, -1)
	for i in range(n):
		if li[i] == 1:
			if vl == -1:
				vl = i
			vr = i
	if vl == vr:
		print(0)
	else:
		ans = 0
		for i in range(vl, vr + 1):
			if li[i] == 0:
				ans += 1
		print(ans)


t = int(input())
MAX = []
for i in range(t):
	s = int(input())
	n = [int(i) for i in input().split()]
	max = 0
	for i in range(s):
		max_new = 0
		if n[i] == 1 and i + 1 < s:
			while n[i + 1] != 1:
				max_new += 1
				i += 1
				if i + 1 >= s:
					max_new = 0
					break
		max += max_new
	MAX.append(max)
for i in range(t):
	print(MAX[i])


t = int(input())
for i in range(t):
	n = int(input().strip())
	shelf = list(map(int, input().strip().split(' ')))
	flag = False
	res = 0
	for pos in shelf:
		if flag and pos == 0:
			res = res + 1
		if pos == 1:
			flag = True
	mins_cnt = 0
	for pos in shelf[::-1]:
		if pos == 0:
			mins_cnt = mins_cnt + 1
		else:
			break
	print(res - mins_cnt)


q = int(input())
for _ in range(q):
	n = int(input())
	st = input().split()
	k_first = -1
	count_zero = 0
	for (i, x) in enumerate(st):
		if x == '1' and k_first == -1:
			k_first = i
		elif x == '0' and k_first != -1:
			count_zero += 1
	for x in st[::-1]:
		if x == '1':
			break
		elif x == '0':
			count_zero -= 1
	print(count_zero)


import re
import sys

def solve(nums: str) -> int:
	nums = nums.replace(' ', '')
	space_map = re.findall('0+', nums)
	distance_from_left = sum([int(len(i)) for i in space_map]) - (0 if nums[-1] == '1' else len(space_map[-1]))
	distance_from_right = sum([int(len(i)) for i in space_map]) - (0 if nums[0] == '1' else len(space_map[0]))
	distance_from_center = sum([int(len(i)) for i in space_map]) - (0 if nums[0] == '1' else len(space_map[0])) - (0 if nums[-1] == '1' else len(space_map[-1]))
	return min(distance_from_left, distance_from_right, distance_from_center)
for (count, line) in enumerate(sys.stdin):
	if count == 0:
		continue
	if count % 2 == 1:
		continue
	print(solve(line.rstrip()))


x = int(input())
for j in range(x):
	y = int(input())
	z = [int(x) for x in input().split()]
	c = 0
	for i in range(len(z) - 1):
		if z[i] == 1:
			p = z[i + 1:]
			if max(p) == min(p) == 0:
				break
			x = i
			while z[x + 1] == 0:
				if x == len(z):
					c = 0
					break
				c += 1
				x = x + 1
			i = x
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	li = [*map(int, input().split())]
	pos = []
	for j in range(n):
		if li[j] == 1:
			pos.append(j)
	ans = 0
	for j in range(len(pos) - 1):
		ans += pos[j + 1] - pos[j] - 1
	print(ans)


import sys
t = int(input().strip())
for a0 in range(t):
	n = int(input())
	l1 = [int(i) for i in input().split()]
	count = 0
	l = []
	for i in range(len(l1)):
		if l1[i] == 1:
			count += 1
			l.append(i)
	if count == 1:
		print(0)
	else:
		ans = 0
		for i in range(len(l) - 1):
			ans += l[i + 1] - l[i] - 1
		print(ans)


for t in range(int(input())):
	input()
	arr = list(map(int, input().split()))
	count = 0
	first = False
	temp = 0
	for i in range(len(arr)):
		if arr[i] == 0:
			temp += 1
		else:
			if first:
				count += temp
			temp = 0
			first = True
	print(count)


from math import *
from sys import *
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	ans = []
	x = f = 0
	for i in range(n):
		if a[i] == 1:
			f = 1
			ans.append(x)
			x = 0
		if f == 1 and a[i] == 0:
			x += 1
	print(sum(ans))


for _ in range(int(input())):
	int(input())
	n = input()
	flag = 0
	ans = 0
	count = 0
	for i in n:
		if i == '1' and flag == 0:
			flag = 1
		elif i == '0' and flag == 1:
			count += 1
		elif i == '1' and flag == 1:
			ans = count
	print(ans)


for _ in range(int(input())):
	n = int(input())
	has = list(map(int, input().split()))
	f = 0
	while f < n and has[f] != 1:
		f += 1
	e = n - 1
	while e > -1 and has[e] != 1:
		e -= 1
	print(e - f + 1 - has.count(1) if e >= f else 0)


for i in range(int(input())):
	n = int(input())
	c = 0
	ans = 0
	a = list(map(int, input().split()))
	for j in range(a.index(1), n, 1):
		if a[j] == 0:
			c += 1
		elif a[j] == 1:
			ans += c
			c = 0
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for z in range(n):
		if a[z] == 1:
			break
	for y in range(n - 1, -1, -1):
		if a[y] == 1:
			break
	a = a[z:y + 1]
	print(a.count(0))


tc = int(input())
for _ in range(tc):
	a = int(input())
	l = list(map(int, input().split()))
	c = 0
	i = 0
	if l.count(1) == 1:
		print(0)
	else:
		if l[0] == 0:
			while l[i] != 1:
				c += 1
				i += 1
			l = l[c:]
		if l[len(l) - 1] == 0:
			j = len(l) - 1
			d = len(l) - 1
			while l[j] != 1:
				d -= 1
				j -= 1
			l = l[:d + 1]
		print(l.count(0))


t = int(input())
for _ in range(t):
	n = int(input())
	books = list(map(int, input().split()))
	sum_so_far = 0
	cnt = 0
	for i in range(n):
		if books[i] == 1:
			for j in range(i + 1, n):
				if books[j] != 1:
					cnt += 1
				if books[j] == 1:
					sum_so_far += cnt
					cnt = 0
					break
	print(sum_so_far)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] == 1:
			ini = i + 1
			break
	c = 0
	for j in range(n):
		if a[j] == 1:
			fin = n - j
	for k in range(ini, n - fin + 1):
		if a[k] == 0:
			c = c + 1
	print(c)


t = int(input())
while t:
	n = int(input())
	arr = [int(x) for x in input().split()]
	(pre, res, i) = (0, 0, 0)
	for val in arr:
		if val == 1:
			break
		i += 1
	while i + 1 < n:
		i += 1
		if arr[i] == 0:
			pre += 1
			continue
		else:
			res += pre
			pre = 0
	print(res)
	t -= 1


t = int(input(''))
for _ in range(t):
	n = int(input(''))
	arr = list(map(int, input().split()))
	prev = -1
	ans = 0
	if arr.count(1) == 1:
		print(0)
		continue
	for i in range(n):
		if arr[i]:
			if prev != -1:
				ans += i - prev - 1
			prev = i
		else:
			continue
	print(ans)


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]

def solve(n, lst):
	lst = ''.join(list(map(str, lst))).strip('0')
	return len(lst) - sum(list(map(int, lst)))
for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	print(solve(n, lst))


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr.count(1) <= 1:
		print(0)
	else:
		strt = arr.index(1)
		end = n - 1 - arr[::-1].index(1)
		ans = 0
		while strt != end:
			if arr[strt] == 0:
				ans += 1
			strt += 1
		print(ans)


n = int(input())
a = []
for i in range(n):
	x = int(input())
	b = list(map(int, input().split()))
	l = b.index(1)
	b = b[::-1]
	r = len(b) - b.index(1)
	b = b[::-1]
	a.append(b[l + 1:r].count(0))
for i in a:
	print(i)


test_cases = int(input())
res = []
for i in range(0, test_cases):
	no_of_places = int(input())
	a = list(map(int, input().split(' ')))
	min = -1
	max = no_of_places
	n = no_of_places
	for i in range(0, n):
		if a[i] == 1:
			min = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			max = i
			break
	count = 0
	for i in range(min, max + 1):
		if a[i] == 0:
			count += 1
	res.append(count)
for i in res:
	print(i)


def rl():
	return list(map(int, input().split()))

def arp(arr):
	return ' '.join([str(i) for i in arr])
from collections import deque, Counter
from math import ceil, sqrt, log2, log, floor
for _ in range(int(input())):
	(n,) = rl()
	arr = rl()
	for i in range(n):
		if arr[i] == 1:
			ind = i
			break
	for i in range(n)[::-1]:
		if arr[i] == 1:
			dd = i
			break
	arr = arr[ind:dd + 1]
	ans = 0
	maxi = 0
	i = 0
	n = len(arr)
	while i < n:
		if i == n:
			break
		if arr[i] == 1:
			for j in range(i + 1, n):
				if arr[j] == 0:
					ans += 1
				else:
					maxi = max(ans, maxi)
					break
				i += 1
		i += 1
	maxi = max(maxi, ans)
	print(maxi)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	shelf = sys.stdin.readline().split()
	shelf = ''.join(shelf)
	sys.__stdout__.write(str(shelf.strip('0').count('0')) + '\n')


t = int(input())
for i in range(t):
	n = int(input())
	k = []
	nl = 0
	nw = True
	for el in list(map(int, input().split())):
		if el == 0:
			nl += 1
			nw = True
		elif nw:
			k.append(nl)
			nw = False
	print(k[-1] - k[0])


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	flag = False
	tmp = 0
	for i in range(n - 1):
		if flag and a[i] == 0:
			tmp += 1
			if a[i + 1] == 1:
				flag = False
				ans += tmp
				tmp = 0
		if a[i] == 1:
			flag = True
	print(ans)


for _ in range(int(input())):
	a = int(input())
	b = [int(i) for i in input().split()]
	c = 0
	d = 0
	for i in range(a):
		if b[i] == 1:
			c = i
			break
	for i in range(a - 1, 0, -1):
		if b[i] == 1:
			d = i
			break
	e = b[c:d]
	print(e.count(0))


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	if y == 0:
		return 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(moves, n):
	val = (moves + 1) // 2
	rem = moves - val
	sol = (val + 1) * (rem + 1)
	return sol < n

def sortSecond(val):
	return val[1]
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect
import functools as fnt
from decimal import Decimal

def solve():
	n = scanner()
	a = get_list()
	i = 0
	while a[i] == 0:
		i += 1
	j = n - 1
	while a[j] == 0:
		j -= 1
	print(a[i:j + 1].count(0))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = scanner()
for i in range(t):
	solve()


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	s = str(input())
	ans.append(s[s.find('1'):s.rfind('1')].count('0'))
for x in ans:
	print(x)


def minMoves(a):
	shift = 0
	i = 0
	if countOnes(a, 0) > 1:
		while i < len(a):
			if countOnes(a, i) == 1:
				return shift
			if a[i] == 1:
				j = i + 1
				if j >= len(a):
					i = i + 1
				while j < len(a):
					if a[j] == 0:
						shift = shift + 1
					else:
						i = j
						break
					j = j + 1
			else:
				i = i + 1
	else:
		return 0
	return shift

def countOnes(a, p):
	count = 0
	for i in range(p, len(a)):
		if a[i] == 1:
			count = count + 1
	return count
n = int(input())
while n > 0:
	k = int(input())
	a = input().split()
	for i in range(len(a)):
		a[i] = int(a[i])
	print(minMoves(a))
	a = []
	n = n - 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(k) for k in input().split()]
	while a[0] == 0:
		del a[0]
	while a[-1] == 0:
		del a[-1]
	print(a.count(0))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) == 1:
		print(0)
	else:
		x = a.index(1)
		a = a[x + 1:]
		if 0 in a:
			y = a.index(0)
			if y > 0:
				a = a[y:]
		ans = 0
		if 1 in a:
			while len(a) > 1:
				if 1 in a:
					x = a.index(1)
					ans += x
					a = a[x + 1:]
				else:
					break
		print(ans)


for i in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	z = []
	f = 0
	for i in range(1, len(s) + 1):
		if s[i - 1] == 1:
			z.append(i - 1)
	for j in range(2, len(z) + 1):
		f += z[j - 1] - z[j - 2] - 1
	print(f)


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	x = l1.index(1)
	c = l1.count(1)
	ans = 0
	for i in range(x, n):
		if l1[i] == 1:
			c -= 1
		else:
			ans += 1
		if c == 0:
			break
	print(ans)


from sys import stdin, stdout
t = int(stdin.readline())
for i in range(t):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	count0 = 0
	counter = 0
	for i in arr:
		if i == 1:
			counter += 1
		elif counter >= 1:
			count0 += 1
	k = len(arr) - 1
	while arr[k] == 0:
		count0 -= 1
		k -= 1
	if counter == 1:
		print(0)
	else:
		print(count0)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=300006, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
for ik in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ind = []
	for i in range(n):
		if l[i] == 1:
			ind.append(i)
	ans = 0
	for i in range(1, len(ind)):
		ans += ind[i] - ind[i - 1] - 1
	print(ans)


import math
import string
import random
from random import randrange
from collections import deque
from collections import defaultdict

def solve(n, arr):
	ans = 0
	st = 0
	while st < n and arr[st] == 0:
		st += 1
	ed = n - 1
	while ed >= 0 and arr[ed] == 0:
		ed -= 1
	if st == n or ed == -1:
		print(0)
		return
	for i in range(st, ed + 1):
		if arr[i] == 0:
			ans += 1
	print(ans)
	return

def main():
	t = int(input())
	while t > 0:
		t -= 1
		n = int(input())
		arr = list(map(int, input().strip().split(' ')))
		solve(n, arr)
	return

def test():
	arr_size = 25
	test_cases = 100
	min_range = -100
	max_range = 100
	str_size = 30
	step = 1
	for i in range(test_cases):
		k = []
		for j in range(arr_size):
			num = randrange(min_range, max_range, step)
			k.append(num)
		solve(n, arr)
		print('<-------- DEBUG ----------->')
	return

def __starting_point():
	main()
__starting_point()


for t in range(int(input())):
	n = int(input())
	a = list(map(str, input().split()))
	a = ''.join(a)
	a = a.strip('0')
	print(a.count('0'))


y122 = int(input())
for _ in range(y122):
	z = int(input())
	n = list(map(int, input().strip().split()))
	i = z - 1
	while n[i] != 1:
		i -= 1
	x = i
	y = 0
	while n[y] != 1:
		y += 1
	s = 0
	for i in range(y, x):
		if n[i] == 0:
			s += 1
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	cnt1 = 0
	for i in a:
		if i == 1:
			cnt1 += 1
	ans = 0
	one = 0
	for i in a:
		if i == 1 and one == 0:
			one = 1
		if one == 1 and i == 0:
			ans += 1
		if i == 1:
			cnt1 -= 1
		if cnt1 <= 0:
			break
	print(ans)


t = int(input())
for i in range(t):
	length = int(input())
	arr = list(map(int, input().split(' ')))
	start = 0
	end = 0
	dd = arr.count(1)
	for i in range(len(arr)):
		if arr[i] == 1 and dd >= 1:
			if dd == arr.count(1):
				start = i
			end = i
			dd -= 1
	print(arr[start:end].count(0))


import sys
import bisect as bi
import collections as cc
import heapq as hp
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
ar = []
for i in range(1, 10):
	j = str(i)
	while int(j) <= 10000:
		ar.append(int(j))
		j += str(i)
for tc in range(int(input())):
	(n,) = I()
	l = I()
	if 1 in l:
		x = l.index(1)
		y = n - l[::-1].index(1) - 1
		d = l[x:y].count(0)
		print(d)
	else:
		print(0)


t = int(input())
final = []
for counter in range(0, t):
	n = int(input())
	l = list(map(int, input().split(' ')[:n]))
	flag_x = 0
	flag_y = 0
	for x in range(0, n):
		if l[x] == 1:
			start = x
			flag_x = 1
			break
	for y in reversed(range(n)):
		if l[y] == 1:
			end = y
			flag_y = 1
			break
	k = 0
	if flag_x == 1 and flag_y == 1:
		for c in range(start, end + 1):
			if l[c] == 0:
				k += 1
	elif flag_y == 1 or flag_x == 1:
		k = 1
	else:
		k = 0
	final.append(k)
for counter in range(0, t):
	print(final[counter])


for _ in range(int(input())):
	n = input()
	a = [int(x) for x in input().split()]
	found = False
	zero = 0
	cnt = 0
	for i in a:
		if not found:
			if i == 1:
				found = True
				zero = 1
		else:
			if i == 0:
				zero = 0
				cnt += 1
			if i == 1:
				zero = 1
	cnt1 = 0
	if a[-1] == 0:
		for i in a[::-1]:
			if i == 1:
				break
			cnt1 += 1
	print(cnt - cnt1)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	flag = 0
	c = 0
	for i in range(n):
		if flag == 0 and a[i] == 1:
			ind = i
			flag = 1
		if a[i] == 1:
			ind2 = i
	for i in range(ind, ind2 + 1):
		if a[i] == 0:
			c += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().split()))
	(i, j) = (0, n - 1)
	while array[i] == 0:
		i += 1
	while array[j] == 0:
		j -= 1
	print(array[i:j + 1].count(0))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	c1 = 0
	f = False
	for i in a:
		if f == False and i == 0:
			c1 += 1
		else:
			break
	f = False
	for i in reversed(a):
		if f == False and i == 0:
			c1 += 1
		else:
			break
	for i in a:
		if i == 0:
			ans += 1
	print(max(0, ans - c1))


import sys, os
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
MOD = 10 ** 9 + 7

def main():
	ans_ = []
	for _ in range(int(input())):
		n = int(input())
		s = input().strip().replace(' ', '').strip('0').split('1')
		ans = 0
		for i in [len(j) for j in s if j != '']:
			ans += i
		ans_.append(str(ans))
	print('\n'.join(ans_))
main()


a = input()
for x in range(int(a)):
	b = input()
	c = input().split(' ')
	if c.count('1') == 1 or c.count('1') == len(c):
		print(0)
	else:
		d = [int(i) for i in c]
		tag = -1
		tag1 = -1
		index = len(d) - 1
		for i in range(len(d)):
			if d[i] == 1 and tag == -1:
				tag = i
			if d[index - i] == 1 and tag1 == -1:
				tag1 = index - i
		c = c[tag:tag1]
		print(c.count('0'))


n = int(input())
for i in range(n):
	n = int(input())
	l = list(map(int, input().split()))
	if l.count(1) <= 1:
		print(0)
	else:
		s = l.index(1)
		for i in range(n - 1, s, -1):
			if l[i] == 1:
				e = i
				break
		c = 0
		for i in range(s, e):
			if l[i] == 0:
				c += 1
		print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	while i < n and a[i] == 0:
		i += 1
	a = a[i:]
	j = n - 1
	while a and a[-1] == 0:
		a.pop()
	b = sorted(a)
	j = 0
	while b[j] != 1:
		j += 1
	mx = 0
	for i in range(len(a)):
		if a[i] == 1:
			mx = max(mx, j - i)
			j += 1
	print(mx)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = a.index(1)
	r = n - a[::-1].index(1)
	print(a[l:r].count(0))


for i in range(int(input())):
	n = int(input())
	nums = list(map(int, input().split(' ')))
	if nums.count(1) <= 1:
		print(0)
	else:
		start = 0
		end = 0
		for j in range(n):
			if start == 0 and nums[j] == 1:
				start = str(j)
			elif start != 0 and nums[j] == 1:
				end = j
		print(nums[int(start):end].count(0))


import sys, math
import io, os

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
mod = int(1000000000.0) + 7
for t in range(int(data())):
	n = int(data())
	a = mdata()
	ind = -1
	for i in range(n):
		if a[i] == 1:
			ind = i
			break
	if ind == -1:
		out(0)
		exit()
	l = []
	s = 0
	for i in range(ind + 1, n):
		if a[i] == 1 and a[i - 1] == 0:
			s += i - ind - 1
		if a[i] == 1:
			ind = i
	out(s)


t = int(input())
for i in range(t):
	n = int(input())
	s1 = list(map(int, input().split()))
	for j in range(n):
		if s1[j] == 1:
			a = j
			break
	for j in range(n):
		if s1[j] == 1:
			b = j
	print(s1[a:b].count(0))


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	res = []
	for i in range(n):
		if not res or res[-1] == 0 or (res[-1] == 1 and lis[i] == 0):
			res.append(lis[i])
	ans = 0
	idx = res.index(1)
	for i in range(idx + 1, len(res)):
		if res[i] == 1:
			ans += i - idx - 1
			idx = i
	print(ans)


n = int(input(''))
for i in range(n):
	k = int(input(''))
	l = list(map(int, input('').split()))
	nzero = 0
	a = l.index(1)
	b = list(reversed(l)).index(1)
	for ii in l[a:k - b]:
		if ii == 0:
			nzero += 1
	print(nzero)


from sys import stdin, stdout

def readArr():
	return list(map(int, stdin.readline().strip().split()))

def readLine():
	return stdin.readline().strip()

def readInt():
	return int(stdin.readline().strip())
n = int(input())
for _ in range(n):
	x = int(input())
	arr = readArr()
	last = False
	ans = 0
	(lo, hi) = ([0, False], len(arr))
	for i in range(len(arr)):
		if arr[i] == 1 and lo[1] == False:
			lo[0] = i
			lo[1] = True
		if arr[i] == 1:
			hi = i
	if lo[0] == hi:
		print(0)
	else:
		for i in range(lo[0], hi):
			if arr[i] == 0:
				ans += 1
		print(ans)


a = int(input())
flag = False
for _ in range(a):
	t = 0
	c = 0
	b = int(input())
	dt = input().split(' ')
	flag = False
	for d in dt:
		d = int(d)
		if flag == True and d == 1:
			flag = False
			t += c
			c = 0
		if d == 1 and flag == False:
			flag = True
		elif flag == True and d == 0:
			c += 1
	print(t)


ans = []
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	start = 0
	end = n - 1
	cnt = 0
	for i in range(n):
		if a[i] == 1:
			start = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			end = i
			break
	for i in range(start, end + 1):
		if a[i] == 0:
			cnt += 1
	ans += [cnt]
print(*ans, sep='\n')


for _ in range(int(input())):
	n = int(input())
	s = input().split()
	ans = 0
	i = 0
	while s[-i - 1] == '0':
		i += 1
	flag = False
	j = 0
	while j < n - i:
		if flag and s[j] == '0':
			ans += 1
		if s[j] == '1':
			flag = True
		j += 1
	print(ans)


for _ in ' ' * int(input()):
	a = int(input())
	b = input().replace(' ', '').replace('01', '0 1').replace('10', '1 0').split()
	while '0' in b[0]:
		b.pop(0)
	while '0' in b[-1]:
		b.pop()
	z = []
	ans = 0
	for i in range(1, len(b), 2):
		ans += len(b[i])
	print(ans)


import sys
from math import sqrt
from collections import defaultdict
inpt = sys.stdin.readline

def inp():
	return int(inpt())

def inlist():
	return list(map(int, inpt().split()))

def instr():
	s = inpt()
	return list(s[:len(s) - 1])

def inbitstr():
	s = inpt()
	return [int(i) for i in list(s[:len(s) - 1])]

def invr():
	return map(int, inpt().split())

def printlist(a):
	for i in range(len(a)):
		print(a[i], end='')
	print()

class Graph:

	def __init__(self, n):
		self.n = n
		self.graph = defaultdict(list)
		self.marked = defaultdict(int)
		self.wt = defaultdict(int)

	def addEdge(self, u, v, wt):
		self.graph[u].append(v)
		self.graph[v].append(u)
		self.wt[n * u + v] = wt

	def cleanup(self):
		self.marked = defaultdict(int)

	def dfs(self, u):
		self.marked[u] = 1
		(max, maxnode) = (0, u)
		for i in self.graph[u]:
			(cur, node) = (0, 0)
			if self.marked[i] == 0:
				(cur, node) = self.dfs(i)
			if cur > max:
				max = cur
				maxnode = node
		return (1 + max, maxnode)

	def lngdfs(self, u, v):
		self.marked[u] = 1
		max = self.n
		for i in self.graph[u]:
			if i == v:
				return 1
			cur = self.n
			if self.marked[i] == 0:
				cur = self.lngdfs(i, v)
			if cur < max:
				max = cur
		return 1 + max

def main():
	t = inp()
	for l in range(t):
		n = inp()
		a = inlist()
		ans = 0
		strbk = False
		nobook = 0
		for i in range(n):
			if a[i] == 1 and strbk == False:
				strbk = True
			if a[i] == 1 and strbk == True:
				ans += nobook
				nobook = 0
			if a[i] == 0 and strbk == True:
				nobook += 1
		print(ans)
main()


x = int(input())
for i in range(x):
	y = int(input())
	l = list(input().split())
	m = []
	s = 0
	for j in range(y):
		if l[j] == '1':
			m.append(j)
	for i in range(len(m) - 1):
		a = m[i + 1] - m[i] - 1
		s = a + s
	print(s)


for i in range(int(input())):
	store = 0
	count = 0
	active = False
	input()
	for num in input():
		if num == '1':
			active = True
			count += store
			store = 0
		elif num == '0' and active:
			store += 1
	print(count)


import sys
input = sys.stdin.readline

def rle(lst):
	ans = []
	cnt = 1
	ini = lst[0]
	for i in range(1, len(lst)):
		if ini == lst[i]:
			cnt += 1
		else:
			ans.append((ini, cnt))
			cnt = 1
			ini = lst[i]
	ans.append((ini, cnt))
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = r = -1
	for i in range(n):
		if a[i] == 1:
			l = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			r = i
			break
	if l == r:
		print(0)
	else:
		u = a[l:r].count(0)
		print(u)


t = int(input())
for i in range(t):
	n = int(input())
	l = input().split(' ')
	l = [int(x) for x in l]
	while True:
		if l[0] == 0:
			l.pop(0)
		else:
			break
	while True:
		if l[-1] == 0:
			l.pop(-1)
		else:
			break
	contador = 0
	for k in l:
		if k == 0:
			contador += 1
	print(contador)


from sys import stdin, stdout
import math
import heapq
import collections
input = stdin.readline

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstrings():
	return [x for x in input().split()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	n = inputnum()
	a = inputlist()
	start = 0
	end = 0
	for i in range(n):
		if a[i] == 1:
			start = i
			break
	for i in reversed(range(n)):
		if a[i] == 1:
			end = i
			break
	ans = 0
	for i in range(start, end):
		ans += a[i] == 0
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = a.index(1)
	r = a[::-1].index(1)
	r = n - 1 - r
	if r == l:
		print(0)
	else:
		k = 0
		for i in range(l, r + 1):
			if a[i] == 0:
				k += 1
		print(k)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	s = 'a'
	e = 'a'
	z = 0
	flag = 0
	lst = []
	for i in range(n):
		if flag == 1:
			if l[i] == 0:
				z += 1
			else:
				lst.append(z)
				e = i
		elif flag == 0:
			if l[i] == 1:
				flag = 1
	if len(lst) > 0:
		print(lst[-1])
	else:
		print(0)


from sys import stdin, stdout
import math
from collections import deque
input = stdin.readline

def print(*args, end='\n'):
	s = []
	for i in args:
		s.append(str(i) + ' ')
	s = ''.join(s)
	stdout.write(s + end)

def solve():
	ans = 0
	n = int(input())
	l = list(map(int, input().split()))
	j = 0
	cc = l.count(1)
	for i in range(n):
		if l[i] == 1:
			j = i
			break
	k = n - 1
	for i in range(n - 1, -1, -1):
		if l[i] == 1:
			k = i
			break
	for i in range(j, k):
		ans += 1 if l[i] == 0 else 0
	print(ans if cc > 1 else 0)
tt = 1
tt = int(input())
for __ in range(tt):
	solve()


for _ in range(int(input())):
	input()
	s = [int(i) for i in input().split()]
	i2 = 0
	l = 0
	f = -1
	for i in s:
		if i == 1:
			if f == -1:
				f = i2
			l = i2
		i2 += 1
	print(s[f:l].count(0))


for t in range(int(input())):
	ip = int(input())
	lsip = list(map(int, input().split()))
	count = 0
	flag = 0
	pos0 = 0
	posl = 0
	for i in range(ip):
		if lsip[i] == 1:
			if flag == 0:
				pos0 = i
				flag = 1
			posl = i
			count += 1
	count = posl - pos0 + 1 - count
	print(count)


try:
	t = int(input())
	while t:
		t = -1
		n = int(input())
		a = list(map(int, input().split()))
		for i in range(n):
			if a[i] == 1:
				break
		for j in range(n - 1, -1, -1):
			if a[j] == 1:
				break
		if i == j:
			print(0)
		else:
			print(a[i:j].count(0))
except:
	pass


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	found = False
	eye = 0
	for j in range(n):
		if arr[j] == 1 and found == False:
			eye = j
			found = True
		elif arr[j] == 1:
			ans += abs(j - eye - 1)
			eye = j
	print(ans)


t = input()
for i in range(int(t)):
	n = int(input())
	a = [int(a) for a in input().split()]
	ans = 0
	for x in range(len(a)):
		if a[x] == 1 and x != len(a) - 1:
			j = x + 1
			maxi = 0
			while j <= len(a) - 1:
				if a[j] == 0:
					maxi += 1
				if a[j] == 1:
					ans = max(maxi, ans)
				j += 1
	print(ans)


def solve(n, arr):
	if n < 2:
		return 0
	j = 0
	while j < n:
		if not arr[j]:
			j += 1
		else:
			break
	if j == n:
		return 0
	z = 0
	ans = 0
	for i in range(j + 1, n):
		if arr[i] == 1 and arr[i - 1] == 0:
			ans += z
			z = 0
		z += int(arr[i] == 0)
	z = 0
	for i in arr:
		if i == 0:
			z += 1
		else:
			break
	return ans
t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	print(min(solve(n, arr), solve(n, arr[::-1])))
	t -= 1


def testcase():
	n = int(input())
	arr = list(map(int, input().split()))
	i = 0
	while i < n:
		if arr[i] == 1:
			break
		i += 1
	i += 1
	ans = 0
	zs = 0
	while i < n:
		if arr[i] == 0:
			zs += 1
		else:
			ans += zs
			zs = 0
		i += 1
	print(ans)
	return
import sys, os
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
t = int(input())
for _ in range(t):
	testcase()


for i in range(int(input())):
	n = input()
	arr = list(map(int, input().split()))
	while arr[:1] == [0]:
		arr = arr[1:]
	while arr[-1:] == [0]:
		arr = arr[:-1]
	print(len(arr) - sum(arr))


def solve():
	n = int(input())
	p = list(map(int, input().split()))
	l = p
	a = l.index(1)
	b = n - l[::-1].index(1) - 1
	c = p[a:b + 1].count(0)
	print(c)
for t in range(int(input())):
	solve()


from math import *
t = int(input())
for u in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 0
	out = 0
	ind = a.index(1)
	for i in range(ind, n):
		if a[i] == 1:
			out += cnt
			cnt = 0
		else:
			cnt += 1
	print(out)


for _ in range(int(input())):
	n = int(input())
	nums = [int(i) for i in input().split()]
	count = 0
	ind1 = nums.index(1)
	for i in range(n):
		if nums[i] == 1:
			ind2 = i
	for i in range(ind1, ind2 + 1):
		if nums[i] == 0:
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	first_book = -1
	for i in range(n):
		if a[i] == 1:
			first_book = i
			break
	last_book = n
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			last_book = i
			break
	if first_book == last_book:
		print(0)
	else:
		gap = 0
		prev_book = first_book
		first_book += 1
		while first_book <= last_book:
			if a[first_book] == 1:
				gap += first_book - prev_book - 1
				prev_book = first_book
			first_book += 1
		print(gap)


def bookShelf(arr):
	t = 0
	cc = 0
	st = []
	for i in range(len(arr)):
		if arr[i] == 1:
			st.append(arr[i])
			t += cc
			cc = 0
		elif not len(st) == 0:
			cc += 1
	print(t)
t = int(input())
while t:
	n = int(input())
	arr = [int(x) for x in input().split()]
	bookShelf(arr)
	t -= 1


def min_steps(arr):
	l = 0
	r = len(arr) - 1
	while arr[l] == 0:
		l += 1
	while arr[r] == 0:
		r -= 1
	return arr[l:r].count(0)
import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	arr = [int(a) for a in sys.stdin.readline().split()]
	print(min_steps(arr))


tc = int(input())
for tcc in range(1, tc + 1):
	n = int(input())
	l = list(map(int, input().split()))
	if sum(l) <= 1:
		print(0)
	else:
		alls = []
		for i in range(0, len(l)):
			if l[i] == 1:
				alls.append(i)
		first1 = alls[0]
		last1 = alls[-1]
		tot = 0
		for j in range(first1, last1 + 1):
			if l[j] == 0:
				tot += 1
		print(tot)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	index = [j for j in range(n) if a[j] == 1]
	ans = 0
	for j in range(len(index) - 1):
		ans += index[j + 1] - index[j] - 1
	print(ans)


def find_zeros(n, lst):
	res = []
	for (i, j) in enumerate(lst):
		if j == 1:
			res.append(i)
	count = 0
	for i in range(res[0] + 1, res[-1]):
		if lst[i] == 0:
			count += 1
	return count
for _ in range(int(input())):
	m = int(input())
	a = [int(i) for i in input().split()]
	print(find_zeros(m, a))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	idxs = [i for i in range(n) if a[i] == 1]
	if len(idxs) == 1:
		print(0)
	else:
		(l, r) = (idxs[0], idxs[-1])
		zero = 0
		for i in range(l + 1, r):
			if a[i] == 0:
				zero += 1
		print(zero)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	(s, e) = (-1, -1)
	f = False
	for i in range(n):
		if l[i] == 1:
			if not f:
				s = i
				f = True
			e = i
	if s == e:
		print(0)
	else:
		res = 0
		for i in range(s, e + 1):
			if l[i] == 0:
				res += 1
		print(res)


for i in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	a = []
	c = 0
	for i in range(n):
		if lst[i] == 1:
			a.append(c)
			c = 0
		else:
			c += 1
	print(sum(a[1:]))


for _ in range(int(input())):
	v = input()
	x = input().split()
	if x.count('1') < 2:
		print(0)
	else:
		x = x[x.index('1'):len(x) - x[::-1].index('1')]
		print(x.count('0'))


import itertools
import math
import sys
from collections import defaultdict

def is_debug():
	return '--debug' in sys.argv

def stdin_wrapper():
	data = '5\n7\n0 0 1 0 1 0 0\n3\n1 0 0\n5\n1 1 0 0 1\n6\n1 0 0 0 0 1\n5\n1 1 0 1 1\n\n'
	for line in data.split('\n'):
		yield line
if not is_debug():

	def stdin_wrapper():
		while True:
			yield sys.stdin.readline()
inputs = stdin_wrapper()

def input_wrapper():
	return next(inputs)

def get_str():
	if is_debug():
		return input_wrapper()
	return input()

def get(_type):
	if _type == str:
		return get_str()
	return _type(input_wrapper())

def get_arr(_type):
	return [_type(x) for x in input_wrapper().split()]

def tuplerize(method):

	def wrap(*args, **kwargs):
		res = method(*args, **kwargs)
		if not isinstance(res, (tuple, list)):
			res = (res,)
		return res
	return wrap

@tuplerize
def solve(a):
	spaces = 0
	if a[0] == 0:
		a = a[a.index(1):]
	if a[-1] == 0:
		last_1 = a[::-1].index(1)
		a = a[:len(a) - 1 - last_1]
	return a.count(0)
t = get(int)
for _ in range(t):
	l = get(int)
	a = get_arr(int)
	print(*solve(a))


import math
from collections import deque
from sys import stdin, stdout, setrecursionlimit
from string import ascii_letters
letters = ascii_letters[:26]
from collections import defaultdict
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	l = 0
	r = n - 1
	while l < n and arr[l] != 1:
		l += 1
	while r > l and arr[r] != 1:
		r -= 1
	res = 0
	for i in range(l, r):
		res += 1 - arr[i]
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(input().split(' '))
	(i_, j_) = (0, len(a) - 1)
	while int(a[i_]) != 1:
		i_ += 1
	while int(a[j_]) != 1:
		j_ -= 1
	ans = 0
	for j in range(i_, j_, 1):
		if int(a[j]) == 0:
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	count = l.count(1)
	if count <= 1:
		print(0)
	else:
		move = 0
		for i in range(count - 1):
			x = l.index(1)
			y = l.index(1, x + 1, n + 1)
			move += y - x - 1
			l[x] = 0
		print(move)


q = int(input())
for i in range(0, q):
	n = int(input())
	p = list(map(int, input().split()))
	l = -1
	r = -1
	for i in range(0, n):
		if l == -1 and p[i] == 1:
			l = i
		if p[i] == 1:
			r = i
	c = 0
	for i in range(l, r + 1):
		if p[i] == 0:
			c += 1
	print(c)


from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
from math import sqrt
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	for _ in range(int(input())):
		n = inin()
		a = ain()
		z = []
		o = []
		temp = -1
		temp2 = 0
		ans1 = 0
		ans2 = 0
		ans = 0
		for i in range(n):
			if len(o) != 0:
				if a[i] == 0:
					temp2 += 1
				else:
					ans += temp2
					temp2 = 0
			elif a[i] == 1:
				o.append(1)
		print(ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for tt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [i for i in range(n) if a[i]]
	ans = 0
	for i in range(len(b) - 1):
		ans += b[i + 1] - b[i] - 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	i = 0
	while l[i] != 1:
		l.pop(i)
	i = -1
	while l[i] != 1:
		l.pop(i)
	j = l.count(0)
	print(j)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	count = -1
	su_m = 0
	for i in range(n):
		if a[i] == 1 and count == -1:
			count = 0
		elif a[i] == 0 and count != -1:
			count += 1
		elif a[i] == 1 and count != -1:
			su_m += count
			count = 0
	print(su_m)
	t -= 1


for t in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	if l1.count(1) == 1:
		print('0')
	else:
		count = 0
		a = l1.index(1)
		b = len(l1) - 1 - l1[::-1].index(1)
		for i in range(a, b):
			if l1[i] == 0:
				count += 1
		print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	lis = []
	a = 0
	for i in range(n):
		if arr[i] == 1:
			lis.append(i)
			a += 1
	ans = 0
	for i in range(a - 1):
		ans += lis[i + 1] - lis[i] - 1
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	A = list(map(int, input().split(' ')))
	one = []
	for i in range(n):
		if A[i] == 1:
			one.append(i)
	if len(one) == 1:
		print(0)
	else:
		c = 0
		for i in range(len(one) - 1):
			c += one[i + 1] - one[i] - 1
		print(c)


t = int(input())
for i in range(t):
	l = str(input())
	books = list(map(str, input().split()))
	result = 0
	while books[0] == '0':
		del books[0]
	while books[-1] == '0':
		del books[-1]
	for i in range(len(books)):
		if books[i] == '0':
			result += 1
	print(result)


n = int(input())
for e in range(n):
	t = int(input())
	seq = input().split()
	zeros = 0
	comecou = False
	resp = 0
	for x in seq:
		if x == '1':
			comecou = True
		if comecou:
			if x == '0':
				zeros += 1
			else:
				resp = zeros
	print(resp)


def minMoves(arr):
	result = 0
	books = 0
	empty_place = 0
	for i in range(len(arr)):
		if books == 1 and arr[i] == 1 and (empty_place != 0):
			result = result + empty_place
			empty_place = 0
		elif arr[i] == 0 and books == 1:
			empty_place = empty_place + 1
		else:
			books = arr[i]
	return result
t = int(input())
for _ in range(t):
	n = int(input())
	book_self = list(map(int, input().strip().split()))
	print(minMoves(book_self))


t = int(input())
res = list()
for i in range(0, t):
	n = int(input())
	zc = 0
	an = ''
	for a in input().split():
		an = an + a
	lo = an.find('1')
	ro = an.rfind('1')
	for j in range(lo, ro):
		if an[j] == '0':
			zc += 1
	res.append(zc)
for a in res:
	print(a)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	lst = [i for i in range(n) if arr[i] == 1]
	c = 0
	for i in range(len(lst) - 1):
		c += lst[i + 1] - lst[i] - 1
	print(c)


for _ in range(int(input())):
	x = input()
	l = list(map(int, input().split()))
	ans = 0
	last = -1
	for i in range(len(l)):
		if l[i] == 1:
			if last != -1:
				ans += i - last - 1
			last = i
	print(ans)


for z in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	init = 0
	count = 0
	already = 0
	last = 0
	for i in a:
		if i:
			init = 1
			already = 1
			last = 0
		elif already == 1:
			last += 1
			count += 1
	print(count - last)


def solve():
	n = int(input())
	x = list(map(int, input().split()))
	cur = x.count(1)
	if cur == 1:
		print(0)
		return
	cur = 0
	for i in range(n - 1, -1, -1):
		if x[i] == 1:
			cur = i
			break
	print(x[x.index(1):cur + 1].count(0))
t = int(input())
for i in range(t):
	solve()


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	z = a.count(0)
	j = 0
	while j < n and a[j] != 1:
		j += 1
		z -= 1
	j = n - 1
	while j >= 0 and a[j] != 1:
		j -= 1
		z -= 1
	print(z)


for _ in range(int(input())):
	n = int(input())
	shelf = list(map(int, input().split()))
	(start, end, count) = (0, 0, 0)
	for i in range(len(shelf)):
		if shelf[i] == 1:
			start = i
			break
	for i in range(len(shelf) - 1, 0, -1):
		if shelf[i] == 1:
			end = i
			break
	if start == end:
		print(0)
		continue
	for i in range(start, end):
		if shelf[i] == 0:
			count += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().strip().split()]
	first = -1
	last = -1
	for i in range(n):
		if arr[i]:
			if first == -1:
				first = i
			last = i
	if first == last:
		print('0')
	else:
		num = 0
		for i in range(first, last + 1):
			if arr[i] == 0:
				num += 1
		print(num)


for i in range(int(input())):
	j = int(input())
	k = [int(i) for i in input().split()]
	r = list(reversed(k))
	start = k.index(1)
	end = j - r.index(1)
	if start != end:
		print(k[start:end].count(0))
	else:
		print(0)


def solve():
	n = int(input())
	s = ''.join(input().split()).split('1')
	ans = 0
	for i in range(1, len(s)):
		if i + 1 == len(s) and s[i]:
			break
		ans += len(s[i])
	print(ans)
t = int(input())
while t:
	solve()
	t -= 1


for _ in range(int(input())):
	n = int(input())
	arr = ''.join(list(map(str, input().split()))).strip('0')
	print(arr.count('0'))


for i in range(int(input())):
	n = int(input())
	x = input()
	print(x[x.find('1'):x.rindex('1') + 1].count('0'))


import sys
INP = lambda : sys.stdin.readline().strip()
INT = lambda : int(INP())
MAP = lambda : map(int, INP().split())
ARR = lambda : [int(i) for i in INP().split()]

def JOIN(arr, x=' '):
	return x.join([str(i) for i in arr])

def EXIT(x='NO'):
	print(x)
	exit()
for _ in range(INT()):
	(n, arr) = (INT(), ARR())
	print(arr.count(0) - arr.index(1) - arr[::-1].index(1))


for _ in range(int(input())):
	n = int(input())
	a = [i for i in input().split()]
	s = ''.join(a)
	start = s.find('1')
	end = s.rfind('1')
	snew = s[start:end + 1]
	print(snew.count('0'))


from collections import Counter

def solve(a, n):
	ans = 0
	f = True
	c = n - 1
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			if not f:
				ans += c - i - 1
			c = i
		elif a[i] == 0 and a[i + 1:].count(1) > 0:
			f = False
	if f:
		ans += c
	return ans
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(min(solve(a, n), solve(a[::-1], n)))


import math
import sys
import collections
import bisect
input = sys.stdin.readline
flush = sys.stdout.flush
readint = lambda : int(input())
readintm = lambda : map(int, input().strip().split())
readintl = lambda : list(map(int, input().strip().split()))
readfloatm = lambda : map(float, input().strip().split())
readfloatl = lambda : list(map(float, input().strip().split()))
readstr = lambda : input().strip()
readstrl = lambda : list(input().strip())
join = lambda x, l: x.join(map(str, l))
print = lambda *x: sys.stdout.write(' '.join(map(str, x)) + '\n')
printl = lambda l: sys.stdout.write(' '.join(map(str, l)) + '\n')
ceil = lambda x, y: (x + y - 1) // y
mod = 1000000007
for _ in range(readint()):
	n = readint()
	books = join('', readintl())
	l = list(books.lstrip('0')).count('0')
	r = list(books.rstrip('0')).count('0')
	m = list(books.strip('0')).count('0')
	print(min(l, r, m))


t = int(input())
for i in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	j = 0
	ans = 0
	ind = []
	while j < n:
		if b[j] == 1:
			if ind != []:
				ans += j - ind[-1] - 1
			ind.append(j)
		j += 1
	print(ans)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if sum(a) == 1:
		print(0)
	else:
		i = 0
		j = n - 1
		while i < n and a[i] == 0:
			i += 1
		while j >= 0 and a[j] == 0:
			j -= 1
		res = 0
		for k in range(i, j + 1):
			res += a[k] == 0
		print(res)


import sys

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_first():
	for k in range(n):
		if ar[k] == 1:
			return k

def get_last():
	for m in range(n):
		if ar[n - (m + 1)] == 1:
			return n - m
for i in range(int(input())):
	n = int(input())
	ar = get_list()
	f = get_first()
	l = get_last()
	if f == l:
		print(0)
		continue
	else:
		count = 0
		tmp = ar[f:l]
		for j in tmp:
			if j == 0:
				count += 1
	print(count)


def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	for case in range(int(input())):
		n = int(input())
		arr = [int(x) for x in input().split()]
		if arr.count(1) <= 1:
			print(0)
			continue
		i = arr.index(1)
		j = arr[::-1].index(1)
		j = n - j
		ans = arr[i:j].count(0)
		print(ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi, ceil
import math
from itertools import permutations
from copy import deepcopy
from sys import setrecursionlimit

def main():
	for t in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		l = []
		for i in range(n):
			if a[i] == 1:
				l.append(i)
		c = 0
		for i in range(1, len(l)):
			c += l[i] - l[i - 1] - 1
		print(c)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def get_input(a=str):
	return a(input())

def get_int_input():
	return get_input(int)

def get_input_arr(a):
	return list(map(a, input().split()))

def get_int_input_arr():
	return get_input_arr(int)

def solve():
	t = get_int_input()
	for _ in range(t):
		n = get_int_input()
		arr = get_int_input_arr()
		found_one = False
		res = 0
		curr_res = 0
		for i in range(n):
			if arr[i] == 1:
				if found_one:
					res += curr_res
				curr_res = 0
				found_one = True
			else:
				curr_res += 1
		cout << res << endl

def main():
	solve()
main()


t = int(input())
while t != 0:
	n = int(input())
	a = list(map(int, input().split()))[:n]
	if a.count(1) == 1:
		print(0)
	else:
		x = a.index(1)
		y = n - 1 - a[::-1].index(1)
		k = a[x:y + 1]
		print(k.count(0))
	t -= 1


num = int(input())
inps = []
inps2 = []
for i in range(0, num):
	inps.append(int(input()))
	inps2.append(list(map(int, input().split())))
for i in range(0, num):
	l = inps[i]
	sp = inps2[i]
	right = l - 1
	left = 0
	while sp[right] != 1:
		right -= 1
	while sp[left] != 1:
		left += 1
	print(right - left + 1 - sum(sp))


from sys import stdin, stdout
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s1 = set()
	for i in range(n):
		if arr[i] == 1:
			s1.add(i)
	s1 = list(s1)
	s1.sort()
	if len(s1) == 1:
		print(0)
	else:
		cnt = 0
		for i in range(1, len(s1)):
			cnt += s1[i] - s1[i - 1] - 1
		print(cnt)


for _ in range(int(input())):
	input()
	x = input().split()
	beg = end = -1
	for (i, v) in enumerate(x):
		if v == '1':
			if beg < 0:
				beg = i
			end = i
	if beg == end:
		print(0)
	else:
		print(sum((1 for v in x[beg:end] if v == '0')))


from sys import stdin, stdout
from collections import *
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	n = int(input())
	l = li()
	ans = 0
	flag = 0
	for i in range(n):
		if l[i]:
			flag = 1
		if flag and (not l[i]):
			ans += 1
	for i in range(n - 1, -1, -1):
		if l[i]:
			break
		else:
			ans -= 1
	pr(ans)
for _ in range(inp()):
	solve()


def solve():
	for _ in range(int(input())):
		n = int(input())
		books = list(map(int, input().split()))
		s = -1
		res = 0
		for i in range(n):
			if books[i] == 1:
				if s == -1:
					s = i
				else:
					res += i - s - 1
					s = i
		print(res)
solve()


for _ in range(int(input())):
	n = int(input())
	data = [int(x) for x in input().split()]
	ans = 0
	flag = 0
	temp = 0
	for q in data:
		if q == 1:
			flag = 1
			ans += temp
			temp = 0
		if q == 0:
			if flag == 1:
				temp += 1
	print(ans)


import sys
input = sys.stdin.readline
for test in range(int(input())):
	n = int(input())
	a = input()
	low = a.find('1')
	high = a.rfind('1')
	ans = a[low:high].count('0')
	print(ans)


for _ in range(int(input())):
	n = input()
	a = list(map(int, input().split()))
	count = 0
	zeros = 0
	ones = 0
	for item in a:
		if item == 1:
			ones = ones + 1
			count = zeros
		elif item == 0 and ones > 0:
			zeros = zeros + 1
	print(count)


t = int(input())
for _ in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	pp = 0
	for i in range(0, len(a)):
		if a[i] == 1:
			pp = 1
			break
	if pp == 1:
		for j in range(len(a) - 1, -1, -1):
			if a[j] == 1:
				break
		if j != i:
			pp = a[i:j]
			print(pp.count(0))
		else:
			print(0)
	else:
		print(0)


t = int(input())
res = []
for i in range(t):
	ed = []
	le = int(input())
	a = [int(i) for i in input().split()]
	for j in range(len(a)):
		if a[j] == 1:
			ed.append(j)
	g = 0
	if len(ed) > 1:
		for k in range(len(ed) - 1):
			if ed[k + 1] - ed[k] != 1:
				g += ed[k + 1] - (ed[k] + 1)
		res.append(g)
		g = 0
	else:
		res.append(0)
for i in range(len(res)):
	print(res[i])


[print(sum((1 for i in str(int(str(int(input() * 0 + input().replace(' ', '')))[::-1])) if i == '0'))) for i in range(int(input()))]


tests = int(input())
for _ in range(tests):
	m = int(input())
	n = list(map(int, input().split()))
	(l, r) = (0, m - 1)
	while l < r:
		if not n[l]:
			l += 1
		if not n[r]:
			r -= 1
		if n[l] and n[r]:
			break
	res = 0
	for i in range(l, r + 1):
		if not n[i]:
			res += 1
	print(res)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	one = False
	cnt = 0
	for i in range(n):
		if arr[i]:
			one = True
			ans += cnt
			cnt = 0
		elif one:
			cnt += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	found = False
	count = 0
	res = 0
	for i in range(n):
		if found:
			if arr[i] == 0:
				count += 1
			else:
				res += count
				count = 0
		elif arr[i] == 1:
			found = True
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split(' ')))
	while A[0] == 0 or A[-1] == 0:
		if A[0] == 0:
			A.pop(0)
		elif A[-1] == 0:
			A.pop(-1)
	print(A.count(0))


t = int(input())
for i in range(t):
	x = int(input())
	a = list(map(str, input().split()))
	s = ''.join(a)
	ind1 = s.find('1')
	ind2 = s.rfind('1')
	print(ind2 - ind1 - s.count('1') + 1)


def read_int() -> int:
	return int(input())

def read_ints():
	return map(int, input().split(' '))

def test_case():
	n = read_int()
	a = list(read_ints())
	print(n - next((ind for (ind, x) in enumerate(reversed(a)) if x)) - next((ind for (ind, x) in enumerate(a) if x)) - sum(a))
for _ in range(read_int()):
	test_case()


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	f = o = 0
	ans = c = 0
	for x in a:
		if x == 1 and f == 0:
			f = 1
		if x == 0 and f == 1:
			c += 1
		if f == 1 and x == 1:
			ans += c
			c = 0
	print(ans)


n = int(input())
for i in range(n):
	x = int(input())
	l = list(map(int, input().split()))
	a = []
	for j in range(x):
		if l[j] == 1:
			a.append(j)
	y = 0
	for j in range(len(a) - 1):
		y = y + a[j + 1] - a[j] - 1
	print(y)


T = int(input())

def f(l, n):
	i = 0
	while i < n and l[i] != 1:
		i += 1
	if i >= n - 1:
		return 0
	s = 0
	b = 0
	m0 = 0
	while i < n:
		if l[i] == 0:
			b += 1
			m0 = 1
		elif m0 == 1:
			s += b
			b = 0
			m0 = 0
		i += 1
	return s
while T:
	n = int(input())
	l = [int(k) for k in input().split()]
	print(f(l, n))
	T -= 1


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	cnt = 0
	i = 0
	while not A[i]:
		cnt += 1
		i += 1
	i = n - 1
	while not A[i]:
		cnt += 1
		i -= 1
	print(A.count(0) - cnt)


import sys
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, sys.stdin.readline().split()))
	j = 0
	while j < n:
		if a[j] == 1:
			break
		j = j + 1
	k = n - 1
	while k >= 0:
		if a[k] == 1:
			break
		k = k - 1
	p = a[j:k + 1].count(0)
	print(p)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = a[::-1]
	if a.count(1) < 2:
		print(0)
		continue
	p = a.index(1)
	q = n - 1 - b.index(1)
	if q - p < 2:
		print(0)
	else:
		c = a[p:q + 1]
		print(c.count(0))


def solve(n):
	p = input().split()
	s = []
	cnt = 0
	for i in range(n):
		if p[i] == '0':
			cnt += 1
		elif p[i] == '1' and cnt != 0:
			s.append(cnt)
			cnt = 0
		if p[i] == '1' and (len(s) == 0 or s[-1] != 0):
			s.append(0)
	if p[0] == '0':
		del s[0]
	print(sum(s))
for _ in range(int(input())):
	n = int(input())
	solve(n)


t = 1
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	one1 = one2 = False
	(ind1, ind2) = (-1, -1)
	c1 = c2 = 0
	cnt = 0
	for i in range(n):
		if arr[i] == 1 and ind1 == -1:
			ind1 = ind2 = i
		if arr[i] == 1 and ind1 != -1:
			ind2 = i
	for i in range(ind1 + 1, ind2):
		if arr[i] == 0:
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	left = lst.index(1)
	right = len(lst) - 1 - lst[::-1].index(1)
	if left == right:
		print(0)
	else:
		res = 0
		for i in lst[left:right + 1]:
			if i == 0:
				res += 1
		print(res)


def solve(lis):
	z = []
	f = 0
	for i in range(1, len(lis) + 1):
		if lis[i - 1] == 1:
			z.append(i - 1)
	for j in range(2, len(z) + 1):
		f += z[j - 1] - z[j - 2] - 1
	return f
t = int(input())
while t > 0:
	n = int(input())
	lis = list(map(int, input().split()))
	print(solve(lis))
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	c = 0
	for i in range(n):
		if lst[i] == 1:
			a = i
			break
	for j in range(n):
		if lst[n - 1 - j] == 1:
			b = n - 1 - j
			break
	if a == b:
		print('0')
	else:
		for k in range(a, b + 1):
			if lst[k] == 0:
				c += 1
		print(c)


for _ in range(int(input())):
	x = input()
	arr = list(map(int, input().split()))
	while arr[0] == 0:
		arr.pop(0)
	while arr[-1] == 0:
		arr.pop(-1)
	print(arr.count(0))


from collections import deque
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = deque(map(int, input().split()))
	while len(a):
		if a[0] == 0:
			a.popleft()
		elif a[-1] == 0:
			a.pop()
		else:
			break
	print(a.count(0))


def main():
	for _ in range(int(input())):
		size = input()
		k = [int(i) for i in input().split()]
		while k[0] == 0:
			k = k[1:]
		while k[-1] == 0:
			k = k[:-1]
		print(k.count(0))
main()


t = eval(input())
sum = 0
for j in range(t):
	book = input()
	n = input()
	n = n.replace(' ', '')
	n = n.strip('0')
	n = list(n)
	for i in range(len(n) - 1):
		if n[i] != n[i + 1]:
			sum += 1
			(n[i], n[i + 1]) = (n[i + 1], n[i])
	print(sum)
	sum = 0


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	posl = -1
	posr = -1
	for i in range(n):
		if a[i] == 1:
			if posl == -1:
				posl = i
			posr = i
	cnt = 0
	for i in range(posl, posr + 1):
		if a[i] == 0:
			cnt += 1
	print(cnt)


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	books = 0
	for i in range(n):
		if a[i] == '1':
			books += 1
	for i in range(n):
		if a[i] == '1':
			pos = i
			break
	total = 0
	booknum = 0
	for i in range(pos, n):
		if a[i] == '1':
			booknum += 1
			if booknum == books:
				break
		if a[i] == '0':
			total += 1
	print(total)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	cp = -1
	for i in range(n):
		if l[i] == 1:
			if cp == -1:
				cp = i
			else:
				ans += i - cp - 1
				cp = i
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
for _ in range(N()):
	n = int(input())
	a = RLL()
	(l, r) = (a.index(1), a[::-1].index(1))
	print(a[l:-r - 1].count(0))


def con_books(arr):
	if arr.count(1) == 1 or arr.count(1) == 0:
		return 0
	l = []
	count = 0
	m = arr.count(1)
	for i in arr:
		if i == 1:
			l.append(1)
		if l and i == 0 and (l.count(1) != m):
			count += 1
	return count
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(con_books(arr))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	while a[i] != 1:
		i += 1
	j = n - 1
	while a[j] != 1:
		j -= 1
	tot = 0
	for count in range(i, j):
		if a[count] == 0:
			tot += 1
	print(tot)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = a[::-1]
	ones = a.count(1)
	f = a.index(1)
	r = b.index(1)
	print(a[f:n - r].count(0))


a = int(input())
for x in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	h = 0
	t = 0
	k = 0
	for y in c:
		if h == 0:
			if y == 1:
				h = 1
		elif y == 0:
			t += 1
		else:
			k += t
			t = 0
	print(k)


from sys import stdin
n = int(stdin.readline())
for _ in range(n):
	m = int(stdin.readline().strip())
	arr = list(map(int, stdin.readline().strip().split()))
	ones = []
	for i in range(len(arr)):
		if arr[i] == 1:
			ones.append(i)
	ans = 0
	if len(ones) == 0:
		print(0)
	else:
		for i in range(1, len(ones)):
			ans += ones[i] - ones[i - 1] - 1
		print(ans)


def solution():
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	l = -1
	for i in range(n):
		if arr[i] == 1:
			if l == -1:
				l = i
				continue
			else:
				ans += i - l - 1
				l = i
	return ans

def main():
	T = int(input())
	for t in range(1, T + 1):
		print(solution())
main()


import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline

def inar():
	return [int(el) for el in input().split()]

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		arr = inar()
		check = 0
		ans = []
		start = 0
		count = 0
		for i in range(n):
			if arr[i] == 1 and start == 0:
				start = i
				count += 1
				continue
			elif arr[i] == 1 and count > 0:
				count += 1
				continue
			elif count > 0:
				ans.append([start, i - 1])
				count = 0
				start = 0
		if count > 0:
			ans.append([start, i - 1])
			start = 0
		take = 0
		for i in range(1, len(ans)):
			take += ans[i][0] - ans[i - 1][1] - 1
		print(take)
main()


tests = int(input())
answers = []
for test in range(tests):
	n = int(input())
	books = list(map(int, input().split()))
	temp = books[::-1]
	moves = 0
	try:
		left = books.index(1)
	except:
		print(0)
		continue
	try:
		right = temp.index(1)
	except:
		print(0)
		continue
	for i in books[left:n - right]:
		if i == 0:
			moves += 1
	answers.append(moves)
for i in answers:
	print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	op = None
	for (i, c) in enumerate(input().split()):
		if c == '1':
			if op is None:
				op = i
			else:
				ans += i - op - 1
				op = i
	print(ans)


a = int(input())
for i in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	d = 0
	e = 0
	for j in range(b):
		if c[j] == 1:
			d = j
			break
	for j in range(b - 1, -1, -1):
		if c[j] == 1:
			e = j
			break
	f = c[d:e + 1]
	print(f.count(0))


from sys import stdout
from sys import stdin

def get():
	return stdin.readline().strip()

def getf():
	return [int(i) for i in get().split()]

def put(a, end='\n'):
	stdout.write(str(a) + end)

def putf(a, sep=' ', end='\n'):
	stdout.write(sep.join([str(i) for i in a]) + end)

def solve(a, n):
	(x, y) = (n, -1)
	for i in range(n):
		if a[i] == 1:
			x = min(i, x)
			y = i + 1
	return y - x - sum(a[x:y])

def main():
	q = int(get())
	for _ in range(q):
		n = int(get())
		a = getf()
		put(solve(a, n))
main()


R = lambda : map(int, input().split())
for _ in range(int(input())):
	(n,) = R()
	s = input().lstrip('0 ').rstrip(' 0')
	count = s.count('0')
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	x = a.count(1)
	ans = 0
	ind = []
	for i in range(n):
		if a[i] == 1:
			ind.append(i)
	for i in range(1, len(ind)):
		ans += ind[i] - ind[i - 1] - 1
	print(ans)


def getMoves(n, arr):
	ans = 0
	zer = 0
	fl = False
	for i in range(n):
		if arr[i] == 0:
			if fl:
				zer += 1
		if arr[i] == 1:
			ans += zer
			zer = 0
			fl = True
	return int(ans)
t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	val = getMoves(n, arr)
	print(val)


t = int(input())
for tt in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	oneFound = False
	ind = -1
	ans = 0
	for i in range(n):
		if oneFound and a[i] == 1:
			ans += i - ind - 1
			ind = i
		elif not oneFound and a[i] == 1:
			oneFound = 1
			ind = i
	print(ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	ans = 0
	nums = list(map(int, input().strip().split()))
	flag = 0
	count = 0
	for num in nums:
		if num == 0:
			count += 1
		elif num == 1:
			if flag:
				ans += count
			count = 0
			flag = 1
	print(ans)


from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	while len(a) > 0 and a[-1] == 0:
		del a[-1]
	a.reverse()
	while len(a) > 0 and a[-1] == 0:
		del a[-1]
	print(len(a) - sum(a))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	fir = -1
	las = -1
	ans = 0
	for j in range(n):
		if l[j] == 1:
			if fir == -1:
				fir = j
			las = j
	for j in range(fir, las):
		if l[j] == 0:
			ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	shelf = input().split()
	first = shelf.index('1')
	last = ''.join(shelf).rindex('1')
	newShelf = shelf[first:last + 1]
	print(newShelf.count('0'))


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	p = []
	for j in range(n):
		if l[j] == 1:
			p.append(j)
	sum = 0
	a = p[0]
	b = p[len(p) - 1]
	for i in range(a, b + 1):
		if l[i] == 0:
			sum += 1
	print(sum)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	a.append(0)
	ans = 0
	c = -1
	for j in range(n):
		if a[j] == 1:
			c = j
		elif c > -1:
			ans += 1
	print(ans - (n - c - 1))


testCase = int(input())
while testCase:
	testCase -= 1
	q = int(input())
	ar = list(map(int, input().split()))
	first = -1
	last = 55
	for i in range(q):
		if ar[i] == 1:
			first = i
			break
	for i in range(q - 1, -1, -1):
		if ar[i] == 1:
			last = i
			break
	res = 0
	if first < last:
		for i in range(first, last + 1):
			if ar[i] == 0:
				res += 1
	print(res)


import collections
for t in range(int(input())):
	n = int(input())
	nums = collections.deque(map(int, input().split()))
	while nums and nums[0] == 0:
		nums.popleft()
	while nums and nums[-1] == 0:
		nums.pop()
	out = 0
	for i in nums:
		if i == 0:
			out += 1
	print(out)


import math
n = int(input())
for i in range(n):
	m = int(input())
	s = input().split(' ')
	a = []
	for c in s:
		a.append(int(c))
	f = False
	_sum = 0
	_all = 0
	for i in range(m):
		if a[i]:
			_all += _sum
			_sum = 0
			f = True
		if f and (not a[i]):
			_sum += 1
	print(_all)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	while len(a) > 0:
		if a[0] == 1:
			break
		else:
			a.pop(0)
	while len(a) > 0:
		if a[-1] == 1:
			break
		else:
			a.pop(-1)
	print(len(a) - sum(a))


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	ones = a.count(1)
	if ones == 1:
		print(0)
	else:
		num_of_gaps = 0
		flag = 0
		for a_i in a:
			if flag == 0:
				if a_i == 1:
					ones -= 1
					flag = 1
			elif a_i == 0 and ones != 0:
				num_of_gaps += 1
			elif a_i == 1:
				ones -= 1
		print(num_of_gaps)


import math
test = int(input())
for t in range(test):
	tt = 0
	pp = 0
	cc = ''
	ss = ''
	dd = 1
	cnttt = 0
	n = int(input())
	A = list(map(int, input().split()))
	cnt = 0
	c = 0
	C = []
	for i in range(n):
		if A[i] == 0 and c == 1:
			cnt += 1
		elif A[i] == 1:
			c = 1
			if cnt != 0:
				C.append(cnt)
			cnt = 0
	ans = 0
	for i in C:
		ans += i
	print(ans)


t = int(input())
for q in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	while i < n and l[i] == 0:
		i += 1
	j = n - 1
	while j >= 0 and l[j] == 0:
		j -= 1
	ct = l.count(1)
	if ct == 0:
		print(0)
	elif ct == 1:
		print(0)
	else:
		c = 0
		for k in range(i + 1, j):
			if l[k] == 0:
				c += 1
		if c != 0:
			print(c)
		else:
			print(0)


for testcase in range(int(input())):
	shelf_capacity = int(input())
	bookshelf = list(map(int, input().split()))
	count_1s = 0
	indices_0s = []
	indices_1s = []
	for index in range(shelf_capacity):
		if bookshelf[index] == 1:
			count_1s += 1
			indices_1s.append(index)
		else:
			indices_0s.append(index)
	if count_1s < 2:
		print(0)
	else:
		starting_index = indices_1s[0]
		ending_index = indices_1s[-1]
		count_0s = 0
		for ranged_index in range(starting_index + 1, ending_index):
			if bookshelf[ranged_index] == 0:
				count_0s += 1
		print(count_0s)


def lis():
	return list(map(int, input().split()))
for _ in range(int(input())):
	y = int(input())
	x = lis()
	for i in range(len(x)):
		if x[i] == 1:
			break
	z = 0
	for i in range(i, len(x)):
		if x[i] == 0:
			z += 1
	x.reverse()
	for i in range(len(x)):
		if x[i] == 1:
			break
	print(z - i)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(str, input().split()))
	arr = ''.join(arr)
	leftmostOne = arr.find('1')
	rightmostOne = arr.rfind('1')
	ans = 0
	for i in range(leftmostOne, rightmostOne + 1):
		if arr[i] == '0':
			ans += 1
	print(ans)


def bookshelf(arr):
	zeros = 0
	last_one = -1
	for (idx, val) in enumerate(arr):
		if val == 1:
			if last_one != -1:
				zeros += idx - last_one - 1
			last_one = idx
	return zeros
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(bookshelf(arr))


t = int(input())
res = [0 for i in range(0, t)]
i = 0
while i < t:
	n = int(input())
	a = list(map(int, input().split()))
	a1 = []
	pos = []
	firstOne = False
	for _ in range(0, len(a)):
		if a[_] == 1:
			pos.append(_)
	if len(pos) < 2:
		res[i] = 0
	else:
		for _ in range(pos[0], pos[len(pos) - 1] + 1):
			a1.append(a[_])
			_ += 1
		amMoves = 0
		_ = 0
		while _ < len(a1):
			while _ < len(a1) and a1[_] == 0:
				amMoves += 1
				_ += 1
			while _ < len(a1) and a1[_] == 1:
				_ += 1
		res[i] = amMoves
	i += 1
for i in range(0, t):
	print(res[i])


def read_generator():
	while True:
		tokens = input().split(' ')
		for t in tokens:
			yield t
reader = read_generator()

def readword():
	return next(reader)

def readint():
	return int(next(reader))

def readfloat():
	return float(next(reader))

def readline():
	return input()

def solve(a):
	l = 0
	r = len(a) - 1
	while l <= r and a[l] == 0:
		l += 1
	while r >= l and a[r] == 0:
		r -= 1
	res = 0
	while l < r:
		if a[l] == 0:
			res += 1
		l += 1
	return res
tests = readint()
for t in range(tests):
	n = readint()
	a = [readint() for _ in range(n)]
	print(solve(a))


def Bitplus():
	n = int(input())
	x = 0
	for i in range(n):
		a = input()
		if '+' in a:
			x += 1
		else:
			x -= 1
	print(x)

def GiftSetidk():
	n = int(input())
	for i in range(n):
		all = input().split(' ')
		x = int(all[0])
		y = int(all[1])
		a = int(all[2])
		b = int(all[3])
		counter = 0
		count = True
		while count:
			if x >= a and y >= b:
				x -= a
				y -= b
				counter += 1
			elif x >= b and y >= a:
				x -= b
				y -= a
				counter += 1
			else:
				count = False
		print(counter)

def Team():
	n = int(input())
	problemcount = 0
	for i in range(n):
		count = 0
		answer = input().split(' ')
		for i in range(len(answer)):
			answer[i] = int(answer[i])
		for i in answer:
			if i == 1:
				count += 1
		if count >= 2:
			problemcount += 1
	print(problemcount)

def NextRound():
	nk = input().split(' ')
	n = int(nk[0])
	k = int(nk[1])
	print(n, k)
	scores = input().split(' ')
	count = 0
	for i in range(n):
		scores[i] = int(scores[i])
	five = scores[k]
	for i in range(n):
		if scores[i] >= five and scores[i] > 0:
			count += 1
	print(count)

def Beautifulmatrix():
	steps = 0
	matrixes = []
	for i in range(5):
		i = [input().split(' ')]
		matrixes += i
	for i in range(5):
		for j in range(5):
			matrixes[i][j] = int(matrixes[i][j])
	for i in range(5):
		for j in range(5):
			if matrixes[i][j] > 0:
				x = j
				y = i
				break
	while x != 2 or y != 2:
		if x > 2:
			x -= 1
			steps += 1
		elif x < 2:
			x += 1
			steps += 1
		elif y > 2:
			y -= 1
			steps += 1
		elif y < 2:
			y += 1
			steps += 1
	print(steps)

def HelpfulMahts():
	s = input().split('+')
	s.sort()
	print('+'.join(s))

def WordCapitalization():
	word = input()
	List = []
	for i in word:
		List.append(i)
	List[0] = List[0].upper()
	s = ''
	for i in List:
		s += i
	print(s)

def Stonesonthetable():
	n = int(input())
	stones = []
	rrg = input()
	counter = 0
	for i in rrg:
		stones.append(i)
	for i in range(n - 1):
		if stones[i] == stones[i + 1]:
			counter += 1
	print(counter)

def BearandBigBrother():
	inpuut = input().split(' ')
	a = int(inpuut[0])
	b = int(inpuut[1])
	year = 0
	while a <= b:
		a *= 3
		b *= 2
		year += 1
	print(year)

def Wrongsubtraction():
	nk = input().split(' ')
	n = int(nk[0])
	k = int(nk[1])
	for i in range(k):
		p = str(n)
		if p[len(p) - 1] == '0':
			n //= 10
		else:
			n -= 1
	print(n)
import string

def Word():
	word = input()
	lower = 0
	upper = 0
	for i in word:
		if i in string.ascii_lowercase:
			lower += 1
		else:
			upper += 1
	if upper > lower:
		word = word.upper()
	else:
		word = word.lower()
	print(word)

def QueueattheSchool():
	nt = input().split(' ')
	n = nt[0]
	t = int(nt[1])
	a = input()
	b = []
	ref = ''
	for i in a:
		b.append(i)
	for k in range(t):
		whre = []
		for i in range(len(b) - 1):
			if b[i] == 'B' and b[i + 1] != 'B':
				whre.insert(0, i)
		for j in whre:
			b.pop(j)
			b.insert(j + 1, 'B')
	for i in b:
		ref += i
	print(ref)

def Nearlyluckynumber():
	n = input()
	if n.count('7') + n.count('4') == 7 or n.count('7') + n.count('4') == 4:
		print('YES')
	else:
		print('NO')

def Translation():
	s = input()
	t = input()
	n = []
	for i in t:
		n.insert(0, i)
	t = ''
	for i in n:
		t += i
	if t == s:
		print('YES')
	else:
		print('NO')

def ANTONandDanik():
	n = int(input())
	s = input()
	A = s.count('A')
	D = s.count('D')
	if A > D:
		print('Anton')
	elif D > A:
		print('Danik')
	else:
		print('Friendship')

def GeorgeandAccomodation():
	n = int(input())
	rooms = 0
	for i in range(n):
		pq = input().split(' ')
		p = int(pq[0])
		q = int(pq[1])
		if q - p >= 2:
			rooms += 1
	print(rooms)

def Magnets():
	n = int(input())
	Rows = []
	groups = 1
	for i in range(n):
		Rows += [input()]
	for i in range(n - 1):
		if Rows[i] != Rows[i + 1]:
			groups += 1
	print(groups)

def InSearcoanEasyProblem():
	n = int(input())
	counter = 0
	s = input().split(' ')
	if '1' in s:
		print('HARD')
	else:
		print('EASY')

def Hulk():
	c = int(input())
	i = 'I'
	s = ''
	it = 'it'
	for i in range(1, c + 1):
		if i == 1:
			s += 'hate '
		elif i % 2 == 0:
			s += 'that I love '
		else:
			s += 'that I hate '
	print(f'I {s}it')

def CalculatingFunctionidk():
	n = int(input())
	c = 0
	for i in range(1, n + 1):
		if i % 2 != 0:
			c -= i
		else:
			c += i
	print(c)

def IWannaBetheGuyidk():
	n = int(input())
	p = input().split(' ')
	q = input().split(' ')
	counter = 0
	for i in range(1, n + 1):
		if str(i) in p or str(i) in q:
			counter += 1
	if counter == n:
		print('I become the guy.')
	else:
		print('Oh, my keyboard!')

def horsesheo():
	n = input().split(' ')
	many = 4
	whatwas = []
	for i in range(len(n)):
		n[i] = int(n[i])
		if n[i] not in whatwas:
			whatwas.append(n[i])
	print(many - len(whatwas))

def ArrivaloftheGeneralidk():
	n = int(input())
	a = input().split(' ')
	max = 0
	minlist = []
	for i in range(n):
		a[i] = int(a[i])
	for i in a:
		if i > max:
			max = i
	maxloc = a.index(max)
	for i in a:
		minlist.insert(0, i)
	min = max
	for i in a:
		if i < min:
			min = i
	minloc = minlist.index(min)
	print(minloc + maxloc)

def UltraFastMathematician():
	first = input()
	second = input()
	s = ''
	for i in range(len(first)):
		if first[i] == '0' and second[i] == '1':
			s += '1'
		elif first[i] == '1' and second[i] == '0':
			s += '1'
		elif first[i] == '0' and second[i] == '0':
			s += '0'
		elif first[i] == '1' and second[i] == '1':
			s += '0'
	print(s)

def Insomniacure():
	klmn = []
	for i in range(4):
		klmn.append(int(input()))
	d = int(input())
	List = []
	if 1 in klmn:
		return d
	for i in range(4):
		mulit = klmn[i]
		while klmn[i] <= d:
			if klmn[i] not in List:
				List.append(klmn[i])
			klmn[i] += mulit
	return len(List)

def AntonandLetters():
	first = input()
	List = []
	for i in first:
		if i not in List and i in string.ascii_lowercase:
			List.append(i)
	print(len(List))

def Pangram():
	n = int(input())
	word = input().lower()
	List = []
	if n >= 26:
		for i in word:
			if i not in List:
				List.append(i)
		if len(List) == 26:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')

def Collectingcoons():
	n = int(input())
	for i in range(n):
		abcd = input().split(' ')
		for i in range(len(abcd)):
			abcd[i] = int(abcd[i])
		d = abcd[3]
		abcd.pop()
		maxi = 0
		for i in abcd:
			if i > maxi:
				maxi = i
		allindexes = [0, 1, 2]
		indexmax = abcd.index(maxi)
		allindexes.pop(indexmax)
		allminus = 0
		for i in allindexes:
			allminus += abcd[indexmax] - abcd[i]
		d -= allminus
		if d % 3 == 0 and d >= 0:
			print('YES')
		else:
			print('NO')

def Brainsphotos():
	nm = input().split(' ')
	colors = []
	for i in range(int(nm[0])):
		colors += input().split(' ')
	for i in colors:
		if i == 'C' or i == 'M' or i == 'Y':
			return '#Color'
	return '#Black&White'

def SerejaandDima():
	n = int(input())
	card = input().split(' ')
	S = 0
	D = 0
	sturn = True
	for i in range(n):
		if int(card[0]) > int(card[len(card) - 1]):
			if sturn:
				S += int(card[0])
				card.pop(0)
				sturn = False
			else:
				D += int(card[0])
				card.pop(0)
				sturn = True
		elif sturn:
			S += int(card[len(card) - 1])
			card.pop(len(card) - 1)
			sturn = False
		else:
			D += int(card[len(card) - 1])
			card.pop(len(card) - 1)
			sturn = True
	print(f'{S} {D}')

def Vanyaandcubes():
	n = int(input())
	counter = 1
	countdodo = 0
	rows = 0
	while n > 0:
		countdodo += counter
		counter += 1
		rows += 1
		n -= countdodo
	if n == 0:
		print(rows)
	else:
		print(rows - 1)

def GennadyandaCarGame():
	card = input()
	cards = input().replace(' ', '')
	for i in card:
		for j in cards:
			if i == j:
				return 'YES'
	return 'NO'

def FafaandhisCompany():
	n = int(input())
	ways = 0
	for i in range(1, n):
		a = n
		a -= i
		if a % i == 0:
			ways += 1
	print(ways)

def Mahmoudandehabandtheevenoddgame():
	n = int(input())
	Mahmoudsturn = True
	Mahmoudlsot = False
	Ehablost = False
	a = 0
	while not Mahmoudlsot and (not Ehablost):
		if Mahmoudsturn:
			if n % 2 == 0 and n >= 2:
				Ehablost = True
			elif n % 2 != 0 and n >= 2:
				a = n - 1
			else:
				Mahmoudlsot = True
		elif n % 2 == 1 and n >= 1:
			Mahmoudlsot = True
		elif n % 2 == 0 and n >= 1:
			a = n - 1
		else:
			Ehablost = False
		n -= a
		if Mahmoudsturn == True:
			Mahmoudsturn = False
		else:
			Mahmoudsturn = True
	if Mahmoudlsot == True:
		print('Ehab')
	else:
		print('Mahmoud')

def FloorNumber():
	t = int(input())
	for i in range(t):
		nx = input().split(' ')
		n = int(nx[0])
		x = int(nx[1])
		aparteements = 2
		floor = 1
		while n > aparteements:
			aparteements += x
			floor += 1
		print(floor)

def VustheCossackandaContest():
	nmk = input().split(' ')
	n = int(nmk[0])
	m = int(nmk[1])
	k = int(nmk[2])
	if n <= m and n <= k:
		print('Yes')
	else:
		print('No')

def NightattheMuseum():
	word = input()
	rotations = 0
	lower = string.ascii_lowercase + string.ascii_lowercase + string.ascii_lowercase
	loc = lower.index('a', 26, 2 * 26)
	for i in word:
		cplus = loc
		cminus = loc
		keep = True
		while keep:
			if i == lower[cplus] or i == lower[cminus]:
				keep = False
			else:
				cplus += 1
				cminus -= 1
				rotations += 1
				loc = lower.index(i, 26, 2 * 26)
	print(rotations)

def OrdinarYnumbers():
	n = int(input())
	for i in range(n):
		k = int(input())
		counter = 0
		for j in range(1, k + 1):
			a = str(j)
			if len(a) == a.count(a[0]):
				counter += 1
		print(counter)

def DieRoll():
	n = input().split(' ')
	y = int(n[0])
	w = int(n[1])
	number = 0
	dec = 6
	if y >= w:
		for i in range(y, 7):
			number += 1
	else:
		for i in range(w, 7):
			number += 1
	if number % 6 == 0:
		number = number // 6
		dec = 1
	elif number % 3 == 0:
		number = number // 3
		dec = 2
	elif number % 2 == 0:
		number = number // 2
		dec = 3
	print(f'{number}/{dec}')

def Borze():
	n = input()
	l = ''
	k = ''
	for i in n:
		if i == '.' and len(l) == 0:
			k += '0'
		else:
			l += i
			if len(l) == 2:
				if l == '-.':
					k += '1'
					l = ''
				else:
					k += '2'
					l = ''
	print(k)

def FairPlayoff():
	n = int(input())
	for i in range(n):
		loser = {}
		winner = {}
		count = 0
		k = input().split(' ')
		if int(k[0]) > int(k[1]):
			loser['one'] = int(k[1])
			winner['two'] = int(k[0])
		else:
			loser['one'] = int(k[0])
			winner['two'] = int(k[1])
		if int(k[2]) > int(k[3]):
			loser['two'] = int(k[3])
			winner['one'] = int(k[2])
		else:
			loser['two'] = int(k[2])
			winner['one'] = int(k[3])
		for i in loser:
			if loser[i] < winner[i]:
				count += 1
		if count >= 2:
			print('YES')
		else:
			print('NO')

def Bustoudaylanbd():
	n = int(input())
	s = []
	rem = -1
	first = True
	ss = ''
	for i in range(n):
		s += input().split('|')
	for i in range(len(s)):
		if s[i] == 'OO' and first:
			rem = i
			s[i] = '++'
			first = False
	for i in range(len(s)):
		if i % 2 == 0:
			ss += s[i] + '|'
		else:
			ss += s[i] + '\n'
	if not first:
		print('YES')
		print(ss)
	else:
		print('NO')

def Maximumincrease():
	n = int(input())
	arraa = input().split(' ')
	for i in range(len(arraa)):
		arraa[i] = int(arraa[i])
	counter = {}
	for i in range(n):
		counter[i] = 0
	count = 0
	last = 0
	for i in arraa:
		if i > last:
			last = i
			counter[count] += 1
		else:
			last = i
			count += 1
			counter[count] += 1
	max = 0
	for i in range(n):
		if counter[i] > max:
			max = counter[i]
	print(max)

def Jugglingletters():
	n = int(input())
	for i in range(n):
		k = int(input())
		s = ''
		map = {}
		possible = True
		for i in range(k):
			s += input()
		for i in s:
			if i not in map:
				map[i] = 1
			else:
				map[i] += 1
		for i in map:
			if map[i] % k != 0:
				possible = False
		if possible:
			print('YES')
		else:
			print('NO')

def Panoramixsprediction():
	nm = input().split(' ')
	n = int(nm[0])
	m = int(nm[1])
	first = True
	for i in range(n + 1, m):
		count = 0
		for j in range(2, i):
			if i % j == 0:
				count += 1
		if count == 0:
			first = False
			break
	if first:
		count = 0
		for j in range(2, m):
			if m % j == 0:
				count += 1
		if count == 0:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')

def ThreepilesofCanides():
	k = int(input())
	for i in range(k):
		n = input().split(' ')
		canides = 0
		for i in n:
			canides += int(i)
		if canides % 2 != 0:
			canides -= 1
		print(canides // 2)

def filename():
	n = int(input())
	name = input()
	more = 0
	map = {}
	map[more] = 0
	count = 0
	for i in name:
		if i == 'x':
			map[more] += 1
		elif map[more] != 0:
			more += 1
			map[more] = 0
	for i in map:
		if map[i] >= 3:
			while map[i] > 2:
				map[i] -= 1
				count += 1
	print(count)

def Football():
	map = {}
	current = 0
	s = input()
	f = s[0]
	map[current] = 0
	check = False
	for i in s:
		if i == f:
			map[current] += 1
		else:
			current += 1
			map[current] = 1
			f = i
	for i in map:
		if map[i] >= 7:
			check = True
	if check:
		print('YES')
	else:
		print('NO')

def CombinationLock():
	n = int(input())
	fl = input()
	sl = input()
	count = 0
	for i in range(n):
		goup = int(fl[i])
		god = int(fl[i])
		cu = 0
		cd = 0
		keep = True
		while keep:
			if goup + 1 <= 9:
				goup += 1
				cu += 1
			else:
				goup = 0
				cu += 1
			if god - 1 >= 0:
				god -= 1
				cd += 1
			else:
				god = 9
				cd += 1
			if goup == int(sl[i]):
				count += cu
				keep = False
			elif god == int(sl[i]):
				count += cd
				keep = False
	print(count)

def Watermelon():
	n = int(input())
	down = n // 2
	up = n - down
	rge = up
	for i in range(rge):
		if up % 2 == 0 and down % 2 == 0:
			return print('YES')
		elif up + 1 < n and down - 1 > 0:
			up += 1
			down -= 1
		else:
			return print('NO')

def Dominopiling():
	nk = input().split(' ')
	n = int(nk[0])
	k = int(nk[1])
	mnk = n * k
	print(mnk // 2)

def yetanotherBookshelf():
	n = int(input())
	for i in range(n):
		le = int(input())
		K = input().split(' ')
		SK = []
		lili = []
		for i in range(le):
			if i + 1 <= le - 1:
				if K[i] == '1' and K[i + 1] == '1':
					lili.append(i)
		lili.reverse()
		for i in lili:
			K.pop(i)
		coun = 0
		while K.count('1') > 1:
			f = K.index('1')
			K.pop(f)
			K.insert(f + 1, '1')
			f += 1
			if K[f + 1] == '1':
				K.pop(f)
			coun += 1
		print(coun)
yetanotherBookshelf()


from sys import stdin
for _ in range(int(stdin.readline())):
	leng = int(stdin.readline())
	array = list(map(int, stdin.readline().split()))
	start = 0
	end = leng
	ans = 0
	for i in range(leng):
		if array[i] == 1:
			start = i
			break
	for i in range(leng - 1, -1, -1):
		if array[i] == 1:
			end = i
			break
	for i in range(start, end + 1):
		if array[i] == 0:
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	flag = 0
	num = 0
	rem = 0
	for a in range(len(l)):
		if l[a] == 1:
			flag = 1
		if flag == 1 and l[a] == 0:
			rem += 1
		elif flag == 1 and l[a] == 1:
			num += rem
			rem = 0
	print(num)


for _ in range(int(input())):
	n = int(input())
	b = input()
	a = list(map(int, b.split()))
	if sum(a) == 1:
		print(0)
	else:
		print(b[b.index('1') + 2:2 * n - b[::-1].index('1')].count('0'))


n1 = int(input())
for i in range(n1):
	c = 0
	n = int(input())
	a = input().split(' ')
	b = ''.join(a)
	a = b.split('1')
	for j in range(1, len(a) - 1):
		if a[j] != '':
			c += len(a[j])
	print(c)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = ''
	for i in l:
		s += str(i)
	s = s.strip('0')
	c = 0
	for i in s:
		if i == '0':
			c += 1
	print(c)


def func(n, arr):
	first = -1
	last = -1
	for i in range(n):
		if arr[i] == 1:
			first = i
			break
	for i in range(n):
		if arr[-i - 1] == 1:
			last = -i - 1
			break
	if first == -1:
		print(0)
	ans = arr[first:last].count(0)
	print(ans)
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	func(n, arr)


t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in l:
		d[i] = d.get(i, 0) + 1
	f = l.index(1)
	l.reverse()
	f = n - l.index(1) - f
	print(f - d[1])


for _ in range(int(input())):
	n = input()
	print(input().replace(' ', '').strip('0').count('0'))


answers = []
test_cases = int(input())
for i in range(test_cases):
	length = int(input())
	user_input = input().split()
	ones = []
	zeros = []
	count = 0
	for j in range(len(user_input)):
		if user_input[j] == '1':
			ones.append(j)
		else:
			zeros.append(j)
	if len(ones) == 1 and (ones[0] == '0' or ones[0] == str(len(user_input) - 1)):
		answers.append(0)
	elif len(zeros) == 0 or len(ones) == 0:
		answers.append(0)
	else:
		for k in range(len(zeros)):
			if ones[0] < zeros[k] < ones[len(ones) - 1]:
				count += 1
		answers.append(count)
for m in answers:
	print(m)


for t in [0] * int(input()):
	mvs = 0
	n = int(input())
	bs = list(map(int, input().split()))
	ai = 0
	ls = False
	(l, r) = (0, 0)
	while ai < n:
		if bs[ai] == 1 and (not ls):
			l = ai
			ls = True
		if bs[ai] == 0 and ls:
			if bs[ai:n].count(1) >= 1:
				mvs += 1
			else:
				break
		ai += 1
	print(mvs)


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().strip().split()))
	revli = list(reversed(li))
	first1 = li.index(1)
	last1 = li[::-1].index(1)
	print(li[first1:n - last1].count(0))


n = int(input())
for i in range(n):
	m = int(input())
	shelf = [int(q) for q in input().split()]
	st = False
	res = 0
	s = 0
	for j in range(m):
		if not st and shelf[j] == 1:
			st = True
		elif st and shelf[j] == 0:
			s += 1
		elif st and shelf[j]:
			res += s
			s = 0
	print(res)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = False
	pos = 0
	ans = 0
	for i in range(n):
		if a[i] == 1 and (not b):
			pos = i
			b = True
		elif a[i] == 1 and b:
			ans += i - pos - 1
			pos = i
	print(ans)


from collections import deque
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	n = int(input())
	arr = deque(list(map(int, input().split())))
	while not arr[0]:
		arr.popleft()
	while not arr[-1]:
		arr.pop()
	print(arr.count(0))


test_cases = int(input())
res = []
for test in range(test_cases):
	n = int(input())
	st = input()
	lst = st.split()
	lo = -1
	count = 0
	res_val = 0
	for i in range(len(lst)):
		if lst[i] == '1':
			if lo == -1:
				lo = i
			else:
				res_val = count
		elif lo != -1:
			count += 1
	res.append(res_val)
for test in range(test_cases):
	print(res[test])


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(1, inp() + 1):
	n = inp()
	x = ip()
	ans = 0
	if x.count(1) < 2:
		print(ans)
		continue
	t = 0
	for i in range(x.index(1), n):
		if x[i] == 1:
			ans += t
			t = 0
		else:
			t += 1
	print(ans)


def ge4_shu4_0(l0):
	a = 0
	for i in range(len(l0)):
		if l0[i] == 0:
			a = a + 1
	return a

def shu_wei4_qd(l1):
	s = []
	for i in range(len(l1)):
		if l1[i] == 1:
			s.append(i)
	return s

def zx_wei4(l2):
	s = 0
	for j in range(len(l2)):
		s = s + abs(l2[j] - l2[0])
	zx = s
	index = l2[0]
	for i in range(1, len(l2)):
		s = 0
		for j in range(len(l2)):
			s = s + abs(l2[j] - l2[i])
		if s < zx:
			zx = s
			index = l2[i]
	return index
pnums = int(input())
L = []
for i in range(pnums):
	n = int(input())
	L.append([])
	c = input()
	S = c.split(' ')
	S = [int(e) for e in S]
	L[i] = L[i] + S
for e in L:
	move_n = 0
	SW = shu_wei4_qd(e)
	T = e[SW[0]:SW[len(SW) - 1]]
	move_n = ge4_shu4_0(T)
	print(move_n)


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log
from collections import Counter
from pprint import pprint
from itertools import combinations

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	l = r = -1
	for i in range(n):
		if l == -1 and arr[i]:
			l = i
		if arr[i]:
			r = i
	print(r - l + 1 - sum(arr))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	main()


t = input()
for i in range(int(t)):
	k = 0
	n = input()
	ch = input()
	L = [int(i) for i in ch.split()]
	p = 0
	test = False
	while p < int(n) - 1:
		if L[p] == 1:
			nb = 0
			for j in range(p + 1, int(n)):
				if int(L[j]) == 1:
					p = j
					break
				if j == int(n) - 1:
					p = j
					test = True
					break
				nb += 1
			if test == False:
				k += nb
		else:
			p += 1
	print(k)


def solve():
	n = int(input())
	arr = [int(v) for v in input().split()]
	while len(arr) and arr[0] == 0:
		arr.pop(0)
		n -= 1
	while len(arr) and arr[-1] == 0:
		arr.pop(-1)
		n -= 1
	print(n - sum(arr))
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	aa = list(map(int, input().split()))
	(k, l, r) = (0, 0, 0)
	for a in aa:
		k += a == 0
	for a in aa:
		if a != 0:
			break
		l += 1
	for a in reversed(aa):
		if a != 0:
			break
		r += 1
	print(k - l - r)


for i in range(int(input())):
	int(input())
	a = [int(x) for x in input().split()]
	x = 0
	y = 0
	d = []
	c = []
	for i in range(len(a)):
		if a[i] == 1:
			c = i
			y = y + 1
			if y > 1:
				d.append(c - x - 1)
			x = c
	print(sum(d))


for _ in range(int(input())):
	n = int(input())
	arr = [int(ele) for ele in input().split()]
	count = 0
	ans = list()
	for i in range(len(arr)):
		if arr[i] == 1:
			ans.append(i)
	for i in range(len(ans) - 1):
		count += ans[i + 1] - ans[i] - 1
	print(count)


def yet_another_bookshelf(book_sequence):
	str_book_sequence = ''
	for i in book_sequence:
		str_book_sequence += str(i)
	str_book_sequence = str_book_sequence.strip('0')
	return str_book_sequence.count('0')
t = int(input())
for i in range(t):
	n = int(input())
	book_sequence = [int(x) for x in input().split()]
	print(yet_another_bookshelf(book_sequence))


import sys
T = int(sys.stdin.readline())
for i in range(T):
	N = int(sys.stdin.readline())
	nums = list(map(int, sys.stdin.readline().split()))
	while True:
		if nums[0] == 0:
			del nums[0]
		if nums[-1] == 0:
			del nums[-1]
		if nums[0] == 1 and nums[-1] == 1:
			break
	print(nums.count(0))


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	res = 0
	temp = 0
	for i in range(1, n):
		if A[i] == 0 and A[i - 1] == 1:
			temp += 1
		if temp != 0 and A[i] == 0 and (A[i - 1] == 0):
			temp += 1
		if A[i] == 1 and A[i - 1] == 0:
			res += temp
			temp = 0
	print(res)


def how_many_times(a):
	times = 0
	start = 0
	end = 0
	for i in a:
		if i == 1:
			break
		start += 1
	for i in a[::-1]:
		if i == 1:
			break
		end += 1
	end = len(a) - end
	for i in a[start:end]:
		if i == 0:
			times += 1
	return times
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(how_many_times(a))


import sys
import math
from collections import Counter
from collections import OrderedDict
from functools import reduce
sys.setrecursionlimit(10 ** 6)

def inputt():
	return sys.stdin.readline().strip()

def printt(n):
	sys.stdout.write(str(n) + '\n')

def listt():
	return [int(i) for i in inputt().split()]

def gcd(a, b):
	return math.gcd(a, b)

def lcm(a, b):
	return a * b // gcd(a, b)

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = int(inputt())
for _ in range(t):
	n = int(inputt())
	s = listt()
	count = 0
	index1 = 0
	index2 = n - 1
	g = s[::-1]
	index1 = s.index(1)
	for i in g:
		if i == 0:
			index2 -= 1
		else:
			break
	g = s[index1:index2 + 1]
	count = g.count(0)
	print(count)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	ans = 0
	fir = end = i = 0
	j = n - 1
	while lis[i] != 1:
		i += 1
	while lis[j] != 1:
		j -= 1
	for _ in range(i, j):
		if lis[_] == 0:
			ans += 1
	print(ans)


def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		f = a.index(1)
		l = -1
		for i in range(n - 1, -1, -1):
			if a[i] == 1:
				l = i
				break
		ans = 0
		for i in range(f, l):
			if a[i] == 0:
				ans += 1
		print(ans)
main()


n = int(input(''))
l3 = []
for i in range(n):
	n1 = int(input(''))
	s = input('')
	l = s.split(' ')
	l = list(map(int, l))
	a = l.index(1)
	l1 = l[::-1]
	b = len(l) - l1.index(1)
	l2 = l[a:b]
	l3.append(l2.count(0))
print(*l3, sep='\n')


for ii in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	left = 0
	right = 0
	for i in range(n):
		if lst[i] == 1:
			left = i
			break
	for i in range(n - 1, -1, -1):
		if lst[i] == 1:
			right = i
			break
	if left == right:
		print(0)
		continue
	print(lst[left:right + 1].count(0))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = 0
	while a[l] == 0 and l <= n - 1:
		l += 1
	if l == n:
		print(0)
		continue
	k = 1
	while a[-k] == 0 and k <= n - l:
		k += 1
	if k == n - l:
		print(0)
		continue
	else:
		ans = 0
		r = n - k
		for i in range(l, r + 1):
			if a[i] == 0:
				ans += 1
		print(ans)


def bookshelf(books):
	i = 0
	for book in books:
		if book == '0':
			i += 1
	print(i)

def remove_front_and_back(books):
	first_index = books.index('1')
	for x in range(len(books)):
		index = -(x + 1)
		if books[index] == '1':
			return books[first_index:index]
for x in range(int(input())):
	throw = input()
	bookshelf_input = input().split(' ')
	if sum([*map(int, bookshelf_input)]) < 2:
		print(0)
	else:
		bookshelf(remove_front_and_back(bookshelf_input))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	arr = []
	for i in range(n):
		if l[i] == 1:
			arr.append(i)
	ans = 0
	for i in range(1, len(arr)):
		ans += arr[i] - arr[i - 1] - 1
	print(ans)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	add = 0
	flag = 2
	for i in range(n):
		if a[i] == 0 and flag == 0:
			count += 1
		if a[i] == 1:
			add += count
			count = 0
			flag = 0
	print(add)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	(s, c) = (0, 0)
	for i in range(a.index(1) + 1, n):
		if a[i] == 1:
			s += c
			c = 0
		else:
			c += 1
	print(s)


for _ in range(int(input())):
	j = int(input())
	x = list(map(int, input().split()))
	c = 0
	n = 0
	count = 0
	for i in range(len(x)):
		if x[i] == 0 and c == 0:
			continue
		if x[i] == 1 and c == 0:
			c = 1
			continue
		if x[i] == 0 and c == 1:
			n += 1
			continue
		if x[i] == 1 and c == 1:
			count += n
			n = 0
			continue
	print(count)


import sys

def read(func=int):
	return func(sys.stdin.readline().strip())

def readList(func=int):
	return list(map(func, sys.stdin.readline().strip().split()))
t = read()
for _ in range(t):
	n = read()
	A = readList()
	ri = -1
	for i in range(n - 1, -1, -1):
		if A[i]:
			ri = i
			break
	count = 0
	start = False
	for i in range(n):
		num = A[i]
		if num == 1:
			start = True
		if num == 0 and start and (i < ri):
			count += 1
	print(count)


import sys
for _ in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	arr = [int(i) for i in input().split()]
	out = []
	for i in range(len(arr)):
		if arr[i] == 1:
			out.append(i + 1)
	minn = out[0] - 1
	maxx = out[-1]
	cnt = arr.count(1)
	print(maxx - minn - cnt)


t = int(input())
for T in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(n):
		if l[i] == 1:
			x = i
			break
	for j in range(n - 1, -1, -1):
		if l[j] == 1:
			y = j
			break
	nl = l[x:y + 1]
	c = 0
	for k in range(y - x):
		if nl[k] == 0:
			c += 1
	print(c)


def solve(arr, n):
	count = 0
	x = 0
	y = 0
	for i in range(n):
		if arr[i] == 1:
			x = i
			break
	for i in reversed(range(n)):
		if arr[i] == 1:
			y = i
			break
	count = arr[x:y + 1].count(0)
	return count
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve(arr, n))


for i in range(int(input())):
	n = int(input())
	l = list(map(str, input().split()))
	s = ''.join(l)
	a = s[s.find('1'):s.rfind('1') + 1]
	b = 0
	for k in a:
		if k == '0':
			b = b + 1
	print(b)


t = int(input())
for y in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	count = 0
	i = 0
	while i < n and A[i] == 0:
		i += 1
	j = n - 1
	while j >= 0 and A[j] == 0:
		j -= 1
	for i in range(i, j + 1):
		if A[i] == 0:
			count += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	f = -1
	for i in range(n):
		if a[i] == 1:
			f = i
			break
	l = -1
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			l = i
			break
	if f == l or f == -1:
		print(0)
	else:
		coun = 0
		for i in range(f, l):
			if a[i] == 0:
				coun += 1
		print(coun)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(len(l)):
		if l[i] == 1:
			s = i
			break
	temp = l[::-1]
	for i in range(len(temp)):
		if temp[i] == 1:
			e = i
			break
	new_l = l[s:n - e]
	count = 0
	for i in range(len(new_l)):
		if new_l[i] == 0:
			count += 1
	print(count)


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	flag = 0
	v = A.index(1)
	ans = 0
	t = 0
	for i in range(v, n):
		if A[i] == 1 and flag == 0:
			flag = 1
			ans = ans + t
			t = 0
		elif A[i] == 0:
			t = t + 1
			flag = 0
	print(ans)


for _ in range(int(input())):
	z = int(input())
	x = list(map(int, input().split()))
	start = 0
	finish = z - 1
	for a in x:
		if a == 0:
			start += 1
		else:
			break
	x.reverse()
	for b in x:
		if b == 0:
			finish -= 1
		else:
			break
	x.reverse()
	y = x[start:finish + 1]
	count = 0
	for c in y:
		if c == 0:
			count += 1
	print(count)


for _ in range(int(input())):
	s = int(input())
	l = list(map(int, input().split()))
	p = []
	ss = 0
	for x in range(s):
		if l[x] == 1:
			p.append(x + 1)
	for n in range(1, len(p)):
		if p[n] - p[n - 1] != 0:
			ss += p[n] - p[n - 1] - 1
	print(ss)


import os
import sys
from io import BytesIO, IOBase
_str = str
BUFSIZE = 8192

def str(x=b''):
	return x if type(x) is bytes else _str(x).encode()

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def inp():
	return sys.stdin.readline().rstrip()

def mpint():
	return map(int, inp().split(' '))

def itg():
	return int(inp())

def rindex(array, value):
	for i in range(len(array) - 1, -1, -1):
		if array[i] == value:
			return i
	raise ValueError('{} is not in list'.format(value))

def solve():
	n = itg()
	arr = tuple(mpint())
	(lf, rg) = (arr.index(1), rindex(arr, 1))
	return arr[lf:rg].count(0)

def main():
	for _ in range(itg()):
		print(solve())
DEBUG = 0
URL = 'https://codeforces.com/contest/1433/problem/B'
if DEBUG == 1:
	import requests
	from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
	runner = TestCaseRunner(main, URL)
	inp = runner.input_stream
	print = runner.output_stream
	runner.checking()
elif DEBUG == 2:
	main()
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	main()


import sys, math, cmath, time
start_time = time.time()

def solve():
	x = inp()
	a = inlt()
	c = 0
	s = 0
	if a.count(1) != 1:
		for i in range(a.index(1), len(a)):
			if a[i] == 0:
				c = c + 1
			else:
				s = s + c
				c = 0
				if 1 not in a[i + 1:]:
					break
	print(s)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def power_two(x):
	return x and (not x & x - 1)

def ceil(a, b):
	return -(-a // b)

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(j) for j in input().split()]
	ind1 = 0
	ind2 = n - 1
	while arr[ind1] != 1:
		ind1 += 1
	while arr[ind2] != 1:
		ind2 -= 1
	ans = 0
	for i in range(ind1, ind2 + 1):
		if arr[i] == 0:
			ans += 1
	print(ans)


t = int(input())
for j in range(t):
	n = int(input())
	a = input().split()
	b = []
	for i in range(len(a)):
		if a[i] == '1':
			saveifront = i
			break
	for i in range(len(a) - 1, -1, -1):
		if a[i] == '1':
			savebacki = i
			break
	for i in range(saveifront, savebacki + 1):
		b.append(a[i])
	cnt = 0
	for i in range(len(b)):
		if b[i] == '0':
			cnt = cnt + 1
	print(cnt)


t = int(input())
while t > 0:
	length = int(input())
	l = list(map(int, input().split()))
	while 1:
		if l[-1] == 0:
			l.pop()
		else:
			break
	l = l[::-1]
	while 1:
		if l[-1] == 0:
			l.pop()
		else:
			break
	cnt = 0
	for i in range(len(l)):
		if l[i] == 0:
			cnt += 1
	print(cnt)
	t -= 1


n = int(input())
List = []
k = []
for i in range(n):
	k.append(int(input()))
	List.append(list(map(int, input().split())))
for i in range(n):
	startFound = False
	result = 0
	for j in range(k[i]):
		if List[i][j] == 1 and (not startFound):
			start = j
			startFound = True
		if List[i][j] == 1:
			end = j
	for j in range(start, end + 1):
		if List[i][j] == 0:
			result += 1
	if start == end and start == 0 or start == k[i] - 1:
		result = 0
	print(result)


for i in range(int(input())):
	input()
	s = input()
	i = s.find('1')
	j = s.rfind('1')
	print(s.count('0', i, j))


for _ in range(int(input())):
	n = int(input())
	s = input().split()
	s = ''.join(s)
	s = str(int(s))
	s = s[::-1]
	s = str(int(s))
	if s.count('1') == 1:
		print(0)
	else:
		print(s.count('0'))


t = int(input())
for x in range(t):
	out = 0
	k = int(input())
	arr = list(map(int, input().split()))
	for y in range(k):
		if arr[y] == 1:
			beg = y
			break
	for y in range(k - 1, -1, -1):
		if arr[y] == 1:
			end = y
			break
	for y in range(beg, end):
		if arr[y] == 0:
			out = out + 1
	print(out)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	t = l.index(1)
	s = 0
	d = 0
	for i in range(t + 1, n):
		if l[i] == 1:
			d = i - t
			t = i
			s = s + d - 1
	print(s)


x = int(input())
for j in range(x):
	n = int(input())
	a = [int(x) for x in input().split()]
	l = 0
	r = 0
	for i in range(len(a)):
		if a[i] == 1:
			l = i
			break
	for i in range(len(a)):
		if a[i] == 1:
			r = i
	ans = 0
	for i in range(r - l):
		if a[i + l] == 0:
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	l = int(input())
	a = list(map(int, input().split()))
	count = 0
	ini = -1
	fin = -1
	for i in range(l):
		if a[i] == 1:
			ini = i
			break
	for i in range(l):
		if a[l - i - 1] == 1:
			fin = l - i - 1
			break
	for i in range(ini, fin + 1):
		if a[i] == 0:
			count += 1
	print(count)


def n_moves(book_str):
	return book_str.replace(' ', '').replace('0', ' ').strip().count(' ')
n_cases = int(input())
for i in range(n_cases):
	n_places = int(input())
	book_str = input()
	print(n_moves(book_str))


from sys import stdin as inp
from math import gcd, sqrt, floor, ceil, log2, log
import heapq
for _ in range(int(inp.readline())):
	n = int(inp.readline())
	arr = list(map(int, inp.readline().split()))
	x = arr.index(1)
	y = n - 1
	for i in range(n - 1, -1, -1):
		if arr[i] == 1:
			y = i
			break
	ans = arr[x:y].count(0)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	ans = 0
	i = 0
	while i < n and a[i] == 0:
		i += 1
	j = n - 1
	while j >= 0 and a[j] == 0:
		j -= 1
	while i <= j:
		if a[i] == 0:
			ans += 1
		i += 1
	print(ans)


from pprint import pprint
import collections

def do():
	n = int(input())
	dat = list(map(int, input().split()))
	q = collections.deque(dat)
	while True:
		if len(q) == 0:
			break
		x = q.popleft()
		if x == 0:
			continue
		q.appendleft(x)
		break
	while True:
		if len(q) == 0:
			break
		x = q.pop()
		if x == 0:
			continue
		q.append(x)
		break
	print(list(q).count(0))
q = int(input())
for _ in range(q):
	do()


bs = input()
a = 0
while a < int(bs):
	s = input()
	case = input().split(' ')
	a += 1
	while case[0] != '1':
		case.pop(0)
	while case[-1] != '1':
		case.pop(-1)
	if len(case) > 1:
		spaces = 0
		for z in case:
			if z == '0':
				spaces += 1
		print(spaces)
	else:
		print(0)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	flag = 0
	r = []
	x = 0
	for i in l:
		if i == 1:
			if flag == 1 and x > 0:
				r.append(x)
			else:
				flag = 1
			x = 0
		elif i == 0 and flag == 1:
			x += 1
	i = 0
	j = len(r) - 1
	c = 0
	while i <= j:
		if i == j:
			c += r[i]
			break
		elif r[i] < r[j]:
			c += r[i]
			i += 1
		else:
			c += r[j]
			j -= 1
	print(c)


t = int(input())
while t > 0:
	t -= 1
	length = int(input())
	stuff = input().split()
	count = 0
	places = []
	for i in range(length):
		if stuff[i] == '1':
			places.append(i)
	if len(places) < 2:
		print(0)
		continue
	for i in range(len(places)):
		if i >= 0 and i < len(places) - 1:
			count += places[i + 1] - places[i] - 1
	print(count)


import os
from heapq import heapify, heappop, heappush
import sys
import math
import operator
import bisect
from collections import defaultdict
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		n = int(input())
		ar = inpt()
		ok = False
		count = 0
		ans = 0
		for i in ar:
			if i == 1 and (not ok):
				ok = True
			if i == 0 and ok:
				count += 1
			if i == 1 and ok:
				ans += count
				count = 0
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for _ in range(n):
		if a[0] == 0:
			a.remove(a[0])
		else:
			break
	a = a[::-1]
	for _ in range(n):
		if a[0] == 0:
			a.remove(a[0])
		else:
			break
	cnt = a.count(0)
	print(cnt)


def yet_another_book_shelf(book_shelf):
	book_index = []
	count = 0
	for i in range(0, len(book_shelf)):
		if book_shelf[i] == '1':
			book_index.append(i)
	for i in range(len(book_shelf)):
		if i < len(book_index) - 1:
			count = count + abs(book_index[i] - book_index[i + 1]) - 1
	print(count)
t = input()
for i in range(0, int(t)):
	n = input()
	arr = input().split(' ')
	yet_another_book_shelf(arr)


def ans(n, arr):
	lst = []
	for i in range(n):
		if arr[i] == 1:
			lst.append(i)
	res = 0
	if len(lst) > 1:
		for i in range(len(lst) - 1):
			res += lst[i + 1] - lst[i] - 1
	return res
T = int(input())
for i in range(T):
	n = int(input())
	arr = list(map(int, input().strip().split(' ')))
	print(ans(n, arr))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if a.count(1) == 0 or a.count(1) == 1:
		print(0)
		continue
	counte = 0
	f = 0
	for i in range(len(a)):
		if a[i] == 1:
			j = i
	for i in range(len(a)):
		if i == j:
			break
		if a[i] == 1:
			f = 1
		if f == 1:
			if a[i] == 0:
				counte += 1
	print(counte)


for i in range(int(input())):
	n = int(input())
	a = list(input().split())
	c = 0
	for j in range(a.index('1'), ''.join(a).rindex('1')):
		if int(a[j]) == 0:
			c += 1
	print(c)


for i in range(int(input())):
	x = input()
	a = list(map(int, input().split()))
	x = 0
	while a[x] == 0:
		x += 1
	y = len(a) - 1
	while a[y] == 0:
		y -= 1
	print(y - x + 1 - sum(a))


import sys
inp = sys.stdin.buffer.readline
inar = lambda : list(map(int, inp().split()))
inin = lambda : int(inp())
inst = lambda : inp().decode().strip()
wrt = sys.stdout.write
pr = lambda *args, end='\n': wrt(' '.join([str(x) for x in args]) + end)
enum = enumerate
inf = float('inf')
cdiv = lambda x, y: -(-x // y)
mod = 1000000007
_T_ = inin()
for _t_ in range(_T_):
	n = inin()
	a = inar()
	fi = -1
	li = -1
	for i in range(n):
		if fi == -1 and a[i] == 1:
			fi = i
		if a[i] == 1:
			si = i
	cnt = 0
	for i in range(fi, si + 1):
		if a[i] == 0:
			cnt += 1
	print(cnt)


from typing import List

def number_shifts(l: int, books: List[int]) -> int:
	number_books = sum(books)
	(left, right) = (0, 0)
	while books[left] == 0:
		left += 1
	while books[l - right - 1] == 0:
		right += 1
	return l - left - right - number_books
n = int(input())
for _ in range(n):
	l = int(input())
	books = list(map(int, input().split()))
	print(number_shifts(l, books))


for i in range(int(input())):
	input()
	books = list(map(int, input().split()))
	prev = None
	gaps = 0
	while books and books[0] == 0:
		books = books[1:]
	while books and books[-1] == 0:
		books = books[:-1]
	print(len([b for b in books if b == 0]))


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	j = n - 1
	while i < n and l[i] == 0:
		i += 1
	while j >= 0 and l[j] == 0:
		j -= 1
	ans = 0
	while i <= j:
		if l[i] == 0:
			ans += 1
		else:
			pass
		i += 1
	print(ans)


import sys

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	lst = []
	lst = get_ints()
	fi = -1
	li = -1
	for i in range(n):
		if lst[i] == 1:
			fi = i
			break
	for i in range(1, n + 1):
		if lst[n - i] == 1:
			li = n - i
			break
	if li == -1 or fi == -1:
		print(0)
		continue
	ans = 0
	for i in range(fi, li):
		if lst[i] == 0:
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = []
	if 1 not in a or 0 not in a:
		print(0)
	elif a[0] == 0:
		f = 0
		start = a.index(1)
		q = 0
		g = 0
		for j in range(start + 1, len(a)):
			if a[j] == 1:
				g = g + j - start - 1
				start = j
		print(g)
	else:
		f = 0
		start = 0
		q = 0
		g = 0
		for j in range(start + 1, len(a)):
			if a[j] == 1:
				g = g + j - start - 1
				start = j
		print(g)


try:
	T = int(input())
	for i in range(T):
		n = int(input())
		A = list(map(int, input().split()))
		summ = 0
		p = []
		for i in range(len(A)):
			if A[i] == 1:
				p.append(i)
		summ = 0
		for i in range(len(p) - 1):
			summ += abs(p[i] - p[i + 1]) - 1
		print(summ)
except:
	pass


a = int(input())
for i in range(0, a):
	t = int(input())
	arr = list(map(int, input().split()))
	arr = [int(i) for i in arr]
	ar = []
	for i in arr:
		if i == 1:
			if len(ar) == 0 or not ar[len(ar) - 1] == 1:
				ar.append(1)
		else:
			ar.append(0)
	ind = ar.index(1)
	ans = 0
	temp = 0
	for i in range(ind, len(ar)):
		if ar[i] == 0:
			temp = temp + 1
		if ar[i] == 1:
			ans = ans + temp
			temp = 0
	print(ans)


t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	k = n
	x = 0
	for j in range(0, n):
		if a[x] == 1:
			break
		x = x + 1
	for m in range(0, k):
		if a[k - 1] == 1:
			break
		k = k - 1
	d = 0
	for r in a[x:k]:
		if r == 0:
			d = d + 1
	print(d)


for _ in range(int(input())):
	bet = 0
	ini = 0
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	while a[i] == 0:
		i += 1
	e = n - 1
	while a[e] == 0 and e > i:
		e -= 1
	ans = 0
	if e == i:
		print('0')
	else:
		for x in range(i, e):
			if a[x] == 0:
				ans += 1
		print(ans)


for _ in range(int(input())):
	input()
	x = str(input().split())
	l = x.find('1')
	r = x.rfind('1')
	ans = 0
	for i in range(l, r + 1):
		ans += x[i] == '0'
	print(ans)


t = int(input())
for i in range(t):
	k = int(input())
	low = 0
	high = 0
	a = list(map(int, input().split()))
	for j in range(len(a)):
		if a[j] == 1:
			low = j
			break
	for j in range(len(a) - 1, -1, -1):
		if a[j] == 1:
			high = j
			break
	print(a[low:high + 1].count(0))


for _ in range(int(input())):
	N = int(input())
	A = [int(i) for i in input().split(' ')]
	start = 0
	end = 0
	for i in range(N):
		if A[i] == 1:
			start = i
			break
	for i in range(1, N + 1):
		if A[-i] == 1:
			end = N - i
			break
	count = 0
	for i in range(start, end + 1):
		if A[i] == 0:
			count += 1
	print(count)


def check(books_list):
	count = 0
	first_index = books_list.index('1')
	last_index = len(books_list) - 1 - list(reversed(books_list)).index('1')
	if last_index != '0':
		for i in range(first_index + 1, last_index):
			if books_list[i] == '0':
				count += 1
	return str(count)
test = int(input())
books = []
for i in range(test):
	books_num = int(input())
	books.append(input().split())
book_check = '\n'.join([check(books[i]) for i in range(0, len(books))])
print(book_check)


import sys, os
t = sys.stdin.readline().strip()
for _ in range(0, int(t)):
	n = int(sys.stdin.readline().strip())
	a = [int(x) for x in sys.stdin.readline().split()]
	a_rev = a.copy()
	a_rev.reverse()
	i1 = a.index(1)
	i2 = n - a_rev.index(1) - 1
	s = a[i1:i2 + 1]
	print(s.count(0))


for i in range(int(input())):
	n = int(input())
	res = list(map(int, input().split()))
	z = []
	sol = 0
	for i in range(1, len(res) + 1):
		if res[i - 1] == 1:
			z.append(i - 1)
	for j in range(2, len(z) + 1):
		sol += z[j - 1] - z[j - 2] - 1
	print(sol)


t = int(input())

def count(bookshelf):
	bookshelf = bookshelf.strip('0 ')
	return bookshelf.count('0')
for i in range(t):
	lenth = input()
	bookshelf = input().strip()
	print(count(bookshelf))


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections as col

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	N = getInt()
	A = getInts()
	for j in range(N):
		if A[j] == 1:
			min1 = j
			break
	for j in range(N - 1, -1, -1):
		if A[j] == 1:
			max1 = j
			break
	ans = 0
	for j in range(min1, max1):
		if A[j] == 0:
			ans += 1
	return ans
for _ in range(getInt()):
	print(solve())


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	prev = -1
	res = 0
	i = 0
	while i < n:
		if arr[i] == 0 and prev != -1:
			j = i
			while j < n and arr[j] == 0:
				j += 1
			if j < n and arr[j] == 1:
				res = res + j - i
			i = j - 1
		elif arr[i] == 1:
			prev = i
		i += 1
	print(res)


t = int(input())
for z in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	pos = []
	last = 0
	for i in range(n):
		if l[i] == 1 and last == 0:
			last = 1
			pos.append([i])
		elif l[i] == 0 and last == 1:
			last = 0
			pos[-1].append(i - 1)
	sum_ = 0
	for i in range(1, len(pos)):
		sum_ += pos[i][0] - pos[i - 1][1] - 1
	print(sum_)


for _ in range(int(input())):
	n = int(input())
	q = list(map(int, input().split()))
	moves = 0
	en_1 = 0
	c = 0
	for i in range(0, n):
		if q[i] == 0 and en_1 == 1:
			moves = moves + 1
		elif q[i] == 1:
			en_1 = 1
			c = c + 1
	if c == 1:
		print(0)
	elif q[n - 1] == 0:
		for i in range(n - 1, 0, -1):
			if q[i] == 1:
				break
			else:
				moves = moves - 1
		print(moves)
	else:
		print(moves)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	while l[0] == 0:
		l.pop(0)
	while l[-1] == 0:
		l.pop(-1)
	print(l.count(0))


def shove_books(shelf):
	ans = 0
	space = 0
	f = False
	for i in shelf:
		if i == 0:
			space += 1
		else:
			if f:
				ans += space
			else:
				f = True
			space = 0
	return ans
for i in range(int(input())):
	n = input()
	print(shove_books([int(i) for i in input().split()]))


def sol(l, start):
	ans = 0
	while start < len(l):
		if l[start] == 0:
			temp = 1
			for i in range(start + 1, n):
				if l[i] == 1:
					ans += temp
					start = i
					break
				else:
					temp += 1
		start += 1
	print(ans)
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	start = 0
	for i in range(n):
		if l[i] == 1:
			start = i
			break
	sol(l, start)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	i = a.index(1)
	a = a[::-1]
	j = a.index(1)
	j = n - 1 - j
	a = a[::-1]
	ans = 0
	for k in range(i, j):
		if a[k] == 0:
			ans += 1
	j = n - 1 - j
	a = a[::-1]
	ans2 = 0
	i = n - 1 - i
	for k in range(j, i):
		if a[k] == 0:
			ans2 += 1
	print(min(ans, ans2))
	t -= 1


for _ in range(int(input())):
	a = int(input())
	ar = list(map(int, input().split()))
	ze = 0
	on = 0
	zet = 0
	for i in ar:
		if i == 0 and on != 0:
			ze += 1
		elif i == 1:
			on += 1
	for j in range(1, a + 1):
		if ar[a - j] == 1:
			break
		zet += 1
	print(ze - zet)


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	start = 0
	end = n - 1
	while arr[start] == 0:
		start += 1
	while arr[end] == 0:
		end -= 1
	ans = arr[start:end].count(0)
	print(ans)


from collections import defaultdict as dd, deque as dq, Counter as c
from math import factorial as f, ceil, gcd, sqrt
for _ in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	t = b.count(0)
	ans = out = 0
	for i in range(len(b)):
		if b[i] == 0:
			ans += 1
		else:
			break
	for i in range(a - 1, -1, -1):
		if b[i] == 0:
			out += 1
		else:
			break
	print(t - ans - out)


for _ in range(int(input())):
	n = int(input())
	book = list(map(int, input().split()))
	(zero, i) = (0, 0)
	while i < n:
		k = i
		while k < n and book[k] == 1:
			k += 1
		i = k
		while k < n and book[k] == 0:
			k += 1
		if i != 0 and k <= n - 1:
			zero += k - i
		i = k
	print(zero)


def driver():
	t = int(input())
	for i in range(t):
		solution()

def solution():
	n = int(input())
	l = [int(x) for x in input().split()]
	i = 0
	for e in range(len(l)):
		if l[e] == 1:
			i = e
			break
	ii = 0
	for e in range(len(l) - 1, -1, -1):
		if l[e] == 1:
			ii = e
			break
	c = 0
	for e in l[i:ii]:
		if e == 0:
			c += 1
	print(c)
driver()


def kira(l):
	if l.count(1) < 2:
		return 0
	l1 = []
	f = 0
	cnt = 0
	for i in l:
		if i == 1:
			if f == 0:
				f = 1
			else:
				if cnt != 0:
					l1.append(cnt)
				cnt = 0
		elif f == 1:
			cnt += 1
	return sum(l1)
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	print(kira(l))


for _ in range(int(input())):
	n = int(input())
	s = 0
	a = list(map(int, input().split()))
	f = 0
	c = 0
	for i in range(n):
		if a[i] == 0 and f == 1:
			c += 1
		elif a[i] == 1 and f == 0:
			f = 1
		elif a[i] == 1 and f == 1:
			s += c
			c = 0
	print(s)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = l.count(1)
	if x == 1:
		print(0)
	else:
		z = []
		for i in range(n):
			if l[i] == 1:
				z.append(i)
				break
		for i in range(n - 1, -1, -1):
			if l[i] == 1:
				z.append(i)
				break
		c = l[z[0]:z[1] + 1]
		print(c.count(0))


from math import log, sqrt, factorial, cos, tan, sin, radians

def li():
	return list(map(int, input().split()))

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def DtoB(n):
	return bin(n).replace('0b', '')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1
mod = 1000000007
for _ in range(ii()):
	n = ii()
	l = li()
	cn = 0
	k = l[::-1]
	i1 = l.index(1)
	i2 = k.index(1)
	i2 = n - i2 - 1
	for i in range(i1, i2 + 1):
		if l[i] == 0:
			cn += 1
	print(cn)


for t in range(int(input())):
	n = int(input())
	print(''.join([' ' if a == '0' else '1' for a in input().split()]).strip().count(' '))


t = int(input())
for i in range(0, t):
	n = int(input())
	L = list(map(int, input().split()))
	M = []
	i = 0
	j = 0
	while i < n:
		if L[i] == 1:
			j = i
			while j < n and L[j] == 1:
				j += 1
			M.append((i, j - 1))
			i = j
		else:
			i += 1
	if len(M) == 1:
		print(0)
	else:
		movesleft = 0
		movesright = 0
		for j in range(0, len(M)):
			if j == 0:
				movesleft += 0
				movesright += M[j + 1][0] - M[j][1] - 1
			elif j == len(M) - 1:
				movesright += 0
				movesleft += M[j][0] - M[j - 1][1] - 1
			else:
				movesright += M[j + 1][0] - M[j][1] - 1
				movesleft += M[j][0] - M[j - 1][1] - 1
		print(min(movesleft, movesright))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	count1 = 0
	sum = 0
	check = False
	for j in l:
		if check == False:
			if j == 1:
				check = True
		if check == True:
			if j == 0:
				count1 += 1
			else:
				sum += count1
				count1 = 0
	print(sum)


t = int(input())
for i in range(t):
	(n, a) = (int(input()), list(map(int, input().split())))
	one = -1
	r = 0
	for j in range(len(a)):
		if a[j] == 1:
			if one == -1:
				one = j
			else:
				r += j - one - 1
				one = j
	print(r)


def answer():
	n = int(input())
	a = [int(x) for x in input().split()]
	s = 0
	e = n - 1
	ans = 0
	c = 0
	for i in range(n):
		if a[i] == 1:
			s = i
			c = 1
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			e = i
			c = 1
			break
	for i in range(s, e):
		if a[i] == 0:
			ans += 1
	if c:
		print(ans)
	else:
		print('0')
t = int(input())
for i in range(t):
	answer()


from math import *
import threading
import sys

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = -1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def graph(n, m):
	adj = dict()
	for i in range(1, n + 1):
		adj.setdefault(i, 0)
	for i in range(m):
		(a, b) = map(int, input().split())
		adj[a] += 1
		adj[b] += 1
	return adj

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	li = []
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, len(prime)):
		if prime[p]:
			li.append(p)
	return li
INF = 1000000000.0
primes = SieveOfEratosthenes(1300000)

def fn(n):
	i = 2
	res = n - 1
	val = 0
	for i in range(int(sqrt(n)) + 1, 1, -1):
		val = i - 1 + int(ceil((n - i) / i))
		if val <= res:
			res = val
		else:
			break
	return res

def solve(a, b, c):
	dis = b ** 2 - 4 * a * c
	ans1 = (-b - sqrt(dis)) / (2 * a)
	print(int(ans1))
	return
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = a[::-1]
	if 1 in a:
		ind = a.index(1)
		indrev = n - 1 - b.index(1)
		ans = a[ind:indrev + 1].count(0)
		print(ans)
	else:
		print(0)


import sys
t = int(sys.stdin.readline())
ans_arr = []
for i in range(t):
	n = int(sys.stdin.readline())
	a = [int(j) for j in sys.stdin.readline().split()]
	left = 0
	for r in range(n):
		if a[r] == 1:
			left = r
			break
	right = n - 1
	for p in range(n - 1, -1, -1):
		if a[p] == 1:
			right = p
			break
	if left == right:
		ans_arr.append('0')
	else:
		ans = 0
		for h in range(left + 1, right):
			if a[h] == 0:
				ans += 1
		ans_arr.append(str(ans))
print('\n'.join(ans_arr))


for _ in range(int(input())):
	n = int(input())
	ara = list(map(int, input().strip().split()))
	start = end = count = 0
	if ara.count(1) == 1:
		print(0)
	else:
		for i in range(n):
			if ara[i] == 1:
				start = i
				break
		for i in range(n):
			if ara[n - i - 1] == 1:
				end = n - i
				break
		for i in range(start, end):
			if ara[i] == 0:
				count += 1
		print(count)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	j = 0
	for t in range(n):
		if a[t] == 1:
			i = t
			break
	for t in range(n - 1, -1, -1):
		if a[t] == 1:
			j = t
			break
	r = 0
	for t in range(i, j):
		if a[t] == 0:
			r += 1
	print(r)


for i in range(int(input())):
	input()
	alef = input()
	indexf = alef.find('1')
	indexs = alef.rfind('1')
	if indexs != len(alef) - 1:
		print(alef[indexf:indexs + 1].count('0'))
	else:
		print(alef[indexf:].count('0'))


t = int(input())
for _ in range(t):
	n = int(input())
	str = input().replace(' ', '')
	indices = [i for i in range(len(str)) if str[i] == '1']
	r = int(indices[-1]) - int(indices[0]) - len(indices) + 1
	print(r)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)

def solve(case):
	n = int(inp())
	a = lis()
	cnt = a.count(1)
	left = -1
	right = -1
	for i in range(n):
		if a[i] == 1:
			left = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			right = i
			break
	print(right - left + 1 - cnt)
testcase(int(inp()))


for pp in range(0, int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a.count(1) == 1:
		print('0')
	else:
		m = []
		for i in range(0, n - 1):
			if a[i] == 1:
				c = 0
				for j in range(i + 1, n):
					if a[j] == 0:
						c += 1
					else:
						break
				m.append(c)
		i = -1
		c = 0
		while a[i] != 1:
			c += 1
			i -= 1
		m.append(-c)
		print(sum(m))


n = int(input())
for i in range(n):
	input()
	arr = list(map(int, input().split(' ')))
	hash = dict()
	hash[1] = []
	for i in range(len(arr)):
		if arr[i]:
			hash[arr[i]].append(i)
	res = 0
	for i in range(1, len(hash[1])):
		lo = hash[1][i - 1]
		hi = hash[1][i]
		for i in range(lo + 1, hi):
			res += 1
	print(res)


def main():
	n = int(input())
	arr = input().split()
	(i, ans) = (0, [])
	while i < n:
		if arr[i] == '0':
			ans.append('0')
		else:
			j = i
			while j < n and arr[j] == '1':
				j += 1
			i = j - 1
			ans.append('1')
		i += 1
	(a, index) = (0, -1)
	for i in range(len(ans)):
		if ans[i] == '1':
			if index != -1:
				a += i - index - 1
			index = i
	print(a)
for _ in range(int(input())):
	main()


for t in range(int(input())):
	n = int(input())
	bs = list(map(int, input().split()))
	f = 1
	l = n
	bs = [2] + bs + [2]
	while bs[f] == 0:
		f += 1
	while bs[l] == 0:
		l -= 1
	while bs[f] == 1:
		f += 1
	while bs[l] == 1:
		l -= 1
	f -= 1
	l += 1
	print(max(0, l - f - 1 - sum(bs[f + 1:l])))


try:
	t = int(input())
	for _ in range(t):
		n = int(input())
		lib = input()
		count0 = lib[lib.index('1'):lib.rindex('1')].count('0')
		print(count0)
except:
	pass


import collections
import sys

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	st = -1
	for (i, value) in enumerate(arr):
		if value == 1:
			st = i
			break
	if st == -1:
		return 0
	end = 0
	for (i, value) in enumerate(arr[::-1]):
		if value == 1:
			end = i
			break
	end = n - end - 1
	if end == st:
		return 0
	cnt = 0
	for i in arr[st:end]:
		if i == 0:
			cnt += 1
	return cnt
for _ in range(int(input())):
	print(solve(), '\n')


cases = int(input())
for t in range(cases):
	n = int(input())
	a = ''.join(input().split())
	lf = a.find('1')
	rf = a.rfind('1')
	out = 0
	for i in range(lf, rf):
		if a[i] == '0':
			out += 1
	print(out)


for k in range(int(input())):
	n = int(input())
	a = input()
	a_to_answer = a.strip('0 ')
	print(a_to_answer.count('0'))


t = int(input())
r = []
for i in range(t):
	n = int(input())
	b = input().split(' ')
	r.append(b[b.index('1'):n - b[::-1].index('1')].count('0'))
for f in r:
	print(f)


for _ in range(int(input())):
	n = int(input())
	stack = []
	arr = list(map(int, input().split()))
	ans = 0
	for i in arr:
		if i == 1 and (not stack):
			stack.append(i)
		elif stack and stack[0] == 1 and (i == 0):
			stack.append(i)
		elif i == 1:
			while stack[-1] == 0:
				ans += 1
				stack.pop()
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	start = 0
	end = 0
	for i in range(len(arr)):
		if arr[i] == 1:
			start = i
			break
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] == 1:
			end = i
			break
	for i in range(start, end + 1):
		if arr[i] == 0:
			ans += 1
	print(ans)


t = int(input())
answers = []
for _ in range(t):
	n = int(input())
	a = input().split()
	a_string = ''.join(a)
	a_strip = a_string.strip('0')
	x = 0
	for i in range(len(a_strip)):
		if a_strip[i] == '0':
			x += 1
	answers.append(x)
for j in range(t):
	print(answers[j])


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(len(a)):
		if a[i] == 1:
			break
	a = a[i:]
	for i in range(len(a) - 1, 0, -1):
		if a[i] == 1:
			break
	a = a[:i + 1]
	if a[-1] == 0:
		a.pop(-1)
	print(a.count(0))


for t in range(int(input())):
	n = int(input())
	arr = [int(k) for k in input().split()]
	fone = 0
	gap = 0
	zer = 0
	for ele in arr:
		if ele == 0:
			zer += 1
		if ele == 1 and fone == 0:
			fone = 1
			zer = 0
		if ele == 1 and fone == 1:
			gap += zer
			zer = 0
	print(gap)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		(l, r) = (0, 0)
		res = []
		while r < n:
			while r < n and a[l] == a[r]:
				r += 1
			if a[l] == 1:
				res.append((r, r - l))
			l = r
		if len(res) == 1:
			print(0)
			continue
		ans = 0
		(left, right) = (res[0][0], res[-1][0] - res[-1][1])
		for j in range(left, right + 1):
			if a[j] == 0:
				ans += 1
		print(ans)
main()


import sys
import os
from math import sqrt, log, log2, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial
from copy import copy, deepcopy
from sys import exit, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : stdout.flush()

def permute(nums):

	def fun(arr, nums, cur, v):
		if len(cur) == len(nums):
			arr.append(cur.copy())
		i = 0
		while i < len(nums):
			if v[i]:
				i += 1
				continue
			else:
				cur.append(nums[i])
				v[i] = 1
				fun(arr, nums, cur, v)
				cur.pop()
				v[i] = 0
				i += 1
		return arr
	res = []
	nums.sort()
	v = [0] * len(nums)
	return fun(res, nums, [], v)

def subsets(res, index, arr, cur):
	res.append(cur.copy())
	for i in range(index, len(arr)):
		cur.append(arr[i])
		subsets(res, i + 1, arr, cur)
		cur.pop()
	return res

def sieve(N):
	root = int(sqrt(N))
	primes = [1] * (N + 1)
	(primes[0], primes[1]) = (0, 0)
	for i in range(2, root + 1):
		if primes[i]:
			for j in range(i * i, N + 1, i):
				primes[j] = 0
	return primes

def bs(arr, l, r, x):
	if x < arr[0] or x > arr[len(arr) - 1]:
		return -1
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	p = int(sqrt(n))
	for i in range(5, p + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def solve():
	n = iinp()
	arr = intl()
	ans = 0
	i = 0
	last = -1
	i = 0
	while i < n and arr[i] == 0:
		i += 1
	j = n - 1
	while j >= 0 and arr[j] == 0:
		j -= 1
	arr = arr[i:j + 1]
	n = len(arr)
	i = 0
	print(arr.count(0))
for _ in range(iinp()):
	solve()


for _ in range(int(input())):
	input()
	seq = input().split()
	for (i, c) in enumerate(seq):
		if c == '1':
			seq = seq[i:]
			break
	seq = list(reversed(seq))
	for (i, c) in enumerate(seq):
		if c == '1':
			seq = seq[i:]
			break
	print(len([x for x in seq if x == '0']))


def solve():
	n = int(input())
	arr = [int(x) for x in input().split()]
	f = 0
	l = n - 1
	while arr[f] != 1:
		f += 1
	while arr[l] != 1:
		l -= 1
	ans = 0
	if f == l:
		print(0)
		return
	for i in range(f, l + 1):
		if arr[i] == 0:
			ans += 1
	print(ans)
T = int(input())
while T > 0:
	T -= 1
	solve()


t = int(input(''))
for i in range(t):
	n = int(input(''))
	d = list(map(int, input('').split()))
	dem = 0
	pos1 = d.index(1)
	for i in range(len(d) - 1, -1, -1):
		if d[i] == 1:
			pos2 = i
			break
	print(d[pos1:pos2 + 1].count(0))


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	bookshelf = list(map(int, input().split()))
	count = 0
	first = bookshelf.index(1)
	r = bookshelf[::-1]
	end = (r.index(1) + 1) * -1
	ans.append(bookshelf[first:end].count(0))
for i in ans:
	print(i)


t = int(input())
for caseNr in range(1, t + 1):
	n = int(input())
	array = list(map(int, input().split()))
	left1 = None
	right1 = None
	for (i, elmt) in enumerate(array):
		if left1 == None and elmt == 1:
			left1 = i
	for (i, elmt) in enumerate(array[::-1]):
		if right1 == None and elmt == 1:
			right1 = len(array) - 1 - i
	if left1 == right1:
		print(0)
	else:
		counter = 0
		new_array = array[left1:right1 + 1]
		for element in new_array:
			if element == 0:
				counter += 1
		print(counter)


def test_case_generator() -> str:
	input_num = int(input())
	for i in range(input_num):
		cells_count = int(input())
		test_case = list()
		array_input = input()
		for element in array_input.split(' '):
			test_case.append(int(element))
		yield test_case

def bookshelf_problem():
	for test_case in test_case_generator():
		first_one = test_case.index(1)
		test_case = test_case[first_one:]
		test_case.reverse()
		last_one = test_case.index(1)
		test_case = test_case[last_one:]
		print(test_case.count(0))
bookshelf_problem()


def find(x):
	left = 0
	right = len(x) - 1
	for i in range(len(x)):
		if x[i] == 0:
			left += 1
		else:
			break
	for i in range(len(x) - 1, -1, -1):
		if x[i] == 0:
			right -= 1
		else:
			break
	if left >= right:
		print(0)
	else:
		print(x[left:right + 1].count(0))
for i in range(int(input())):
	input()
	l = list(map(int, input().split()))
	find(l)


def process(arr, n):
	count = 0
	temp = 0
	flag = 0
	for i in range(len(arr)):
		if arr[i] == 1:
			flag = 1
		if flag == 1:
			if arr[i] == 0:
				temp += 1
			else:
				count += temp
				temp = 0
	print(count)
for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	process(arr, n)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = a.count(1)
	if m == 0 or m == 1:
		ans = 0
	else:
		(l, r) = (-1, -1)
		for i in range(n):
			if a[i] == 1:
				if l == -1:
					l = i
				else:
					r = i
		ans = a[l:r].count(0)
	print(ans)


T = int(input())
for i in range(T):
	N = int(input())
	l = list(map(int, input().split()))
	count = 0
	ans = 0
	x = l.index(1)
	s = len(l) - l[::-1].index(1) - 1
	for j in range(x + 1, s):
		if l[j] == 0:
			count += 1
	print(count)


t = int(input())
for i in range(t):
	c = 0
	ct = 0
	n = int(input())
	p = list(map(int, input().split()))
	for j in range(1, n):
		if p[j - 1] == 1 and p[j] == 0:
			ct = 1
		elif ct > 0 and p[j] == 0:
			ct += 1
		elif ct > 0 and p[j] == 1:
			c += ct
			ct = 0
	print(c)


for i in range(int(input())):
	n = input()
	z = ''.join(input().split()).strip().strip('0').count('0')
	print(z)


def bookshelf_search():
	t_cases = int(input())
	for case in range(t_cases):
		length = int(input())
		bookshelf = list(map(int, input().strip().split()))
		first_i = bookshelf.index(1)
		second_i = length - bookshelf[::-1].index(1) - 1
		print(bookshelf[first_i:second_i + 1].count(0))
bookshelf_search()


t = int(input())
for _ in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	i = 0
	j = n - 1
	s = 0
	for k in range(n):
		if lst[k] == 1:
			i = k
			break
	for k in range(n - 1, -1, -1):
		if lst[k] == 1:
			j = k
			break
	for k in range(i + 1, j):
		if lst[k] == 0:
			s += 1
	print(s)


from collections import Counter, OrderedDict
from itertools import permutations as perm
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()
for _ in range(t):
	(n,) = gil()
	a = gil()
	start = a.index(1)
	end = start
	for i in range(start, n):
		if a[i]:
			end = i
	print(a[start:end + 1].count(0))


t = int(input())
ll = []
for _ in range(t):
	_ = input()
	ss = input().split()
	ll.append([int(s) for s in ss])
for l in ll:
	isStarted = False
	count = 0
	for e in l:
		if e == 1:
			last_count = 0
			if not isStarted:
				isStarted = True
		elif isStarted:
			count += 1
			last_count += 1
	print(count - last_count)


def solve(lst):
	ans = 0
	prev = -1
	for i in range(len(lst)):
		if lst[i] == 1 and prev != -1:
			ans += i - prev - 1
			prev = i
		elif lst[i] == 1:
			prev = i
	return ans
t = int(input())
for x in range(t):
	p = int(input())
	lst = list(map(int, input().split(' ')))
	print(solve(lst))


t = int(input())
for _ in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	res = 0
	it = 0
	flag = 0
	while it < n:
		if lis[it] == 0 and flag == 0:
			f = 1
		else:
			flag = 1
			break
		it += 1
	k = n - 1
	flag2 = 0
	while k > -1:
		if lis[k] == 0 and flag2 == 0:
			f = 1
		else:
			flag2 = 1
			break
		k -= 1
	while it < k:
		if lis[it] == 0:
			res += 1
		it += 1
	print(res)


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor
from heapq import *
from typing import List
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

@lru_cache(None)
def fact(x):
	if x < 2:
		return 1
	return fact(x - 1) * x

@lru_cache(None)
def per(i, j):
	return fact(i) // fact(i - j)

@lru_cache(None)
def com(i, j):
	return per(i, j) // fact(j)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class smt:

	def __init__(self, l, r, arr):
		self.l = l
		self.r = r
		self.value = (1 << 31) - 1 if l < r else arr[l]
		mid = (l + r) // 2
		if l < r:
			self.left = smt(l, mid, arr)
			self.right = smt(mid + 1, r, arr)
			self.value &= self.left.value & self.right.value

	def setvalue(self, x, val):
		if self.l == self.r:
			self.value = val
			return
		mid = (self.l + self.r) // 2
		if x <= mid:
			self.left.setvalue(x, val)
		else:
			self.right.setvalue(x, val)
		self.value = self.left.value & self.right.value

	def ask(self, l, r):
		if l <= self.l and r >= self.r:
			return self.value
		val = (1 << 31) - 1
		mid = (self.l + self.r) // 2
		if l <= mid:
			val &= self.left.ask(l, r)
		if r > mid:
			val &= self.right.ask(l, r)
		return val

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d

def md(a, b, mod):
	return a * pow(b, mod - 2, mod) % mod
t = N()
for i in range(t):
	n = N()
	a = RLL()
	ans = 0
	res = []
	for (ch, g) in groupby(a):
		res.append((ch, len(list(g))))
	if len(res) == 1:
		print(ans)
	else:
		if res[-1][0] == 0:
			res.pop()
		flag = False
		for (ch, l) in res:
			if ch == 1:
				if not flag:
					flag = True
			elif flag:
				ans += l
		print(ans)


t = int(input())
for i in range(t):
	input()
	s = input()
	sub = s[s.index('1'):s.rfind('1')]
	print(sub.count('0'))


t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	first = 0
	second = 0
	gap = 0
	while i < n:
		if l[i] == 1:
			while i < n and l[i] != 0:
				i += 1
			begin = i
			while i < n and l[i] != 1:
				i += 1
			end = i
			if i < n and l[i] == 1:
				gap += end - begin
		else:
			i += 1
	print(gap)


for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = 0
	f = 0
	k = 0
	for i in range(len(a)):
		if a[i] == 1:
			b = i
			break
	for i in range(len(a) - 1, -1, -1):
		if a[i] == 1:
			f = i
			break
	for i in range(b, f + 1):
		if a[i] == 0:
			k += 1
	print(k)


def solve():
	(n, a) = (int(input()), [False] + [i == '1' for i in input().split()])
	s = []
	for i in range(1, n + 1):
		if a[i] == False:
			continue
		if len(s) == 0 or a[i - 1] == False:
			s.append([i, 1])
		else:
			s[-1][-1] += 1
	res = 1000000000
	for i in range(1, n + 1):
		(p, cres, x) = (i, 0, 0)
		for j in s:
			cres += abs(j[0] - p) - x
			x = 0 if j[0] <= p else abs(j[0] - p)
			p += j[1]
		res = min(res, cres)
	print(res)
t = int(input())
while t:
	t -= 1
	solve()


def solve():
	places = int(input())
	books = list(map(int, input().split(' ')))
	book_indices = [i for (i, x) in enumerate(books) if x == 1]
	return books[book_indices[0]:book_indices[-1]].count(0)
for i in range(int(input())):
	print(solve())


t = int(input())
output = []
for q in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	k = 0
	first_one = 0
	second_one = 0
	flag = False
	for i in range(len(a)):
		if a[i] == 1:
			second_one = i
			if not flag:
				first_one = i
				flag = True
	for i in range(first_one, second_one + 1):
		if a[i] == 0:
			k += 1
	output.append(k)
for i in output:
	print(i)


for i in range(int(input())):
	a = input()
	b = list(map(int, input().split()))
	p = 0
	r = 0
	q = 0
	for i in b:
		if i == 1:
			p = 1
			r += q
			q = 0
		if i == 0 and p == 1:
			q += 1
	print(r)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count_1 = 0
	for i in range(n):
		if a[i] == 1:
			count_1 += 1
	temp = 1
	for i in range(n):
		if a[i] == 1:
			j = i + 1
			while j < n:
				if a[j] == 1:
					temp += 1
					j += 1
				else:
					break
			break
	if temp == count_1:
		print(0)
		continue
	count_1_temp = 1
	count = 0
	one_found = False
	for i in range(n):
		if one_found == True and count_1_temp != count_1:
			if a[i] == 0:
				count += 1
			else:
				count_1_temp += 1
		elif a[i] == 1:
			one_found = True
	print(count)


from collections import Counter

def main():
	outputs = []
	for __ in range(int(input())):
		n = int(input())
		A = list(map(int, input().split()))
		p_A = []
		for i in A:
			if p_A:
				p_A.append(p_A[-1] + i)
			else:
				p_A.append(i)
		dic = Counter(p_A)
		p = 0
		if len(dic.keys()) == 1:
			outputs.append(0)
		else:
			assigned = False
			tem = 0
			for key in dic.keys():
				if key != 0:
					if assigned:
						p += tem
						tem = dic.get(key) - 1
					else:
						tem = dic.get(key) - 1
						assigned = True
			outputs.append(p)
	for output in outputs:
		print(output)
main()


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(a) for a in input().split()]
	bn = 0
	fn = 0
	ba = a.count(1)
	for j in range(n):
		if a[j] == 1:
			bn += j
			break
	a.reverse()
	for u in range(n):
		if a[u] == 1:
			fn = n - u
			break
	print(fn - bn - ba)


for _ in range(int(input())):
	n = int(input())
	st = input().strip('0 ')
	print(st.count('0'))


for _ in range(int(input())):
	n = int(input())
	l = list(map(str, input().split()))
	x = l.index('1')
	y = ''.join(l).rindex('1')
	z = l[x:y]
	print(z.count('0'))


for test in range(int(input())):
	n = int(input())
	shelf = list(map(int, input().split()))
	if sum(shelf) == 1:
		print(0)
	else:
		distances = [idx for (idx, val) in enumerate(shelf) if val == 1]
		sampling = shelf[distances[0]:distances[-1] + 1]
		print(sampling.count(0))


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	prev = None
	for (i, x) in enumerate(a):
		if x == 1:
			if prev is None:
				prev = i
			else:
				ans += i - prev - 1
				prev = i
	print(ans)


from itertools import groupby

def solve(n):
	z = 0
	for (k, v) in groupby(n):
		if not k:
			z += len(list(v))
	return z

def main():
	TT = int(input())
	for i in range(TT):
		_ = int(input())
		print(solve(map(int, input().strip('0 ').split())))
main()


import math
from collections import Counter
try:
	for _ in range(int(input())):
		n = int(input())
		arr = [int(i) for i in input().split()]
		fptr = 0
		bptr = n - 1
		while fptr < n - 1:
			if arr[fptr] == 1:
				break
			fptr += 1
		while bptr > fptr:
			if arr[bptr] == 1:
				break
			bptr -= 1
		ans = 0
		for i in range(fptr, bptr):
			if arr[i] == 0:
				ans += 1
		print(ans)
except EOFError as e:
	print(e)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().rsplit(' ')))
	state = False
	que = False
	gaps = 0
	pot = 0
	for el in a:
		if state and el == 1:
			gaps += 1
			gaps += pot
			pot = 0
			que = False
			state = False
		if state and el == 0:
			pot += 1
		if el == 0 and que == True:
			state = True
		if el == 1:
			que = True
	print(gaps)


def calc(n, a):
	ans = 0
	intervals = []
	i = 0
	while i < n:
		if a[i] == 1:
			start = i
			while i < n and a[i] == 1:
				i += 1
			end = i - 1
			intervals.append([start, end])
		else:
			i += 1
	for i in range(1, len(intervals)):
		ans += intervals[i][0] - intervals[i - 1][1] - 1
	return ans
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(calc(n, a))


from collections import Counter, defaultdict, deque
from heapq import heapify, heappush, heappop
from bisect import bisect_left
from functools import lru_cache
import math

def debug(*x):
	import sys
	print(*x, file=sys.stderr)

def compute(a, seg, mid):
	if not 0 <= mid < len(seg):
		return math.inf
	ans = 0
	(c, valid) = (0, False)
	for i in range(seg[0][0], seg[mid][0]):
		if a[i] == 0:
			c += 1
		if a[i] == 1:
			valid = True
	if valid:
		ans += c
	(c, valid) = (0, False)
	for i in range(seg[mid][1] + 1, seg[-1][1] + 1):
		if a[i] == 0:
			c += 1
		if a[i] == 1:
			valid = True
	if valid:
		ans += c
	return ans
tc = int(input())
while tc:
	tc -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	seg = []
	lhs = 0
	while lhs < n:
		if a[lhs] == 1:
			rhs = lhs
			while rhs < n and a[rhs] == 1:
				rhs += 1
			seg.append((lhs, rhs - 1))
			lhs = rhs - 1
		lhs += 1
	mid = len(seg) // 2
	ans = min(compute(a, seg, mid), compute(a, seg, mid - 1), compute(a, seg, mid + 1))
	print(ans)


n = int(input())
for i in range(0, n):
	o = int(input())
	p = input().rstrip().split(' ')
	G = 0
	ans = 0
	tot = 0
	for j in range(0, len(p)):
		if G == 0:
			if int(p[j]) == 1:
				G = 1
		elif int(p[j]) == 0:
			tot += 1
		else:
			ans += tot
			tot = 0
	print(ans)


from sys import *
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
for _ in range(int(input())):
	n = int(input())
	arr = int_arr()
	ct = 0
	flag = 0
	ind = n - 1 - arr[::-1].index(1)
	for i in range(ind + 1):
		if arr[i] == 1:
			flag = 1
		if flag and arr[i] == 0:
			ct += 1
	print(ct)


def proB(arr):
	i = 0
	cost = 0
	while i < len(arr):
		if arr[i] == 1:
			j = i + 1
			ans = 0
			while j < len(arr):
				if arr[j] == 1:
					i = j
					break
				j += 1
				ans += 1
			if j == len(arr):
				i = j
				ans = 0
			else:
				cost += ans
		else:
			i += 1
	return cost
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(proB(arr))


def solve():
	n = int(input())
	arr = input().split()
	s = ''.join(arr)
	s = s.strip('0')
	return s.count('0')

def main():
	for _ in range(int(input())):
		print(solve())
main()


t = int(input())
for _ in range(t):
	mov = 0
	arr = []
	n = int(input())
	ara = list(map(int, input().split()))
	for i in range(n):
		if ara[i] == 1:
			arr.append(i)
	if len(arr) == 1:
		print(mov)
	else:
		for i in range(len(arr) - 1):
			if arr[i + 1] - arr[i] >= 2:
				mov += arr[i + 1] - arr[i] - 1
		print(mov)


for t in range(int(input())):
	n = int(input())
	M = [int(i) for i in input().split()]
	count = 0
	flag = 0
	for i in range(n):
		if M[i] == 1:
			flag = 1
			ls = i
		elif M[i] == 0 and flag == 1:
			count += 1
		else:
			continue
	count -= n - ls - 1
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	books = list(map(int, input().split()))
	z = 0
	was_b = False
	dist = []
	for el in books:
		if el:
			if was_b and z > 0:
				dist.append(z)
			z = 0
			was_b = True
		else:
			z += 1
	if len(dist) == 0:
		print(0)
	else:
		print(sum(dist))


t = int(input())
arr = []
for _ in range(t):
	n = int(input())
	arr.append(tuple(map(int, input().split())))
for nums in arr:
	(l, r) = (0, len(nums) - 1)
	while nums[r] != 1:
		r -= 1
	while nums[l] != 1:
		l += 1
	if l == r:
		print(0)
	else:
		print(r - l + 1 - sum(nums[l:r + 1]))


def read_int():
	return int(input())
t = read_int()
for case in range(t):
	n = read_int()
	s = [int(i) for i in input().split(' ')]
	left = 0
	while s[left] == 0 and left < n:
		left += 1
	right = n - 1
	while s[right] == 0 and right >= 0:
		right -= 1
	ans = 0
	for i in range(left, right + 1):
		ans += 1 if s[i] == 0 else 0
	print(ans)


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	try:
		for _ in range(inp()):
			n = inp()
			a = inlt()
			ans = 0
			if a.count(1) == 1:
				print('0')
				continue
			else:
				i1 = a.index(1)
				i2 = n - a[::-1].index(1) - 1
				for i in range(i1, i2):
					if a[i] == 0:
						ans += 1
			print(ans)
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	c = 0
	a = [int(x) for x in input().split()]
	for i in range(n):
		if a[i] == 1:
			break
	for j in range(n - 1, -1, -1):
		if a[j] == 1:
			break
	for k in range(i, j + 1):
		if a[k] == 0:
			c += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	lst = []
	lst1 = []
	temp = 0
	for i in range(n):
		if a[i] == 1:
			start = i
			break
	for i in range(n):
		if a[i] == 1:
			end = i
	for i in range(start, end + 1):
		if a[i] == 0:
			temp += 1
		else:
			lst.append(temp)
			temp = 0
	if temp > 0:
		lst.append(temp)
	print(sum(lst))


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(a[a.index(1) + 1:len(a) - a[::-1].index(1)].count(0))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	f = 0
	l = 0
	count = 0
	mcount = 0
	for i in range(n):
		if count == 0 and arr[i] == 1:
			count += 1
			f = i
		elif arr[i] == 1:
			count += 1
			l = i
	mcount = l - f - count + 1
	if count == 1:
		print(0)
	else:
		print(mcount)


n = int(input())
for iii in range(n):
	a = int(input())
	b = list(map(int, input().split()))
	t = 0
	t1 = 0
	q = 0
	for i in range(0, len(b)):
		if b[i] == 1:
			t = i
			break
	for j in range(0, len(b)):
		if b[j] == 1:
			t1 = j
	for ii in range(t, t1 + 1):
		if b[ii] == 0:
			q += 1
	print(q)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = -1
	e = n
	for i in range(n):
		if a[i] == 1:
			s = i
			break
	for i in reversed(range(n)):
		if a[i] == 1:
			e = i
			break
	if s == -1 or e == n:
		print(0)
		continue
	c = 0
	for i in range(s + 1, e):
		if a[i] == 0:
			c += 1
	print(c)


for _ in range(int(input())):
	x = int(input())
	mylist = list(map(int, input().split()))
	l = 0
	r = 0
	i = len(mylist) - 1
	while mylist[l] == 0:
		l += 1
	while mylist[i] == 0:
		i -= 1
		r += 1
	sum = mylist.count(0) - (l + r)
	print(sum)


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
for _ in range(int(I1())):
	n = int(I1())
	a = list(I())
	s = set()
	for i in range(n):
		if a[i] == 1:
			s.add(i)
	s = list(s)
	s.sort()
	if len(s) == 1:
		print(0)
	else:
		c = 0
		for i in range(1, len(s)):
			c += s[i] - s[i - 1] - 1
		print(c)


for _ in range(int(input())):
	count = 0
	n = int(input())
	arr = list(map(int, input().split()))
	arr10 = []
	for k in range(n):
		if arr[k] == 1:
			arr10.append(k)
	for k in range(len(arr10) - 1):
		count += arr10[k + 1] - arr10[k] - 1
	print(count)


for t in range(int(input())):
	n = int(input())
	a = input().rstrip().replace(' ', '').strip('0')
	print(a.count('0'))


t = input()
for i in range(int(t)):
	k = 0
	n = int(input())
	ch = input()
	L = [int(i) for i in ch.split()]
	pos1_1 = -1
	pos1_2 = -1
	for j in range(n):
		if L[j] == 1:
			pos1_1 = j
			break
	for j in range(n):
		if L[j] == 1:
			pos1_2 = j
	nb = 0
	for j in range(pos1_1, pos1_2):
		if L[j] == 0:
			nb += 1
	print(nb)


for _ in range(int(input())):
	n = int(input())
	string = input()
	z = 0
	answ = 0
	is_on = False
	for i in string:
		if i == '1':
			is_on = True
			answ += z
			z = 0
		if i == '0' and is_on:
			z += 1
	print(answ)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
sys.setrecursionlimit(100000000)
ii = lambda : int(input())
si = lambda : input()
jn = lambda x, l: x.join(map(str, l))
sl = lambda : list(map(str, input().strip()))
mi = lambda : map(int, input().split())
mif = lambda : map(float, input().split())
lii = lambda : list(map(int, input().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
mod = 1000000007
for _ in range(ii()):
	n = ii()
	arr = lii()
	s = ''
	for ele in arr:
		s += str(ele)
	a = s.index('1')
	b = s.rindex('1')
	sol = 0
	for i in range(a + 1, b):
		if arr[i] == 0:
			sol += 1
	print(sol)


from sys import stdin, stdout
import math, bisect
from collections import Counter, deque, defaultdict
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
S = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()

def pr(a):
	return ''.join(list(map(str, a)))

def solve():
	n = I()
	a = L()
	for i in range(n):
		if a[i] == 1:
			break
	for j in range(n - 1, -1, -1):
		if a[j] == 1:
			break
	a = a[i:j]
	s = pr(a)
	print(s.count('0'))
for _ in range(I()):
	solve()


n = int(input())
for i in range(n):
	l = input()
	seq = list(map(int, input().split()))
	count = 0
	i = 0
	found = False
	while seq[i] != 1:
		i += 1
	result = 0
	for i in range(i, len(seq)):
		if seq[i] == 0:
			count += 1
		else:
			result += count
			count = 0
	print(result)


for _ in range(int(input())):
	n = int(input())
	x = input().split()
	count = 0
	indices = [i for (i, x) in enumerate(x) if x == '1']
	for i in range(len(indices) - 1):
		count += indices[i + 1] - indices[i] - 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	zero = 0
	one = 0
	j = 0
	while j < n:
		if l[j] == 1:
			break
		j += 1
	for i in range(j, n):
		if l[i] == 1:
			if zero != 0:
				ans += zero
				zero = 0
		else:
			zero += 1
	print(ans)


n = int(input())

def removeExtra(lst):
	newLst = []
	for i in range(len(lst) - 1):
		if lst[i] == 1 and lst[i + 1] == 0:
			newLst.append(lst[i])
		elif lst[i] == 0:
			newLst.append(0)

def rindex(lst, value):
	lst.reverse()
	i = lst.index(value)
	lst.reverse()
	return len(lst) - i - 1
for i in range(n):
	count = int(input())
	a = [int(x) for x in input().split()]
	left = a.index(1)
	right = rindex(a, 1)
	print(a[left + 1:right].count(0))


for q in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = a.index(1)
	y = x
	res = 0
	for i in range(y + 1, n):
		if a[i] == 1:
			res += i - x - 1
			x = i
	res1 = 0
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			x = i
			break
	y = x
	for i in range(y - 1, -1, -1):
		if a[i] == 1:
			res1 += x - i - 1
			x = i
	print(min(res, res1))


for i in range(int(input())):
	shr_num = int(input())
	shr_ll = list(map(int, input().split()))
	i = 1
	sum = 0
	while i < shr_num - 1:
		p1 = 0
		if shr_ll[i - 1] == 1:
			while shr_ll[i] == 0 and i < shr_num - 1:
				p1 += 1
				i += 1
		if shr_ll[i] == 1:
			sum += p1
		i += 1
	print(sum)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	first = arr.index(1)
	second = len(arr) - arr[::-1].index(1)
	cnt = 0
	for i in arr[first:second]:
		if i == 0:
			cnt += 1
	print(cnt)


def print_result(ans):
	print(ans)

def find_one(num_arr):
	for i in range(len(num_arr)):
		if num_arr[i] == 1:
			return i

def solve(num_arr):
	count = 0
	temp = 0
	first = find_one(num_arr)
	for i in range(first + 1, len(num_arr)):
		if num_arr[i] == 0:
			temp += 1
		else:
			count += temp
			temp = 0
	return count
t = int(input())
for i in range(1, t + 1):
	n = int(input())
	num_arr = list(map(int, input().split()))
	ans = solve(num_arr)
	print_result(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	l = -1
	r = -1
	lol = [int(n) for n in input().split()]
	if lol.count(1) == 1:
		print(0)
	else:
		for i in range(n):
			if lol[i] == 1:
				l = i
				break
		for j in range(len(lol) - 1, -1, -1):
			if lol[j] == 1:
				r = j
				break
		for z in range(l + 1, r):
			if lol[z] == 0:
				ans += 1
		print(ans)


for _ in range(int(input())):
	input()
	data = list(map(int, input().split()))
	li = data.index(1)
	c = 0
	c2 = 0
	ri = li
	for i in range(li, len(data)):
		if data[i] == 1:
			ri = i
			c2 = 0
		else:
			c += 1
			c2 += 1
	print(c - c2)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	a = 0
	for i in range(n):
		if arr[i] == 1:
			a = i
			break
	b = 0
	for i in range(n):
		if arr[i] == 1:
			b = i
	print(b - a + 1 - sum(arr))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	a = l.index(1)
	b = max((i for (i, val) in enumerate(l) if val == 1))
	for i in range(a, b):
		if l[i] == 0:
			c += 1
	print(c)


import sys
sys.setrecursionlimit(311111)
ikimasu = sys.stdin.buffer.readline
ini = lambda : int(ins())
ina = lambda : list(map(int, ikimasu().split()))
ins = lambda : ikimasu().strip()
codeforces = ini()
for _ in range(codeforces):
	n = ini()
	tmp = ina()
	rick = 0
	for i in tmp:
		if i == 0:
			rick += 1
	for i in tmp:
		if i == 0:
			rick -= 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if tmp[i] == 0:
			rick -= 1
		else:
			break
	print(rick)


for _ in range(int(input())):
	n = int(input())
	lst = [int(i) for i in input().split()]
	ind = lst.index(1)
	sum1 = 0
	nk = 0
	for i in range(ind + 1, n):
		if lst[i] == 0:
			nk += 1
		else:
			sum1 += nk
			nk = 0
	print(sum1)


inp = lambda : int(input())
strl = lambda : list(input().strip())
seq = lambda : list(map(int, input().strip().split()))

def f(arr, n):
	i = n - 1
	cnt2 = 0
	while i > 0:
		if arr[i] == 1:
			break
		i -= 1
		cnt2 += 1
	i = 0
	cnt3 = 0
	while i < n:
		if arr[i] == 1:
			break
		i += 1
		cnt3 += 1
	cnt = arr.count(0)
	return max(0, cnt - cnt2 - cnt3)

def main():
	t = inp()
	for _ in range(t):
		n = inp()
		a = seq()
		result = f(a, n)
		print(result)
main()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	x = arr.index(1)
	y = -1
	for i in range(n - 1, -1, -1):
		if arr[i] == 1:
			y = i
			break
	c = 0
	for i in range(x, y):
		if arr[i] == 0:
			c += 1
	print(c)


t = int(input())
for q in range(t):
	n = int(input())
	ans = 0
	l = list(map(int, input().split()))
	for i in range(0, n):
		if l[i] == 0 and 1 in l[:i] and (1 in l[i:]):
			ans += 1
	print(ans)


for i in range(int(input())):
	m = int(input())
	l = list(map(int, input().split()))
	i = 1
	sum = 0
	while i < m - 1:
		p1 = 0
		if l[i - 1] == 1:
			while l[i] == 0 and i < m - 1:
				p1 += 1
				i += 1
		if l[i] == 1:
			sum += p1
		i += 1
	print(sum)


tests = int(input())
answers = []
for test in range(tests):
	n = int(input())
	books = list(map(int, input().split()))
	temp = books[::-1]
	try:
		w = temp.index(1)
	except:
		print(0)
		continue
	books = books[:n - w]
	n = n - w
	i = 0
	j = 0
	moves = 0
	while i < n:
		if books[i] == 1:
			while j < n and books[j] == 1:
				j += 1
		if books[i] == 0:
			if i == 0:
				while j < n and books[j] == 0:
					j += 1
			else:
				while j < n and books[j] == 0:
					j += 1
					moves += 1
		i = j
	answers.append(moves)
for i in answers:
	print(i)


for tt in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = []
	i = 0
	strt = l.index(1)
	i = strt
	end = i
	for j in range(i, n):
		if l[j] == 1:
			end = j
	print(l[i:end + 1].count(0))


t = int(input())
for _ in range(t):
	n = int(input())
	lst = input().split()
	rlst = list(reversed(lst))
	k = n - rlst.index('1') - 1
	lst = lst[lst.index('1'):k]
	print(lst.count('0'))


for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = -1
	c = 0
	for i in range(n):
		if l[i] == 1:
			if x == -1:
				x = i
			else:
				c += i - x - 1
				x = i
	print(c)


g = int(input())
for i in range(g):
	h = int(input())
	a = input().split()
	b = a[::-1]
	if '1' in a:
		c = a.index('1')
		d = len(a) - b.index('1')
		e = 0
		for i in range(c, d):
			if a[i] == '0':
				e += 1
		print(e)
	else:
		print(0)


t = int(input())
for z in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	f_index = -1
	flag = True
	cnt = 0
	for i in range(len(arr)):
		if arr[i] == 1:
			cnt = cnt + 1
			if flag:
				flag = False
				f_index = i
	ls = 1
	res = 0
	for i in range(f_index + 1, len(arr)):
		if cnt == ls:
			break
		if arr[i] == 0:
			res = res + 1
		if arr[i] == 1:
			ls = ls + 1
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	Au = A.copy()
	Au.reverse()
	if A.count(1) > 1:
		x = A.index(1)
		x1 = Au.index(1)
		x1 = n - x1
		A = A[x:x1]
		print(A.count(0))
	else:
		print(0)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	found = False
	cnt = 0
	ans = 0
	for i in range(len(a)):
		if a[i] == 0:
			cnt += 1
		else:
			if found:
				ans += cnt
			found = True
			cnt = 0
	print(ans)


for w in range(int(input())):
	input()
	a = input().split()
	b = []
	e = f = 0
	for i in a:
		if i == '1':
			if e != 0:
				b.append(e)
				e = 0
			f += 1
		else:
			if f != 0:
				b.append('*')
				f = 0
			e += 1
	if e != 0:
		b.append(e)
	if f != 0:
		b.append('*')
	r1 = b.index('*')
	r2 = len(b) - b[::-1].index('*') - 1
	s = 0
	for i in range(r1, r2):
		if b[i] != '*':
			s += b[i]
	print(s)


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	alst = list(map(int, input().split()))
	flg = False
	ans = 0
	for (i, a) in enumerate(alst):
		if a == 1:
			if not flg:
				flg = True
			else:
				ans += i - bef - 1
			bef = i
	print(ans)
for _ in range(int(input())):
	main()


t = int(input())
for ii in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ind1 = None
	ind2 = None
	for i in range(n):
		if ind1 == None and l[i] == 1:
			ind1 = i
		if l[i] == 1:
			ind2 = i
	cnt = 0
	for i in range(ind1, ind2 + 1):
		if l[i] == 0:
			cnt += 1
	print(cnt)


for cnt in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	l = 0
	while b[l] == 0:
		l += 1
	r = n - 1
	while b[r] == 0:
		r -= 1
	res = 0
	for i in range(l, r + 1):
		if b[i] == 0:
			res += 1
	print(res)


for i in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	lst2 = lst.copy()
	lst2.reverse()
	print(abs(n - lst2.index(1) - lst.index(1)) - lst.count(1))


for t in range(int(input())):
	n = int(input())
	entry = input().split(' ')
	while entry[0] == '0':
		entry.pop(0)
	while entry[len(entry) - 1] == '0':
		entry.pop(len(entry) - 1)
	cont = 0
	for i in entry:
		cont += int(i)
	print(len(entry) - cont)


testCases = int(input())
while testCases > 0:
	n = int(input())
	bookShelf = input().split()
	shifts = 0
	flagFront = False
	lastOne = -1
	front = -1
	end = -1
	for j in range(n):
		if bookShelf[j] == '1':
			if flagFront == False:
				flagFront = True
				front = j
			lastOne = j
	end = lastOne
	for i in range(front + 1, end):
		if bookShelf[i] == '0':
			shifts += 1
	print(shifts)
	testCases -= 1


t = int(input())
for h in range(t):
	f = int(input())
	n = list(map(int, input().split()))
	x = 0
	for i in range(f):
		if n[i] == 0:
			n[i] = 2
		elif n[i] == 1:
			break
	n = n[::-1]
	for i in range(f):
		if n[i] == 0:
			n[i] = 2
		elif n[i] == 1:
			break
	for i in range(f):
		if n[i] == 0:
			x += 1
	print(x)


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	prev = 0
	new = []
	for i in range(n):
		if prev != 1 and ar[i] == 1:
			new.append(1)
			prev = 1
		elif ar[i] == 0:
			new.append(0)
			prev = 0
	if new.count(1) == 0 or new.count(1) == 1:
		print(0)
	else:
		ind = []
		for i in range(len(new)):
			if new[i] == 1:
				ind.append(i)
		s = 0
		for i in range(len(ind) - 1):
			s += abs(-ind[i] + ind[i + 1] - 1)
		print(s)


quant = int(input())
array = []
o = -1
for i in range(0, quant):
	quantity = int(input())
	count = list(map(int, input().split()))
	i = 0
	o = -1
	array = []
	for i in range(len(count)):
		if count[i] == 1:
			array = array + [0]
			o = o + 1
			array[o] = i
	counter = 0
	for i in range(len(array) - 1, 0, -1):
		counter = counter + (array[i] - array[i - 1] - 1)
	if counter > 0:
		print(counter)
	else:
		print('0')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	gap = 0
	count1 = 0
	seen = False
	for x in a:
		if x == 0:
			gap += 1
		elif x == 1 and seen:
			count1 += gap
			gap = 0
			seen = True
		else:
			seen = True
			gap = 0
	count2 = 0
	seen = False
	for x in a[::-1]:
		if x == 0:
			gap += 1
		elif x == 1 and seen:
			count2 += gap
			gap = 0
			seen = True
		else:
			seen = True
			gap = 0
	print(min(count1, count2))


def solve():
	n = int(input())
	lst = list(map(int, input().split()))
	while len(lst) > 0 and lst[-1] == 0:
		lst.pop()
	od = False
	ans = 0
	for i in lst:
		if i == 0 and od:
			ans += 1
		if i == 1:
			od = True
	print(ans)
for i in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	ss = 0
	cnt = 0
	k = 0
	for i in a:
		if i == 0:
			cnt += 1
		else:
			if cnt and k:
				ss += cnt
			cnt = 0
			k += 1
	print(ss)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = False
	i = n - 1
	cnt = 0
	while i >= 0:
		if l[i] == 1:
			break
		cnt += 1
		i -= 1
	count = 0
	for i in l[0:n - cnt]:
		if ans == False and i == 1:
			ans = True
		if ans == True and i == 0:
			count += 1
	print(count)


a = int(input())
for i in range(0, a):
	b = int(input())
	c = list(map(int, input().split()))
	y = 0
	e = 0
	h = []
	for i in range(0, b):
		if c[i] == 1 and y == 0:
			y = 1
		if c[i] == 1 and y == 1 and (e > 0):
			y = 1
			h.append(e)
			e = 0
		if c[i] == 0 and y == 1:
			e = e + 1
	print(sum(h))


for i in range(int(input())):
	a = int(input())
	b = input()
	c = b.strip('0 ')
	print(c.count('0'))


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))[:n]
	if a.count(1) == 1 or a.count(1) == 0:
		print(0)
	else:
		start = a.index(1)
		end = n - 1 - a[::-1].index(1)
		new_list = a[start:end]
		print(new_list.count(0))
	t = t - 1


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = input().split()
	(l, r, c) = (-1, -1, 0)
	for (i, e) in enumerate(a):
		if e == '1':
			if l == -1:
				l = i
			r = i
	for e in a[l + 1:r]:
		if e == '0':
			c += 1
	print(0 if l == r else c)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	a = l[::-1].index(1)
	j = 0
	while j < n - 1 - a:
		if l[j] == 1 and l[j + 1] == 0:
			c = 0
			j += 1
			while l[j] == 0:
				ans += 1
				j += 1
		else:
			j += 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for j in range(int(input())):
	n = int(input())
	vals = list(map(int, input().split()))
	gap = 0
	count = 0
	check = False
	for s in range(n):
		if vals[s] == 0:
			if check == True:
				count += 1
		elif check == True:
			gap += count
			count = 0
		else:
			check = True
	print(gap)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def msi():
	return map(str, input().split())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	return x * y // gcd(x, y)
mod = 1000000007

def modInverse(b, m):
	g = gcd(b, m)
	if g != 1:
		return -1
	else:
		return pow(b, m - 2, m)

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def modu(a, b, m):
	a = a % m
	inv = modInverse(b, m)
	if inv == -1:
		return -999999999
	else:
		return inv * a % m
from math import log, sqrt, factorial, cos, tan, sin, radians, floor
import bisect
from decimal import *
getcontext().prec = 8
abc = 'abcdefghijklmnopqrstuvwxyz'
pi = 3.141592653589793

def fun(a, n):
	s = 0
	if n == 1:
		return s
	for i in range(n):
		b = []
		b.extend(a[0:i])
		c = a[i + 1:]
		b.extend(c)
		s += fun(b, n - 1)

def isP(n):
	c = 0
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			c += 1
	if c:
		return False
	return True
pr = []
for i in range(101, 1050):
	if isP(i):
		pr.append(i)

def main():
	for _ in range(ii()):
		n = ii()
		a = li()
		ans = 0
		pos1 = pos2 = -1
		for i in range(n):
			if a[i] == 1:
				pos1 = i
				break
		for i in range(n - 1, -1, -1):
			if a[i] == 1:
				pos2 = i
				break
		if pos1 == -1 or pos2 == -1:
			print(0)
			continue
		c = 0
		for i in range(pos1 + 1, pos2):
			if a[i] == 0:
				c += 1
			else:
				ans += c
				c = 0
		ans += c
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math
from collections import Counter, defaultdict, deque

def f(n, a):
	x = 0
	f = False
	f1 = True
	for pos in range(n):
		if a[pos] == 1:
			if not f:
				f = True
			l1 = pos
		if f and a[pos] == 0:
			x += 1
	if a[-1] == 0:
		return x - (pos - l1)
	else:
		return x
t = int(input())
result = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	result.append(f(n, a))
for i in range(t):
	print(result[i])


t = int(input())
import array as arr
ans = arr.array('i', [0] * t)
for j in range(t):
	n = int(input())
	x = arr.array('i', list(map(int, input().split())))
	c = 0
	i = 0
	while i != n - 1:
		ci = 0
		if x[i] == 1:
			while x[i + 1] != 1:
				if i == n - 2:
					ci = 0
					break
				ci += 1
				i += 1
		c += ci
		i += 1
	ans[j] = c
for i in ans:
	print(i)


t = int(input())
w = []
for i in range(t):
	l = []
	n = int(input())
	x = list(map(int, input().split()))
	l.append(x[0])
	for i in range(1, n):
		if x[i] == 0:
			l.append(0)
		elif l[-1] != 1:
			l.append(1)
	r = l.count(1)
	if r == 1:
		w.append(0)
	else:
		c = 0
		for i in range(len(l)):
			if l[i] == 1:
				break
			else:
				c = c + 1
		k = list(reversed(l))
		for i in range(len(k)):
			if k[i] == 1:
				break
			else:
				c = c + 1
		w.append(l.count(0) - c)
for i in w:
	print(i)


t = int(input())
for i in range(0, t):
	m = int(input())
	str1 = input()
	x = str1.find('1')
	y = str1.rfind('1')
	if x == y:
		ans = 0
	else:
		str2 = str1[x:y + 1]
		z = str2.count('0')
		ans = z
	print(ans)


def yet_another_bookshelf():
	for _ in range(int(input())):
		ans = 0
		a = input()
		b = list(map(int, input().split()))
		for i in range(len(b)):
			if b[i] == 1:
				d = []
				d.append(b[i])
				for j in range(i + 1, len(b)):
					d.append(b[j])
					if b[j] == 1:
						ans += d.count(0)
						break
		print(ans)
yet_another_bookshelf()


t = int(input())

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	indices = []
	for i in range(n):
		if arr[i] == 1:
			indices.append(i)
	leftMost = indices[0]
	rightMost = indices[-1]
	count1 = 10000
	for i in range(len(indices)):
		count = 0
		s1 = indices[0:i]
		s2 = indices[i + 1:len(indices)]
		s1.reverse()
		for j in range(len(s1)):
			if j == 0:
				count += abs(indices[i] - s1[j]) - j - 1
			else:
				count += abs(s1[j] - s1[j - 1]) - 1
		for j in range(len(s2)):
			if j == 0:
				count += abs(indices[i] - s2[j]) - j - 1
			else:
				count += abs(s2[j] - s2[j - 1]) - 1
		count1 = min(count, count1)
	print(count1)
for i in range(t):
	solve()


import sys
tests = int(sys.stdin.readline())
for _ in range(tests):
	shelves = int(sys.stdin.readline().strip())
	places = list(map(int, sys.stdin.readline().split()))
	gap_on = False
	count = 0
	for p in places:
		if not gap_on and p == 0:
			continue
		if p == 1:
			gap_on = True
		if p == 0:
			count += 1
	if places[-1] == 0:
		places.reverse()
		count -= places.index(1)
	print(count)
	1


t = int(input())
for _ in range(t):
	n = int(input())
	l = input().split()
	p = 0
	q = n - 1
	if l == ['1'] * n:
		print(0)
	else:
		while l[p] != '1':
			p += 1
		while l[q] != '1':
			q -= 1
		if p == q:
			print(0)
		else:
			l1 = l[p:q + 1]
			print(l1.count('0'))


n = int(input())
for i in range(n):
	n = int(input())
	print(input().strip('0 ').count('0'))


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
for _ in range(int(input())):
	q = int(input())
	w = list(map(int, input().split()))
	e = 0
	r = 0
	t = 0
	for i in w:
		if e == 1 and i == 0:
			r += 1
		if e == 1 and i == 1:
			t = r
		if i == 1:
			e = 1
	print(t)


for _ in range(int(input())):
	n = int(input())
	s = input().replace(' ', '')
	l = s.index('1')
	r = n - s[::-1].index('1') - 1
	print(s[l:r].count('0'))


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	(l, r) = (0, n - 1)
	while s[l] != 1 and l < n:
		l += 1
	while s[r] != 1 and r > 0:
		r -= 1
	if l >= r:
		print(0)
	else:
		ans = 0
		for i in range(l, r + 1):
			if s[i] == 0:
				ans += 1
		print(ans)


t = int(input())
import re
for _ in range(t):
	n = int(input())
	(*a,) = input().split()
	for i in range(n):
		if a[i] == '1':
			break
		a[i] = '1'
	for i in range(n - 1, -1, -1):
		if a[i] == '1':
			break
		a[i] = '1'
	sta = ''.join(a)
	re.sub('1+', '1', sta)
	a = sta.split('1')
	aa = [len(ai) for ai in a]
	ans = sum(aa)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	cnt = 0
	f = 0
	d = l.count(1)
	if d == 1:
		print(0)
	else:
		for i in range(n):
			if l[i] == 1:
				f = 1
				d -= 1
			elif f == 1 and d > 0:
				cnt += 1
		print(cnt)


casos = int(input())
for i in range(casos):
	numBooks = int(input())
	books_stack = input().split(' ')
	num_zeros_iad = 0
	num_zeros_dai = 0
	found_first_one = False
	reversed_list = False
	one_count = 0
	books_stack3 = []
	for j in range(len(books_stack)):
		if books_stack[j] == '1':
			books_stack3 = books_stack[j:len(books_stack)]
			j = len(books_stack)
			break
	books_stack3 = books_stack3[::-1]
	books_stack2 = []
	for j in range(len(books_stack3)):
		if books_stack3[j] == '1':
			books_stack2 = books_stack3[j:len(books_stack)]
			j = len(books_stack3)
			break
	x = 0
	while x < len(books_stack2):
		if books_stack2[x] == '1':
			one_count += 1
		if x == len(books_stack2) - 1 and reversed_list == False:
			if one_count <= 1:
				num_zeros_iad = 0
				num_zeros_dai = 0
				break
			books_stack2 = books_stack2[::-1]
			reversed_list = True
			x = 0
		if found_first_one == False:
			if books_stack2[x] == '1':
				found_first_one = True
		elif books_stack2[x] == '0':
			if reversed_list == False:
				num_zeros_iad += 1
			else:
				num_zeros_dai += 1
		x += 1
	if num_zeros_iad < num_zeros_dai:
		print(num_zeros_iad)
	else:
		print(num_zeros_dai)


a = []
for i in range(int(input())):
	input()
	a.append(input().replace(' ', ''))
for i in a:
	if i.count('1') == 1:
		print(0)
	elif i.count('0') == 0:
		print(0)
	else:
		t = i.index('1')
		print(i.count('0', i.index('1'), i.rindex('1')))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	count = 0
	ind = -1
	for i in range(n):
		if arr[i] == 1:
			ind = i
			break
	last = n
	for i in range(n - 1, -1, -1):
		if arr[i] == 1:
			last = i
			break
	for i in range(ind, last):
		if arr[i] == 0:
			count += 1
	print(count)


import math
import sys
from collections import OrderedDict

class Graph:

	def __init__(self, Nodes, is_directed=False):
		self.nodes = Nodes
		self.adj_list = {}
		self.is_directed = is_directed
		for node in self.nodes:
			self.adj_list[node] = []

	def add_edge(self, u, v):
		self.adj_list[u].append(v)
		if self.is_directed == False:
			self.adj_list[v].append(u)

	def print_graph(self):
		for node in self.nodes:
			print(node, '->', self.adj_list[node])

	def degree_node(self, node):
		return len(self.adj_list[node])

	def dfsUTIL(self, v, visited, parents=[]):
		visited[v] = True
		for i in self.adj_list[v]:
			if visited[i] == False:
				self.dfsUTIL(i, visited, parents)
				parents.append(i)

	def dfs(self, v):
		visited = [False] * (max(self.adj_list) + 1)
		parents = [v]
		self.dfsUTIL(v, visited, parents)
		return parents

def dict_sort(ans):
	ans = sorted(ans.items(), reverse=True, key=lambda kv: kv[1])

def is_prime(n):
	if n == 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def seive_primes(n):
	flag = [0] * (n + 10)
	flag[1] = flag[0] = 1
	i = 2
	while i * i <= n + 1:
		if flag[i] == 0:
			j = i * i
			while j <= n + 1:
				flag[j] = 1
				j += i
		i += 1
	return flag

def factors(n):
	d = {}
	while n % 2 == 0:
		if 2 in d:
			d[2] += 1
		else:
			d[2] = 1
		n /= 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
			n /= i
	n = int(n)
	if n > 1:
		d[n] = 1
	return d

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def alphabates():
	return 'abcdefghijklmnopqrstuvwxyz'

def binary_search(ls, n, flag):
	low = 0
	hi = n - 1
	while low <= hi:
		mid = (low + hi) // 2
		if ls[mid] == flag:
			return mid
		elif ls[mid] > flag:
			hi = mid - 1
		else:
			low = mid + 1
	return -1

def qdrt(a, b, c):
	chk = b * b - 4 * a * c
	if chk >= 0:
		ans1 = (-b + chk ** 0.5) / (2 * a)
		ans2 = (-b - chk ** 0.5) / (2 * a)
		return [int(ans1), int(ans2)]
	return -1

def permutation(n, r):
	if n < r:
		return 0
	ans = 1
	for i in range(n - r + 1, n + 1):
		ans *= i
	return ans

def combination(n, r):
	if n < r:
		return 0
	ans = 1
	for i in range(r):
		ans *= n - i
	div = 1
	for i in range(2, r + 1):
		div *= i
	return ans // div

def ispow2(n):
	ans = int(math.log(n, 2))
	if 2 ** ans == n:
		return True
	return False

def _2dmat(n):
	flag = [[i + 1 for i in range(n)]]
	for i in range(2, n + 1):
		new = []
		for j in range((i - 1) * n + 1, i * n + 1):
			new.append(j)
		flag.append(new)
	return flag

def sumn(n):
	return n * (n + 1) // 2

def arrinp():
	ls = list(map(int, input().split()))
	return ls

def mult_inp():
	return map(int, input().split())

def main():
	n = int(input())
	ls = arrinp()
	ans = 0
	dp = []
	for i in range(n):
		if ls[i] == 1:
			dp.append(i)
	for i in range(1, len(dp)):
		ans += dp[i] - dp[i - 1] - 1
	print(ans)
for _ in range(int(input())):
	main()


import sys
import math
import bisect
from sys import stdin, stdout
from math import floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
mod = 1000000007

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def mod_inverse(a, n):
	N = n
	xx = 0
	yy = 1
	y = 0
	x = 1
	while n > 0:
		q = a // n
		t = n
		n = a % n
		a = t
		t = xx
		xx = x - q * xx
		x = t
		t = yy
		yy = y - q * yy
		y = t
	x %= N
	x += N
	x %= N
	return x

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	return prime

def solve():
	n = int(input())
	l = [int(i) for i in input().split()][:n]
	if l.count(0) == 0:
		print(0)
	else:
		(x, y) = (-1, -1)
		for i in range(n):
			if l[i] == 0:
				if x != -1:
					break
			else:
				x = i
		for i in range(n - 1, -1, -1):
			if l[i] == 0:
				if y != -1:
					break
			else:
				y = i
		cnt = 0
		for i in range(x, y):
			if l[i] == 0:
				cnt += 1
		print(cnt)
testcase = int(sys.stdin.readline())
for _ in range(testcase):
	solve()


import sys, collections
tc = int(sys.stdin.readline())
for _ in range(tc):
	n = int(sys.stdin.readline())
	arr = list(map(int, sys.stdin.readline().split()))
	left = arr.index(1)
	right = 0
	for i in range(n):
		if arr[i] == 1:
			right = i
	ans = 0
	for i in range(left, right + 1):
		if arr[i] == 0:
			ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	A = [int(x) for x in input().split()]
	beg = 0
	end = 0
	for i in range(n):
		if A[i] == 1:
			beg = i
			break
	for i in range(n - 1, -1, -1):
		if A[i] == 1:
			end = i
			break
	count = 0
	for i in range(beg, end + 1):
		if A[i] == 0:
			count += 1
	print(count)


t = int(input())
while t:
	t = t - 1
	n = int(input())
	ans = n + 1
	a = [int(ai) for ai in input().split()]
	las = 0
	num = 0
	fir = 0
	for i in range(len(a)):
		if a[i] == 1:
			las = i + 1
			num = num + 1
			if fir == 0:
				fir = i + 1
	if ans > las - num - fir + 1:
		ans = las - num - fir + 1
	las = 0
	num = 0
	fir = 0
	for i in range(len(a) - 1, -1, -1):
		if a[i] == 1:
			las = i + 1
			num = num + 1
			if fir == 0:
				fir = i + 1
	if ans > n - las + 1 - num + n - fir:
		ans = n - las + 1 - num + n - fir
	print(ans)


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def NLI(n):
	return [[int(i) for i in input().split()] for i in range(n)]

def NLI_(n):
	return [[int(i) - 1 for i in input().split()] for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def RLI(n=8, a=1, b=10):
	return [random.randint(a, b) for i in range(n)]

def RI(a=1, b=10):
	return random.randint(a, b)

def INP():
	N = 10
	A = 10
	n = random.randint(1, N)
	a = [random.randint(1, A) for i in range(n)]
	return (n, a)

def Rtest(T):
	(case, err) = (0, 0)
	for i in range(T):
		inp = INP()
		a1 = naive(*inp)
		a2 = solve(*inp)
		if a1 != a2:
			print((a1, a2), inp)
			err += 1
		case += 1
	print('Tested', case, 'case with', err, 'errors')

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()
show_flg = False
show_flg = True
ans = 0
for _ in range(I()):
	ans = 0
	n = I()
	a = deque(LI())
	while a and a[0] == 0:
		a.popleft()
	while a and a[-1] == 0:
		a.pop()
	ans = a
	print(a.count(0))


import sys

def solve():
	k = int(input())
	s = input()
	i = s.find('1')
	j = s.rfind('1')
	c = 0
	for w in range(i + 1, j):
		if s[w] == '0':
			c += 1
	print(c)
a = int(input())
for i in range(a):
	solve()


import sys
from collections import defaultdict
from sys import maxsize

def ini():
	return int(sys.stdin.readline())

def inp():
	return map(int, sys.stdin.readline().strip().split())

def li():
	return list(map(int, sys.stdin.readline().strip().split()))
for _ in range(ini()):
	n = ini()
	l = li()
	(a, b) = (0, 0)
	for i in range(n):
		if l[i] == 1:
			break
	for j in range(n - 1, -1, -1):
		if l[j] == 1:
			break
	t = []
	c = 0
	for k in range(i, j + 1):
		if l[k] == 0:
			c += 1
		else:
			t.append(c)
			c = 0
	if c:
		t.append(c)
	print(sum(t))


def solve(nums):
	s = e = None
	cnt = 0
	for (i, n) in enumerate(nums):
		if n == 1:
			cnt += 1
			if s is None:
				s = i
			e = i
	return e - s + 1 - cnt
for _ in range(int(input())):
	n = int(input())
	nums = [int(x) for x in input().split()]
	print(solve(nums))


n = int(input())
all_shelfs = []
for i in range(n):
	k = int(input())
	shelf = [int(x) for x in input().split(' ')]
	all_shelfs.append(shelf)
for shelf in all_shelfs:
	try:
		first = shelf.index(1)
		last = len(shelf) - shelf[::-1].index(1) - 1
	except ValueError:
		first = 0
		last = 0
	moves = shelf[first:last].count(0)
	print(moves)


def f(l, k):
	return l - k[::-1].index('1') - k.index('1') - k.count('1')
for i in range(int(input())):
	print(f(int(input()), input().split()))


T = int(input())
for I in range(0, T):
	N = int(input())
	X = input().split(' ')
	if '1' in X:
		X = X[X.index('1'):]
	if '1' in X:
		R = X[::-1]
		R = R[R.index('1'):]
		X = R[::-1]
	M = 0
	for I in X:
		if I == '0':
			M += 1
	print(M)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	i = 0
	while i < n:
		if l[i] == 1:
			j = i + 1
			count = 0
			while j < n:
				if l[j] == 1:
					ans += count
					break
				count += 1
				j += 1
			i = j
			continue
		i += 1
	print(ans)


for i in range(int(input())):
	l = int(input())
	p = list(map(int, input().split()))
	pos = []
	for j in range(l):
		if p[j] == 1:
			pos.append(j)
	s = min(pos)
	e = max(pos)
	c = 0
	for j in range(s, e + 1):
		if p[j] == 0:
			c += 1
	print(c)


import math
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(n):
		if l[i]:
			break
	for j in range(n - 1, -1, -1):
		if l[j]:
			break
	print(l[i + 1:j].count(0))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if n <= 2:
		print(0)
		continue
	else:
		i = 0
		while arr[i] != 1:
			del arr[i]
		i = 0
		while i < len(arr):
			if arr[i] == 0:
				i += 1
				continue
			else:
				while i + 1 < len(arr) and arr[i + 1] == 1:
					del arr[i]
				i += 1
		if arr[len(arr) - 1] == 0:
			i = len(arr) - 1
			while arr[i] == 0:
				del arr[i]
				i -= 1
	print(arr.count(0))


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	cnt = 0
	c = 0
	C = []
	for i in range(n):
		if A[i] == 0 and c == 1:
			cnt += 1
		elif A[i] == 1:
			c = 1
			if cnt != 0:
				C.append(cnt)
			cnt = 0
	ans = 0
	for i in C:
		ans += i
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(zerosBetween, ans) = (0, 0)
	oneIsPresent = False
	for i in a:
		if i == 1:
			oneIsPresent = True
			ans += zerosBetween
			zerosBetween = 0
		elif oneIsPresent:
			zerosBetween += 1
	print(ans)


loopcount = int(input())
for loop in range(loopcount):
	a = int(input())
	x = input()
	x = x.split(' ')
	x = list(map(int, x))
	index = []
	move = 0
	for i in range(len(x)):
		if x[i] == 1:
			index.append(i)
	for i in range(len(index) - 1):
		move += index[i + 1] - index[i] - 1
	print(move)


from collections import Counter
T = int(input())

def Compute():
	n = int(input())
	Arr = [int(i) for i in input().split(' ')]
	CountOfOnes = Counter(Arr)
	CountOfOnes = CountOfOnes[1]
	count = 0
	value = 0
	i = 0
	firstone = 0
	while i < len(Arr):
		if count == CountOfOnes:
			return value
		if Arr[i] == 1:
			count = count + 1
			i = i + 1
			firstone = 1
			continue
		if firstone == 1:
			value = value + 1
		i = i + 1
	return value
for t in range(T):
	print(Compute())


for _ in range(int(input())):
	n = int(input())
	a = input()
	print(a.strip('0 ').count('0'))


for _ in range(int(input())):
	n = int(input())
	a = list(map(str, input().split()))
	s = ''.join(a)
	s = s.strip('0')
	c = 0
	for i in range(len(s)):
		if s[i] == '0':
			c = c + 1
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	l = []
	for i in range(n):
		if li[i] == 1:
			l.append(i)
	c = 0
	if len(l) == 1:
		print(0)
	else:
		for i in range(len(l) - 1):
			c += abs(l[i + 1] - l[i] - 1)
		print(c)


l = []
for _ in range(int(input())):
	n = int(input())
	a = list(input().split())
	s = []
	count = 0
	flag = 1
	for i in range(n):
		if a[i] == '0':
			count = count + 1
			flag = 1
		elif flag == 1:
			s.append(count)
			count = 0
			flag = 0
	if a[0] == '0':
		s = s[1:]
	l.append(sum(s))
for i in l:
	print(i)


for a0 in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	tp = -1
	for i in range(n):
		if l[i] == 1:
			if tp == -1:
				tp += 1
		elif tp >= 0 and 1 in l[i:]:
			tp += 1
	print(tp)


for i in range(int(input())):
	b = int(input())
	a = [int(i) for i in input().split()]
	summ = 0
	c = []
	for j in range(b):
		if a[j] == 1:
			c.append(j)
	for j in range(1, len(c)):
		summ += c[j] - c[j - 1] - 1
	print(summ)


n = int(input())
for i in range(n):
	t = int(input())
	ar = list(map(int, input().split()))
	for i in range(len(ar)):
		if ar[i] == 1:
			x = i
			break
	for i in range(len(ar) - 1, -1, -1):
		if ar[i] == 1:
			y = i
			break
	m = ar[x:y + 1]
	ans = m.count(0)
	print(ans)


t = int(input())

def yet_another_book(books_in_bookself):
	steps = 0
	for i in range(n):
		count = 0
		if books_in_bookself[i] == 1:
			for j in range(i + 1, n):
				if books_in_bookself[j] == 0:
					count += 1
				elif books_in_bookself[j] == 1 and count > 0:
					steps += count
					break
				else:
					break
	return steps
result = []
for i in range(t):
	n = int(input())
	books_in_bookself = [int(a) for a in input().split(' ')]
	result.append(yet_another_book(books_in_bookself))
for i in range(t):
	print(f'{result[i]}')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	ans = 0
	one = 0
	for i in range(n):
		if a[i] == 1:
			for j in range(i + 1, n):
				if a[j] == 1:
					break
				elif 1 not in a[j + 1:]:
					break
				else:
					count += 1
	if a.count(1) == 1:
		print(0)
	else:
		print(count)


s = ''
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = 0
	if 1 in a:
		ind = a.index(1)
		for i in range(n - 1, -1, -1):
			if a[i] == 1:
				last = i
				break
		if last == ind:
			d = 0
		else:
			for i in range(ind, last):
				if a[i] == 0:
					d += 1
		print(d)
	else:
		print(0)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	if a.count(0) == len(a):
		print(0)
	leftmostOne = 0
	while a[leftmostOne] != 1:
		leftmostOne += 1
	rightmostOne = len(a) - 1
	while a[rightmostOne] != 1:
		rightmostOne -= 1
	ans = a[leftmostOne:rightmostOne + 1].count(0)
	print(ans)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	start = 0
	end = 0
	count = 0
	for i in range(n):
		if l[i] == 1:
			start = i
			break
	for i in range(n - 1, -1, -1):
		if l[i] == 1:
			end = i
			break
	for i in range(start, end + 1):
		if l[i] == 0:
			count += 1
	print(count)


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	c = Counter(a)
	total = 0
	if len(c) == 1 or c[1] == 1:
		print(0)
	else:
		if a[0] == 0:
			while a[0] == 0:
				a.pop(0)
		if a[-1] == 0:
			while a[-1] == 0:
				a.pop(-1)
		c = Counter(a)
		print(c[0])


t = int(input())
for i in range(t):
	n = int(input())
	booklist = input().strip(' ')
	zerocount = 0
	for j in range(booklist.find('1') + 1, booklist.rfind('1')):
		if booklist[j] == '0':
			zerocount += 1
	print(zerocount)


s = int(input())
for i in range(s):
	n = input()
	a = list(map(int, input().split()))
	a1 = 0
	a2 = 0
	for ai in range(len(a)):
		if a[ai] == 1:
			a1 = ai
			break
	for ai in range(len(a) - 1, 0, -1):
		if a[ai] == 1:
			a2 = ai
			break
	count = 0
	for ai in a[a1:a2]:
		if ai == 0:
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	l = 0
	cnt = 0
	flag = True
	for a in A:
		if a == 0:
			cnt += 1
		elif flag:
			cnt = 0
			flag = False
		else:
			l += cnt
			cnt = 0
	r = 0
	cnt = 0
	flag = True
	A.reverse()
	for a in A:
		if a == 0:
			cnt += 1
		elif flag:
			cnt = 0
			flag = False
		else:
			r += cnt
			cnt = 0
	print(min(l, r))


a = int(input())
vs = []
for i in range(a):
	x = int(input())
	x2 = input().split()
	vs.append(x2)
for x in vs:
	r = 0
	lf = 0
	rg = len(x) - 1
	while x[lf] != '1':
		lf += 1
	while x[rg] != '1':
		rg -= 1
	xd = x[lf:rg + 1]
	for i in xd:
		if i == '0':
			r += 1
	print(r)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	ans = 0
	(prev, curr) = (None, None)
	(first, Last) = (None, None)
	for i in range(n):
		if a[i] == 1:
			if first is None:
				first = i
			Last = i
			curr = i
			if prev is None:
				prev = i
			ans += max(0, curr - prev - 1)
			prev = curr
	print(ans)


import math, sys, os
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def minp():
	return map(int, sys.stdin.readline().rstrip().split())

def linp():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def inp():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
for _ in range(inp()):
	n = inp()
	a = linp()
	count0 = 0
	for i in range(n):
		if a[i] == 1:
			break
		count0 += 1
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			break
		count0 += 1
	print(a.count(0) - count0)


for i in range(int(input())):
	n = int(input())
	a = list(map(str, input().split()))
	s = ''
	for x in a:
		s += x
	s = str(int(s))
	s = str(int(s[::-1]))
	print(s.count('0'))


def inp():
	return int(input())

def inl():
	return [int(i) for i in input().split()]
p = inp()
for _ in range(p):
	n = inp()
	x = inl()
	flag = True
	cnt = 0
	p = 0
	for i in x:
		if i == 1:
			flag = False
			cnt += p
			p = 0
		elif flag == False and i == 0:
			p += 1
	print(cnt)


for _ in range(0, int(input())):
	input()
	v = list(map(int, input().split()))
	c = sum(v)
	i = 0
	a = 0
	s = False
	while c > 0:
		if v[i] == 1:
			c -= 1
			s = True
		elif s:
			a += 1
		i += 1
	print(a)


from collections import deque
for tt in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	d = deque()
	for i in range(n):
		if s[i] == 1:
			d.append(i)
	r1 = d[0]
	r2 = d[-1]
	cnt = 0
	for i in range(r1, r2 + 1):
		if s[i] == 0:
			cnt += 1
	c = deque()
	c.append(cnt)
	for i in c:
		print(i)


t = int(input())
for iii in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	s = []
	x = 0
	for ii in range(len(a)):
		if a[ii] == 1:
			s.append(ii)
	for i in range(len(s) - 1):
		x += s[i + 1] - s[i] - 1
	print(x)


t = int(input())
for _ in range(t):
	n = int(input())
	v = input().split()
	gap = False
	l = 0
	total = 0
	for b in v:
		book = int(b)
		if book == 1:
			if gap and l > 0:
				total += l
			gap = True
			l = 0
		else:
			l += 1
	print(total)


t = int(input())
for test_case in range(t):
	n = [int(x) for x in input().split()]
	n = n[0]
	a = [int(y) for y in input().split()]
	for i in range(n):
		if a[i] == 1:
			point = i
			break
	res = 0
	summ = 0
	for i in range(point + 1, n):
		if a[i] == 0:
			summ += 1
		elif summ != 0:
			res += summ
			summ = 0
	print()
	print(res)
	print()


import sys
n = int(input())
for i in range(n):
	counter = 0
	length = int(input())
	array = list(map(int, input().split()))
	for j in range(length):
		if array[j] == 1:
			firstindex = j
			break
	for j in range(length - 1, -1, -1):
		if array[j] == 1:
			lastindex = j
			break
	for j in range(firstindex, lastindex + 1, 1):
		if array[j] == 0:
			counter += 1
	print(counter)


for c in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	v = b.count(1)
	new = []
	if v == 1 or v == 0:
		print(0)
	else:
		i = 0
		for nn in b:
			i += 1
			if nn == 1:
				break
		j = 0
		q = -1
		for tt in range(len(b)):
			ne = b[q]
			new.append(ne)
			q -= 1
		for nn in new:
			j += 1
			if nn == 1:
				break
		last = a - (j - 1)
		ans = 0
		for y in range(i, last):
			if b[y] == 0:
				ans += 1
		print(ans)


for i in range(int(input())):
	n = int(input())
	l = input().split()
	l = [int(e) for e in l]
	(init, fi, t) = (0, 0, 0)
	for j in range(len(l)):
		if l[j] == 1:
			if t == 0:
				init = j
				t = 1
			else:
				fi = j
	if fi == 0:
		print(0)
	else:
		nl = l[init:fi + 1]
		c = nl.count(0)
		print(c)


t = int(input())
g = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x = 0
	x1 = 0
	ans = 0
	for j in range(n):
		if a[j] == 1:
			a = a[j:]
			break
	a.reverse()
	for j in range(len(a)):
		if a[j] == 1:
			a = a[j:]
			break
	for j in range(len(a)):
		if a[j] == 0:
			ans += 1
	g.append(ans)
for i in range(len(g)):
	print(g[i])


for _ in range(int(input())):
	n = int(input())
	l = list([int(x) for x in input().split()])
	s = sum(l)
	if s == 1:
		print('0')
	elif s == n:
		print('0')
	else:
		lb = 0
		ub = n - 1
		while l[lb] == 0:
			lb += 1
		while l[ub] == 0:
			ub -= 1
		c = 0
		for i in range(lb, ub + 1):
			if l[i] == 0:
				c += 1
		print(c)


t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	sidx = l.index(1)
	eidx = 0
	for i in range(1, n):
		if l[n - i] == 1:
			eidx = n - i
			break
	c = 0
	for j in range(sidx, eidx):
		if l[j] == 0:
			c += 1
	print(c)


n = int(input())
numberOfblock = []
blocks = []
for i in range(n):
	numberOfblock.append(int(input()))
	temp = input().split(' ')
	blocks.append(temp)
for blc in range(len(blocks)):
	iter = numberOfblock[blc]
	one = 0
	hldone = 0
	counter = 0
	start = False
	for i in range(iter):
		if int(blocks[blc][i]) == 1:
			one += 1
	for x in range(iter):
		if int(blocks[blc][x]) == 1:
			start = True
		if start:
			if int(blocks[blc][x]) == 0:
				counter += 1
			else:
				hldone += 1
			if one == hldone:
				print(counter)
				break


for k in range(int(input())):
	n = int(input())
	vec = list(map(int, input().split()))
	while vec[0] == 0:
		vec = vec[1:]
	while vec[-1] == 0:
		vec = vec[:-1]
	print(vec.count(0))


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def solve():
	for _ in range(ii()):
		n = ii()
		a = li()
		x = []
		(c, f) = (0, 0)
		for i in range(n):
			if a[i]:
				if c > 0 and f:
					x.append(c)
				c = 0
				f = 1
			else:
				c += 1
		print(sum(x))
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	k = 0
	s = 0
	f = 0
	for i in range(n):
		if a[i] == 1:
			s = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			f = i
			break
	print(a[s:f].count(0))


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		num = int(input())
		books = list(map(int, input().split()))
		count = 0
		index = -1
		for (i, ele) in enumerate(books):
			if index > -1 and ele:
				count += i - index - 1
			if ele:
				index = i
		yield count
t = int(input())
ans = gift()
print(*ans, sep='\n')


t = int(input())
for tn in range(1, t + 1):
	n = int(input())
	a = list(map(int, input().split()))
	cnt0 = a.count(0)
	ss = 0
	ccl = 0
	ccr = 0
	for i in range(n):
		if a[i] == 0:
			ccl = ccl + 1
		if a[i] == 1:
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 0:
			ccr = ccr + 1
		if a[i] == 1:
			break
	print(cnt0 - ccl - ccr)


import sys
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def getMaxLength(arr, n):
	count = 0
	result = 0
	for i in range(0, n):
		if arr[i] == 0:
			count = 0
		else:
			count += 1
			result = max(result, count)
	return result
for t in range(int(input())):
	n = int(input())
	arr = get_list()
	while arr[0] == 0:
		arr.pop(0)
	while arr[-1] == 0:
		arr.pop(-1)
	count = arr.count(1)
	if getMaxLength(arr, len(arr)) == count:
		print(0)
		continue
	else:
		ans = arr.count(0)
		print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	i = 0
	ans = 0
	while i < n:
		if arr[i] == 1:
			j = i + 1
			while j < n and arr[j] == 0:
				j += 1
			if j < n:
				ans += j - i - 1
		i += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	n = len(a)
	z = 0
	o = 0
	for i in range(n):
		if a[i] == 0:
			if o > 0:
				z = z + 1
		else:
			o = o + 1
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			break
		else:
			z = z - 1
	print(z)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = []
	for j in range(n):
		if a[j] == 1:
			l.append(j)
	l1 = l[0]
	l2 = l[-1]
	count = len(l)
	print(l2 - l1 - count + 1)


def solve():
	n = int(input())
	lst = list(map(int, input().split()))
	ans = 0
	strt = -1
	for i in range(n):
		if strt == -1 and lst[i] == 1:
			strt = i
		elif lst[i] == 1:
			ans += i - strt - 1
			strt = i
	print(ans)
	return
t = int(input())
while t != 0:
	solve()
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	last = a[0]
	groups = a[0]
	gaps = []
	curr_gap = 0
	for i in range(1, len(a)):
		if a[i] != last:
			if a[i] == 1:
				if groups > 0:
					gaps.append(curr_gap)
				curr_gap = 0
				groups += 1
			else:
				curr_gap = 1
			last = a[i]
		elif a[i] == 0:
			curr_gap += 1
	print(sum(gaps))


t = int(input())
for _t in range(t):
	n = int(input())
	a = input().split()
	was_1 = False
	c = 0
	for one in a:
		if one == '1':
			was_1 = True
		elif was_1:
			c += 1
	if was_1:
		for one in a[::-1]:
			if one == '1':
				break
			else:
				c -= 1
	print(c)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = a.index(1)
	y = n - a[::-1].index(1) - 1
	s = 0
	if x == y:
		s = 0
	else:
		for i in range(x, y):
			if a[i] == 0:
				s += 1
	print(s)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	stack = []
	total = 0
	sum = 0
	for i in l:
		if i == 1:
			stack.append(i)
			total += sum
			sum = 0
		elif stack:
			sum += 1
	print(total)


n = int(input())
for i in range(n):
	t = int(input())
	ls = list(map(int, input().split()))
	zerocnt = ls.count(1)
	ps = [0] * (t + 1)
	cnt = 0
	zr = 0
	for j in range(t):
		if zerocnt == zr:
			break
		if ls[j] == 1:
			zr += 1
		ps[j + 1] = ps[j] + ls[j]
		if ps[j + 1] == ps[j] and ps[j + 1] != 0:
			cnt += 1
	print(cnt)


t = int(input())
for j in range(0, t):
	x = int(input())
	li = list(map(int, input().split()))
	count = 0
	l = 0
	r = len(li) - 1
	while l < len(li) - 1:
		if li[l] == 1:
			break
		l += 1
	while r > 1:
		if li[r] == 1:
			break
		r -= 1
	counter = 0
	for j in range(l, r):
		if li[j] == 0:
			counter += 1
	print(counter)


try:
	t = int(input())
	for _ in range(t):
		n = int(input())
		l = list(map(int, input().split(' ')))
		i = 0
		while i < n and l[i] != 1:
			i += 1
		j = n - 1
		while j > 0 and l[j] != 1:
			j -= 1
		if i == n or j == 0 or i == j:
			print(0)
		else:
			count = 0
			for k in range(i + 1, j):
				if l[k] == 0:
					count += 1
			print(count)
except:
	pass


import itertools

def solve():
	n = int(input().strip())
	books = [int(x) for x in input().strip().split()]
	l = [(k, len(list(g))) for (k, g) in itertools.groupby(books)]
	if l[0][0] == 0:
		l = l[1:]
	if l[-1][0] == 0:
		l = l[:-1]
	return sum([x[1] for x in l if x[0] == 0])
for _ in range(int(input().strip())):
	print(solve())


test_cases = int(input())
for _ in range(test_cases):
	books = int(input())
	bookshelf = [int(x) for x in input().split()]
	counter = 0
	zeroes = 0
	flag = False
	i = 0
	while i < len(bookshelf):
		try:
			if bookshelf[i] == 1:
				i += 1
				while bookshelf[i] == 0:
					zeroes += 1
					i += 1
					if bookshelf[i] == 1:
						counter += zeroes
			else:
				i += 1
			zeroes = 0
		except IndexError:
			pass
	print(counter)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	s = sum(arr)
	if s == 1:
		print(0)
	else:
		first = 0
		while arr[first] == 0:
			first += 1
		last = n - 1
		while arr[last] == 0:
			last -= 1
		print(last - first + 1 - s)


for t in range(int(input())):
	n = int(input())
	(*a,) = map(int, input().split())
	(l, r) = (0, n - 1)
	while l < n and a[l] == 0:
		l += 1
	while r >= 0 and a[r] == 0:
		r -= 1
	l = min(l, n - 1)
	r = max(0, r)
	ans = 0
	for i in range(l, r + 1):
		if a[i] == 0:
			ans += 1
	print(ans)


n = int(input())
l = []
for i in range(n):
	x = int(input())
	a = list(map(int, input().split()))
	l.append(a)
for i in range(n):
	c1 = 0
	while l[i][c1] != 1:
		c1 = c1 + 1
	c2 = len(l[i]) - 1
	while l[i][c2] != 1:
		c2 = c2 - 1
	cout = 0
	for j in range(c1 + 1, c2):
		if l[i][j] == 0:
			cout += 1
	print(cout)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count = False
	zeros = 0
	moves = []
	for e in a:
		if e == 1:
			count = True
			moves.append(zeros)
			zeros = 0
		elif count:
			zeros += 1
	print(sum(moves))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	low = -1
	for x in range(n):
		if arr[x] == 1:
			low = x
			break
	high = n + 1
	for y in range(n - 1, -1, -1):
		if arr[y] == 1:
			high = y
			break
	count = 0
	if low == -1 or high == n + 1:
		print('0')
	elif low == high:
		print('0')
	else:
		for z in range(low, high + 1):
			if arr[z] == 0:
				count += 1
		print(count)


from collections import *
from itertools import *
from bisect import *

def inp():
	return int(input())

def arrinp():
	return [int(x) for x in input().split()]

def main():
	t = inp()
	for _ in range(t):
		n = inp()
		A = arrinp()
		ans = 0
		counter = 0
		flag = False
		for a in A:
			if a == 0 and flag == True:
				counter += 1
			elif a == 1:
				if flag == False:
					flag = True
				else:
					ans += counter
					counter = 0
		print(ans)
main()


def Solve():
	n = ri()
	a = rl()
	(f1, s1) = (-1, 0)
	for i in range(n):
		if f1 == -1 and a[i] == 1:
			f1 = i
		if a[i] == 1:
			s1 = i
	ans = 0
	for i in range(f1, s1 + 1):
		if a[i] == 0:
			ans += 1
	print(ans)
import sys
inp = sys.stdin.buffer.readline
rl = lambda : list(map(int, inp().split()))
ri = lambda : int(inp())
rs = lambda : inp().decode().strip()
Testcase = 1
Testcase = ri()
for Test in range(Testcase):
	Solve()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	flag = 0
	count = 0
	temp = 0
	for i in range(n):
		if a[i] == 1:
			flag = 1
			temp = 0
		if flag == 1 and a[i] == 0:
			if i == n - 1:
				count -= temp
			else:
				temp += 1
				count += 1
	print(count)


def read_int() -> int:
	return int(input())

def read_ints():
	return list(map(int, input().split(' ')))

def pop_zeros(array):
	while array[0] == 0:
		array.pop(0)
	while array[-1] == 0:
		array.pop()

def test_case():
	length = read_int()
	shelf = read_ints()
	books = sum(shelf)
	if books == 1:
		print(0)
	else:
		pop_zeros(shelf)
		print(len(shelf) - books)
tests = read_int()
for _ in range(tests):
	test_case()


def bookshelf(arr, n):
	count = 0
	left = 0
	right = n - 1
	while right >= 0:
		if arr[right] == 1:
			break
		right -= 1
	while left < n:
		if arr[left] == 1:
			break
		left += 1
	for i in range(left, right):
		if arr[i] == 0:
			count += 1
	return count
testCase = int(input())
while testCase != 0:
	testCase -= 1
	n = int(input())
	arr = [int(x) for x in input().split(' ')]
	print(bookshelf(arr, n))


for i in range(int(input())):
	n = int(input())
	nn = [int(s) for s in input().split()]
	l = nn.index(1)
	r = n - nn[::-1].index(1) - 1
	print(nn[l:r].count(0))


for _ in range(int(input())):
	f = input()
	li = list(map(int, input().split()))
	flag = False
	start = 0
	end = 0
	count = 0
	for i in range(len(li)):
		if li[i] == 1 and flag == True:
			end = i
			count += end - start - 1
			start = i
		elif li[i] == 1 and flag == False:
			flag = True
			start = i
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	line = input().strip().split()
	end = -1
	for i in range(n - 1, -1, -1):
		if line[i] == '1':
			end = i
			break
	begin = -1
	for i in range(end + 1):
		if line[i] == '1':
			begin = i
			break
	res = 0
	for i in range(begin + 1, end):
		if line[i] == '0':
			res += 1
	print(res)


test_cases = int(input())
while test_cases != 0:
	test_cases = test_cases - 1
	n = int(input())
	inp = ''.join(input().split())
	start = inp.find('1')
	end = inp.rfind('1')
	print(inp.count('0', start, end))


rn = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rns = lambda : map(int, input().split())
rs = lambda : input()
yn = lambda x: print('Yes') if x else print('No')
YN = lambda x: print('YES') if x else print('NO')
for _ in range(rn()):
	n = rn()
	l = rl()
	ans = 0
	start = False
	acc = 0
	for i in l:
		if i == 1:
			start = True
			ans += acc
			acc = 0
		elif start:
			acc += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a = a[a.index(1):]
	a = a[::-1]
	a = a[a.index(1):]
	r = len(a) - sum(a)
	print(r)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	zeroes = fz = fl = enz = 0
	for i in range(n):
		if not fl and (not a[i]):
			fz += 1
		if not a[i]:
			zeroes += 1
			enz += 1
		else:
			enz = 0
			fl = 1
	print(zeroes - fz - enz)

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()
main()


resultados = list()
cases = int(input())
for n in range(cases):
	cuenta = False
	zeros = unos = anadir = 0
	size = int(input())
	lista = input()
	lista = lista.split(' ')
	for n in range(size):
		if lista[n] == '1':
			zeros += anadir
			anadir = 0
			cuenta = True
			unos += 1
		elif lista[n] == '0' and cuenta == True:
			anadir += 1
	if unos == 1:
		resultados.append(0)
	else:
		resultados.append(zeros)
for n in range(len(resultados)):
	print(resultados[n])


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a = list(map(str, a))
	s = ''.join(a)
	c1 = s.find('1')
	c2 = s.rfind('1')
	ans = s[c1:c2].count('0')
	print(ans)


for u in range(int(input())):
	n = int(input())
	x = [int(w) for w in input().split()]
	ans = 0
	i = 0
	while i < n and x[i] == 0:
		i += 1
	j = n - 1
	while j >= 0 and x[j] == 0:
		j -= 1
	while i <= j:
		if x[i] == 0:
			ans += 1
		i += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	for i in range(n):
		if lst[i] == 1:
			index1 = i
			break
	for i in range(n - 1, -1, -1):
		if lst[i] == 1:
			index2 = i
			break
	if index1 == index2:
		print(0)
	else:
		print(lst[index1:index2].count(0))


def answer(l):
	idx = 0
	lft = 0
	rgt = 0
	gap = 0
	N = len(l)
	res = 0
	fp = True
	while idx < N:
		if l[idx] == '0' and (not fp):
			gap += 1
		if l[idx] == '1':
			fp = False
		if l[idx] == '1' and gap > 0:
			res += gap
			gap = 0
		idx += 1
	return res
t = int(input())
for _ in range(t):
	input()
	x = input()
	print(answer(x[::-1].split(' ')))


times = int(input())
for i in range(times):
	n = int(input())
	a = input().split(' ')
	count1 = 0
	for j in range(n):
		a[j] = int(a[j])
		if a[j] == 1:
			count1 += 1
	if count1 == 1:
		print(0)
	else:
		b = []
		c = []
		count2 = 0
		for j in range(n):
			if a[j] == 1:
				for k in range(j, n):
					b.append(a[k])
				break
			else:
				continue
		b.reverse()
		for j in range(len(b)):
			if b[j] == 1:
				for k in range(j, len(b)):
					c.append(b[k])
				break
			else:
				continue
		c.reverse()
		for j in range(len(c)):
			if c[j] == 0:
				count2 += 1
		print(count2)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	for j in range(n):
		if l[j] == 1:
			le = j
			break
	k = n - 1
	while k >= 0:
		if l[k] == 1:
			ri = k
			break
		k = k - 1
	if le == ri:
		print(0)
	else:
		count = 0
		for i in range(le, ri):
			if l[i] == 0:
				count = count + 1
		print(count)


def moves(shelf):
	one_pos = 0
	for i in range(len(shelf)):
		if shelf[i] == 1:
			one_pos = i
			break
	between_zeros = 0
	z_cont = 0
	for i in shelf[one_pos:]:
		if i == 1:
			between_zeros += z_cont
			z_cont = 0
		else:
			z_cont += 1
	return between_zeros
t = int(input())
for i in range(t):
	n = int(input())
	shelf = list(map(int, input().split()))
	print(moves(shelf))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(pre, pos) = (-1, -1)
	for i in range(n):
		if l[i] == 1:
			pre = i
			break
	for i in range(n - 1, -1, -1):
		if l[i] == 1:
			pos = i
			break
	if pre == pos:
		print(0)
	else:
		print(l[pre:pos + 1].count(0))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = 0
	while l < n and a[l] == 0:
		l += 1
	r = n - 1
	while r >= 0 and a[r] == 0:
		r -= 1
	cnt = 0
	res = 0
	for i in range(l, r + 1):
		if a[i] == 0:
			cnt += 1
		else:
			if cnt:
				res += cnt
			cnt = 0
	if cnt:
		res += cnt
	print(res)


test = int(input())
for _ in range(test):
	n = int(input())
	arr = list(map(int, input().split()))
	(l, r) = (2 ** 31 - 1, 2 ** 31 - 1)
	gap = 0
	cur = 0
	for i in range(n):
		if arr[i] == 1:
			if l == 2 ** 31 - 1:
				l = i
				r = i
			else:
				r = i
				gap += cur
				cur = 0
		elif l != 2 ** 31 - 1:
			cur += 1
	print(gap)


t = int(input())
for i in range(t):
	n = int(input())
	books = list(input().split())
	locate = list()
	moves = 0
	for j in range(0, n):
		if books[j] == '1':
			locate.append(j + 1)
	for k in range(0, len(locate) - 1):
		moves += locate[k + 1] - locate[k] - 1
	print(moves)


t = int(input())
index1 = 0
index2 = 0
for i in range(t):
	counter = 0
	n = int(input())
	arr = input().split()
	for num in arr:
		if num == '1':
			index1 = arr.index(num)
			break
	for num in arr[::-1]:
		if num == '0':
			arr.pop()
		else:
			break
	for num in arr[index1:]:
		if num == '0':
			counter += 1
	print(counter)


from sys import stdin, stdout

def INPUT():
	return list((int(i) for i in stdin.readline().split()))
import math

def inp():
	return stdin.readline()

def out(x):
	return stdout.write(x)
import math as M
MOD = 10 ** 9 + 7
from random import randint as R
for _ in range(int(input())):
	n = int(input())
	A = INPUT()
	for i in range(n):
		if A[i] == 1:
			ind = i
			break
	for i in range(n - 1, -1, -1):
		if A[i] == 1:
			ind2 = i
			break
	ans = 0
	for i in range(ind, ind2 + 1):
		if A[i] == 0:
			ans += 1
	print(ans)


ns = lambda : input()
ni = lambda : int(input())
nm = lambda : map(int, input().split())
nl = lambda : list(map(int, input().split()))
for _ in range(ni()):
	n = ni()
	a = nl()
	f = l = z = 0
	i = -1
	while f == 0:
		i += 1
		f = a[i]
	f = i
	i = n
	while l == 0:
		i -= 1
		l = a[i]
	l = i
	i = f
	while i <= l:
		if a[i] == 0:
			z += 1
		i += 1
	print(z)


for _ in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	i = 0
	f = False
	ans = 0
	while i < a:
		if b[i] == 0 and f:
			j = i
			ss = 0
			while j < a and b[j] == 0:
				ss += 1
				j += 1
			if j < a and b[j] == 1:
				ans += ss
			i = j
		elif b[i] == 1:
			i += 1
			f = True
		else:
			i += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = 0
	c = 0
	k = l.count(0)
	for k in range(n - 1, -1, -1):
		if l[k] == 1:
			end = k
			break
	for m in range(0, n):
		if l[m] == 1:
			start = m
			break
	count = 0
	for i in range(start, end + 1):
		if l[i] == 0:
			count += 1
	if k == n:
		print(0)
	else:
		print(count)


def main(n, s):
	c = 0
	d = 0
	idx = s.index(1)
	for i in range(n):
		if s[i] == 1:
			c += 1
			if i < n - 1:
				if max(s[i + 1:]) == 0:
					n = i + 1
					break
				if s[i + 1] == 1:
					d += 1
	if c == d + 1:
		return 0
	if c == 1:
		return 0
	res = n - idx - c
	return res
k = int(input())
for _ in range(k):
	n = int(input())
	s = list(map(int, input().strip().split()))
	print(main(n, s))


t = int(input())
for i in range(t):
	n = int(input())
	books = list(map(int, input().split()))
	nb1 = sum(books)
	ad = 0
	first1 = n
	last1 = 0
	for j in range(n):
		if books[j] == 1:
			first1 = min(first1, j)
			last1 = max(last1, j)
	print(last1 - first1 + 1 - nb1)


def solve():
	t = int(input())
	a = list(map(int, input().split()))
	x = a.index(1)
	res = 0
	for i in range(x + 1, len(a)):
		if a[i] == 1:
			res += i - x - 1
			x = i
	return res
for i in range(int(input())):
	print(solve())


from functools import reduce
import os
import sys
from collections import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
inf = 1e+18
div = 998244353
for _ in range(inn()):
	n = inn()
	a = arr()
	i = 0
	while i < n and a[i] == 0:
		i += 1
	j = n - 1
	while j >= 0 and a[j] == 0:
		j -= 1
	ans = 0
	while i < j:
		if a[i] == 0:
			ans += 1
		i += 1
	print(ans)


for efkjr in range(int(input())):
	a = int(input())
	our = list(map(int, input().split()))
	res = 0
	i = 0
	j = a - 1
	while our[i] == 0:
		i += 1
	while our[j] == 0:
		j -= 1
	print(j - i + 1 - sum(our[i:j + 1]))


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	num = list(input().split())
	s = ''
	for j in num:
		s += j
	a = b = 0
	for j in range(len(s)):
		if s[j] == '1':
			a = j
			break
	for j in range(len(s) - 1, -1, -1):
		if s[j] == '1':
			b = j
			break
	c = 0
	for j in range(a, b + 1):
		if s[j] == '0':
			c += 1
	print(c)


t = int(input())
while t > 0:
	x = int(input())
	y = input()
	y = y.split(' ')
	z = []
	for i in range(0, x):
		if y[i] == '1':
			z.append(i)
			y[i] = '2'
	print(y[z[0]:z[len(z) - 1]].count('0'))
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	zeroct = 0
	isone = False
	ans = 0
	for i in range(n):
		if arr[i] == 1 and isone:
			ans += zeroct
			zeroct = 0
		elif arr[i] == 1:
			isone = True
			zeroct = 0
		else:
			zeroct += 1
	print(ans)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 6 + 6
for _ in range(I()):
	n = I()
	a = L()
	p = -1
	ans = 0
	for i in range(n):
		if p == -1 and a[i]:
			p = i
		elif a[i]:
			ans += i - p - 1
			p = i
	print(ans)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] == 1:
			break
		a[i] = 1
	for i in reversed(range(n)):
		if a[i] == 1:
			break
		a[i] = 1
	return a.count(0)
t = int(input())
i = 0
while i < t:
	print(solve())
	i += 1


MOD = 1000000007
from collections import defaultdict as dd, Counter, deque

def si():
	return input()

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def mi():
	return map(int, input().split())

def out(v):
	print(v)

def spout():
	print(v, end=' ')

def d2b(n):
	return bin(n).replace('0b', '')

def twod(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def vow():
	return ['a', 'e', 'i', 'o', 'u']

def let():
	return [chr(i) for i in range(97, 123)]

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ispow2(x):
	return x and (not x & x - 1)

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)
t = ii()
while t:
	t -= 1
	n = ii()
	a = li()
	i = c = 0
	start = 0
	end = n - 1
	while i < n:
		if a[i] == 1:
			start = i
			break
		i += 1
	i = n - 1
	while i >= 0:
		if a[i] == 1:
			end = i
			break
		i -= 1
	for i in range(start, end + 1):
		if a[i] == 0:
			c += 1
	print(c)


def check(a, n):
	answer = 0
	firstIndex = -1
	lastIndex = -1
	for i in range(n):
		if a[i] == 1:
			firstIndex = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			lastIndex = i
			break
	for i in range(firstIndex, lastIndex + 1):
		if a[i] == 0:
			answer += 1
	return answer
t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(check(a, n))


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()
for _ in range(II()):
	n = II()
	s = SI()
	l = s.find('1')
	r = s.rfind('1')
	ans = s[l:r].count('0')
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	bl = 0
	re = 0
	sums = sum(l)
	if sum(l) == 1:
		print(0)
	else:
		for i in l:
			if sums == 0:
				break
			if i == 1 and bl == 0:
				bl = 1
			if bl and i == 0:
				re += 1
			if i == 1:
				sums -= 1
		print(re)


t = 1
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	cont = 0
	gaps = []
	for el in a:
		if el == 0:
			cont += 1
		else:
			gaps.append(cont)
			cont = 0
	gaps.pop(0)
	print(sum(gaps))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	b = []
	while i < len(a):
		if a[i] == 1:
			j = i
			while j < len(a) and a[j] == 1:
				j += 1
			b.append([i, j])
			i = j
		i += 1
	s = 0
	for i in range(len(b) - 1):
		s += b[i + 1][0] - b[i][1]
	print(s)


t = int(input())
bookshelves = []
shelf = []
for i in range(t):
	n = int(input())
	books = input()
	for j in books:
		if j != ' ':
			shelf.append(int(j))
	bookshelves.append(shelf)
	shelf = []
for i in bookshelves:
	while True:
		ones = i.count(1)
		if ones <= 1:
			print(0)
			break
		elif i[0] == 0:
			i.remove(0)
		elif i[-1] == 0:
			i.pop(-1)
		else:
			zeros = i.count(0)
			print(zeros)
			break


t = int(input())
for i in range(t):
	p = int(input())
	x = input().split(' ')
	flag = -1
	c = 0
	if x.count('1') > 1:
		for j in range(x.index('1'), ''.join(x).rindex('1')):
			if x[j] == '0':
				c += 1
	print(c)


def mi():
	return map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	a = list(mi())
	(first, last) = (-1, -1)
	for i in range(n):
		if a[i] == 1:
			last = i
			if first == -1:
				first = i
	ans = 0
	for i in range(first, last + 1):
		if a[i] == 0:
			ans += 1
	print(ans)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	if a.count(1) == 1:
		print(0)
		return
	i = 0
	while a[i] == 0:
		i += 1
	j = n - 1
	while a[j] == 0:
		j -= 1
	print(a[i:j + 1].count(0))
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = []
	d = 0
	for i in range(n):
		if l == [] and a[i] == 1:
			l.append(i)
		elif a[i] == 1:
			d += i - l[-1] - 1
			l.append(i)
	print(d)


t = int(input())
for _ in range(t):
	n = int(input())
	line = list(map(int, input().split()))
	line = line[line.index(1):n - line[::-1].index(1)]
	total = 0
	for i in line:
		if i == 0:
			total += 1
	print(total)


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split(' ')))
	flag = False
	n = len(arr)
	i = 0
	final_ans = 0
	while i < n:
		if arr[i] == 1:
			ans = 0
			i += 1
			while i < n and arr[i] != 1:
				ans += 1
				i += 1
			if i >= n:
				break
			final_ans += ans
		else:
			i += 1
	print(final_ans)


def solve():
	n = int(input())
	shelf = list(map(int, input().split()))
	lIndex = 0
	rIndex = n
	for i in range(n):
		if shelf[i] == 1:
			lIndex = i
			break
	for i in range(n - 1, -1, -1):
		if shelf[i] == 1:
			rIndex = i
			break
	cntZero = 0
	for i in range(lIndex, rIndex + 1):
		if shelf[i] == 0:
			cntZero += 1
	print(cntZero)
tests = int(input())
while tests > 0:
	solve()
	tests -= 1


import time, math as mt, bisect, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return

def readTree(v):
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return adj
mod = 10 ** 9 + 7

def solve():
	n = II()
	a = L()
	if a.count(1) == 1:
		print(0)
		return
	else:
		(left, right) = (n + 5, -5)
		for i in range(n):
			if a[i] == 1:
				left = min(left, i)
				right = max(right, i)
		cnt = 0
		for i in range(left, right + 1):
			if a[i] == 0:
				cnt += 1
		print(cnt)
	return
t = II()
for i in range(t):
	solve()


def ans(books):
	i = None
	j = None
	for k in range(len(books)):
		if books[k] == 0:
			continue
		j = k
		if i is None:
			i = k
	return sum((1 - x for x in books[i:j + 1]))
for _ in range(int(input())):
	input()
	books = list(map(int, input().split()))
	print(ans(books))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	c = 0
	for items in a:
		if items == 1:
			if c1 > 0 and c2 > 0:
				c += c2
			c2 = 0
			c1 = 1
		if items == 0:
			c2 += 1
	print(c)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	st = 0
	while a[st] != 1:
		st += 1
	(ans, c) = (0, 0)
	for i in range(st, n):
		if a[i] == 0:
			c += 1
		else:
			ans += c
			c = 0
	print(ans)
for _ in range(int(input())):
	solve()


from collections import Counter

def cal(a, c):
	for ai in a:
		if ai == '0':
			c['0'] -= 1
		else:
			break
for t in range(int(input())):
	n = input()
	a = input().split()
	c = Counter(a)
	cal(a, c)
	a.reverse()
	cal(a, c)
	print(c['0'])


for tc in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	flag = False
	cnt = 0
	zeros = 0
	if arr.count(1) == 1:
		print(0)
	else:
		for x in arr:
			if flag and x == 1:
				cnt += zeros
				zeros = 0
			if x == 1:
				flag = True
			elif x == 0 and flag:
				zeros += 1
		print(cnt)


def bookshelf(arr):
	ans = []
	countz = 0
	currentZ = None
	currentone = None
	for i in range(len(arr)):
		if arr[i] == 0:
			currentZ = i
			countz += 1
		if arr[i] == 1:
			if currentone != None and currentZ != None and (currentone < currentZ):
				ans.append(countz)
				countz = 0
				currentone = i
			else:
				currentone = i
				countz = 0
	return sum(ans)
t = int(input())
for i in range(t):
	a = input()
	lst = list(map(int, input().strip().split()))
	print(bookshelf(lst))


import re

def readGenerator():
	while True:
		tokens = input().split(' ')
		for t in tokens:
			yield t
reader = readGenerator()

def readWord():
	return next(reader)

def readInt():
	return int(next(reader))

def readFloat():
	return float(next(reader))

def readLine():
	return input()

def solve(a, n):
	f = a.index(max(a))
	l = n - a[::-1].index(max(a)) - 1
	res = 0
	for i in range(f, l + 1):
		if a[i] == 0:
			res += 1
	return res
t = readInt()
for _ in range(t):
	n = readInt()
	a = [readInt() for _ in range(n)]
	print(solve(a, n))


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	i = 0
	while ar[i] == 0:
		del ar[0]
		if len(ar) == 0:
			break
	ar.reverse()
	while ar[i] == 0:
		del ar[0]
		if len(ar) == 0:
			break
	if len(ar) < 2:
		print(0)
	else:
		print(len(ar) - sum(ar))


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	count = 0
	arr = []
	for i in range(0, n):
		if l[i] == 0:
			count += 1
		elif count > 0:
			arr.append(count)
			count = 0
	if count > 0:
		arr.append(count)
	if l[0] == 1 and l[n - 1] == 1:
		print(sum(arr))
	elif l[0] == 0 and l[n - 1] == 1:
		print(sum((arr[i] for i in range(1, len(arr)))))
	elif l[0] == 1 and l[n - 1] == 0:
		print(sum((arr[i] for i in range(0, len(arr) - 1))))
	else:
		print(sum((arr[i] for i in range(1, len(arr) - 1))))


import sys
num = int(sys.stdin.readline())
for i in range(num):
	t = int(sys.stdin.readline())
	lst = list(map(int, sys.stdin.readline().strip().split(' ')))
	while len(lst) > 0 and lst[0] == 0:
		lst.pop(0)
	while len(lst) > 0 and lst[-1] == 0:
		lst.pop(len(lst) - 1)
	print(len(lst) - sum(lst))


def left(arr):
	count = 0
	for i in range(len(arr)):
		if arr[i] == 1:
			return (count, i)
		else:
			count += 1

def right(arr):
	count = 0
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] == 1:
			return (count, i)
		else:
			count += 1

def mid(left, right, arr):
	idx = left
	count = 0
	while idx < right:
		if arr[idx] == 0:
			count += 1
		idx += 1
	return count
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(left_count, left_one) = left(arr)
	(right_count, right_one) = right(arr)
	mid_count = mid(left_one, right_one, arr)
	if mid_count > 0:
		print(mid_count)
	else:
		print(0)


t = int(input())
for test in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	temp = arr.count(1)
	if temp == 1:
		print(0)
	else:
		cnt = 0
		(pre, post) = (0, 0)
		for i in range(n):
			if arr[i] == 1:
				post = 1
				pre = arr[i + 1:].count(1)
				if pre == 0:
					break
			elif post >= 1:
				cnt += 1
		print(cnt)


t = int(input())
for _ in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	print
	k = 0
	ans = 0
	start = False
	for i in lis:
		if i == 1 and start == False:
			start = True
		elif i == 1 and start == True:
			ans += k
			k = 0
		elif i == 0 and start == True:
			k += 1
		else:
			continue
	print(ans)


for _ in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	c = b.index(1)
	s = b.copy()
	b.reverse()
	p = b.index(1)
	v = s[c:-p - 1].count(0)
	print(v)


def R():
	return map(int, input().split())

def L():
	return list(map(int, input().split()))

def I():
	return int(input())
for _ in range(I()):
	n = I()
	a = L()
	for i in range(n):
		if a[i] == 1:
			break
	for k in range(n - 1, -1, -1):
		if a[k] == 1:
			break
	cnt = 0
	for j in range(i + 1, k):
		if a[j] == 0:
			cnt += 1
	print(cnt)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	for i in range(n):
		if ar[i] == 1:
			break
	ans = 0
	count = 0
	for j in range(i + 1, n):
		if ar[j] == 0:
			count += 1
		else:
			ans += count
			count = 0
	print(ans)


def solve(query):
	arr = [int(i) for i in query.split(' ')]
	left_zero_count = right_zero_count = 0
	for (i, e) in enumerate(arr):
		if e == 1:
			left_zero_count = i
			break
		left_zero_count += 1
	for (i, e) in enumerate(arr[::-1]):
		if e == 1:
			right_zero_count = i
			break
		right_zero_count += 1
	ans = 0
	for i in range(left_zero_count, len(arr) - right_zero_count):
		if arr[i] == 0:
			ans += 1
	return ans
t = int(input())
for _ in range(t):
	input()
	query = input().strip()
	print(solve(query))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(s) for s in input().split(' ')]
	first_one = last_one = -1
	zeroes = 0
	for i in range(n):
		if a[i] == 1:
			first_one = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			last_one = i
			break
	for i in range(first_one + 1, last_one):
		if a[i] == 0:
			zeroes += 1
	print(zeroes)


for _ in range(int(input())):
	n = int(input())
	books = list(map(int, input().split()))
	moves = 0
	found = []
	for i in range(n):
		if books[i] == 1:
			found.append(i)
	if len(found) == 1:
		print(0)
		continue
	for i in range(len(found) - 1):
		moves += found[i + 1] - found[i] - 1
	print(moves)


T = int(input())
for _ in range(0, T):
	n = int(input())
	s = [int(x) for x in input().split()]
	ptr = len(s)
	flag = 0
	ans = 0
	for i in range(len(s) - 1, -1, -1):
		if s[i] == 1:
			ptr = i + 1
			break
	for i in range(0, ptr):
		if s[i] == 1:
			flag = 1
		if s[i] == 0 and flag == 1:
			ans += 1
	print(ans)


for i in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	count = 0
	for i in range(len(l)):
		if l[i] == 1:
			countv = 0
			flag = 0
			for j in range(i + 1, n):
				if l[j] == 0:
					countv += 1
				else:
					flag = 1
					break
			if flag == 1:
				count += countv
	print(count)


for _ in range(int(input())):
	n = int(input())
	ar = [int(i) for i in input().split()]
	(left, right) = (0, n - 1)
	while left < n - 1 and ar[left] != 1:
		left += 1
	while right > 0 and ar[right] != 1:
		right -= 1
	if left == right:
		print(0)
	else:
		ans = 0
		for i in range(left, right):
			if ar[i] == 0:
				ans += 1
		print(ans)


t = int(input())
for i in range(t):
	l = int(input())
	s = list(map(int, input().split()))
	first = 0
	last = l - 1
	while s[first] != 1:
		first += 1
	while s[last] != 1:
		last -= 1
	ans = 0
	for j in range(first, last):
		if s[j] == 0:
			ans += 1
	print(ans)


t = int(input())
while t > 0:
	t = t - 1
	books = []
	n = int(input())
	books = [int(i) for i in input().split()]
	from_last = 0
	one = 0
	zeroes = 0
	for i in books:
		if i == 1:
			one = 1
			from_last = 0
		elif one > 0:
			zeroes = zeroes + 1
			from_last = from_last + 1
	print(zeroes - from_last)


from math import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
import heapq
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
INF = float('inf')
dx = [-1, 0, 0, 1]
dy = [0, 1, -1, 0]
from sys import stdin
readline = stdin.readline

def readInts():
	return list(map(int, readline().split()))

def readTuples():
	return tuple(map(int, readline().split()))

def I():
	return int(readline())
ans = []
for i in range(1, 10):
	s = ''
	s += str(i)
	ans.append(s)
	for j in range(3):
		s += str(i)
		ans.append(s)
q = I()
for _ in range(q):
	n = I()
	flag = False
	s = ''.join(input().split(' '))
	ans = 0
	a = 0
	for i in range(n):
		if s[i] == '1':
			if flag:
				ans += a
				a = 0
			else:
				flag = True
		elif flag:
			a += 1
		else:
			pass
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	cc = False
	c = 0
	while l[n - 1] != 1:
		n -= 1
	while i < n:
		if l[i] == 1:
			while i < n and l[i] != 0:
				i += 1
			while i < n and l[i] != 1:
				c += 1
				i += 1
		else:
			i += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	flag = 0
	a = 0
	for i in l:
		if i == 1:
			flag = 1
		elif flag == 1:
			a = a + 1
		if i == 1:
			ans = a
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	rfirst = 0
	rshift = 0
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			rfirst = i
			break
	for i in range(rfirst, -1, -1):
		if a[i] == 1:
			j = i + 1
			while j < rfirst and a[j] == 0:
				rshift += 1
				j += 1
	lfirst = 0
	lshift = 0
	for i in range(n):
		if a[i] == 1:
			lfirst = i
			break
	for i in range(lfirst, n):
		if a[i] == 1:
			j = i - 1
			while j > lfirst and a[j] == 0:
				lshift += 1
				j -= 1
	print(min(rshift, lshift))


t = int(input())
for j in range(t):
	n = int(input())
	l = list(map(int, input().strip().split()))
	ans = 0
	fl = []
	for i in range(len(l)):
		if l[i] == 1:
			fl.append(i)
	for i in range(min(fl), max(fl)):
		if l[i] == 0:
			ans += 1
	print(ans)


import random

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = -1
	e = -1
	for i in range(n):
		if a[i]:
			s = i
			break
	for i in range(n - 1, -1, -1):
		if a[i]:
			e = i
			break
	ans = 0
	for i in range(s, e):
		if a[i] == 0:
			ans += 1
	print(ans)


for test in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	ones = 0
	wans = 0
	ans = 0
	for x in arr:
		if x == 1:
			ones += 1
	for x in arr:
		if x == 1:
			wans += 1
		if 1 <= wans < ones:
			if x == 0:
				ans += 1
	print(ans)


for k in range(int(input())):
	a = int(input())
	b = input()
	res = 0
	for l in range(b.index('1'), b.rindex('1') + 1):
		if b[l] == '0':
			res += 1
	print(res)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	ans = ''
	for i in l:
		ans += str(i)
	ans = ans.strip('0')
	print(ans.count('0'))


import heapq
t = int(input())
for t_i in range(t):
	input()
	bookshelf = list(map(int, input().split()))
	segments = []
	start = -1
	for i in range(len(bookshelf)):
		if bookshelf[i] == 1:
			if start == -1:
				start = i
		elif start != -1:
			segments.append((start, i))
			start = -1
	if start != -1:
		segments.append((start, i))
	unvisited = [(0, segments)]
	while unvisited:
		(moves, segments) = heapq.heappop(unvisited)
		if len(segments) == 1:
			min_moves = moves
			break
		max_segment_size = segments[0][1] - segments[0][0]
		max_segment_i = 0
		for i in range(1, len(segments)):
			segment_size = segments[i][1] - segments[i][0]
			if segment_size > max_segment_size:
				max_segment_size = segment_size
				max_segment_i = i
		if max_segment_i == len(segments) - 1:
			gap = segments[-1][0] - segments[-2][1]
			new_segment = (segments[-2][0], segments[-1][1])
			new_segments = segments[:-2] + [new_segment]
			heapq.heappush(unvisited, (moves + gap, new_segments))
		else:
			gap = segments[max_segment_i + 1][0] - segments[max_segment_i][1]
			new_segment = (segments[max_segment_i][0], segments[max_segment_i + 1][1])
			new_segments = segments[:max_segment_i] + [new_segment] + segments[max_segment_i + 2:]
			heapq.heappush(unvisited, (moves + gap, new_segments))
	print(min_moves)


from sys import stdin
for i in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().strip().split()))
	(x, cout) = (0, 0)
	y = []
	p = 0
	for i in range(n):
		if a[i] == 1:
			y.append(i)
	z = len(y)
	if z == 1:
		print(0)
	else:
		y.reverse()
		for i in range(z - 1):
			cout = cout + y[i] - y[i + 1] - 1
		print(cout)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if l.count(1) == 1:
		print(0)
	else:
		b = []
		for i in range(n - 1, -1, -1):
			if l[i] == 1:
				b.append(i)
		s = 0
		for j in range(len(b) - 1):
			s += b[j] - b[j + 1] - 1
		print(s)


for i in range(int(input())):
	n = int(input())
	a = input()
	a = a[a.index('1'):a.rindex('1') + 1]
	print(a.count('0'))


def solve(n, arr):
	left = -1
	right = 0
	for i in range(n):
		if arr[i] == 1:
			if left == -1:
				left = i
			right = i
	count0 = 0
	for i in range(left, right):
		if arr[i] == 0:
			count0 += 1
	return count0
T = int(input())
for t in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve(n, arr))


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(inp()):
	n = inp()
	a = inpl()
	st = la = 0
	for i in range(n):
		if a[i]:
			st = i
			break
	for i in range(n)[::-1]:
		if a[i]:
			la = i
			break
	ch = False
	res = 0
	for i in range(st, la + 1):
		x = a[i]
		if ch:
			if x:
				continue
			ch = False
			res += 1
		elif x:
			ch = True
		else:
			res += 1
	print(res)


def read_array():
	x = []
	x1 = []
	x = input()
	x = x.split(' ')
	for r in range(len(x)):
		x1.append(int(x[r]))
	return x1

def find_gap(vector):
	dif = 0
	count = 0
	for i in range(len(vector)):
		if vector[i] == 1 and count > 0:
			pos2 = i - pos1
			pos1 = i
			if pos2 > 1:
				dif += pos2 - 1
			count += 1
		elif vector[i] == 1:
			pos1 = i
			count += 1
	return dif
res = []
m = int(input())
for j in range(m):
	input()
	x = read_array()
	res.append(find_gap(x))
for v in res:
	print(v)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	i = 0
	while i < n - 1:
		if a[i] == 1:
			j = i + 1
			check = 0
			c = 0
			while a[j] == 0:
				j += 1
				c += 1
				if j == n:
					check = 1
					break
			i = j
			if check == 0:
				count += c
		else:
			i += 1
	print(count)


import sys
import math

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	a = get_array()
	ans1 = []
	ans2 = []
	for i in range(n):
		if a[i] == 1:
			ans1.append(i)
		else:
			ans2.append(i)
	ans3 = 0
	for i in range(len(ans1) - 1):
		ans3 += ans1[i + 1] - ans1[i] - 1
	print(ans3)


def check(arr):
	o = False
	m = False
	for el in arr:
		if el == 1 and (not o):
			o = True
		if el == 0 and o and (not m):
			m = True
		if el == 1 and o and m:
			return False
	return True
x = int(input())
for i in range(x):
	m = int(input())
	l = list(map(int, input().split()))
	b = sum(l)
	if not check(l):
		x1 = 0
		y = 0
		m = False
		for i in range(len(l)):
			if l[i] == 1:
				y += 1
				m = True
			if b == y:
				break
			if l[i] == 0 and m:
				x1 += 1
		print(x1)
	else:
		print(0)


t = int(input())
for i in range(t):
	n = int(input())
	riiul = [int(x) for x in input().split()]
	r = n - riiul.index(1)
	riiul.reverse()
	l = riiul.index(1)
	b = riiul[l:r]
	print(b.count(0))


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	findx = 0
	cnt = 0
	lindx = 0
	findx = l.index(1)
	lindx = len(l) - 1 - l[::-1].index(1)
	for i in l[findx:lindx + 1]:
		if not i:
			cnt += 1
	print(cnt)


from math import *
from collections import *
from bisect import *
t = int(input())

def solve():
	n = int(input())
	arr = [x for x in input().split()]
	s = ''.join(arr)
	i = s.find('1')
	j = s[::-1].find('1')
	ans = s[i:n - j].count('0')
	print(ans)
p = 1
while t:
	t -= 1
	ans = solve()
	p += 1


case = int(input())
for i in range(case):
	length = input()
	x = [v for v in input().split()]
	string = ''
	for j in range(len(x)):
		string += x[j]
	string = string.strip('0')
	print(string.count('0'))


t = int(input())
for _ in range(t):
	n = int(input())
	mas = list(map(int, input().split()))
	ind = -1
	for k in range(n - 1, -1, -1):
		if mas[k] == 1:
			ind = k
			break
	z = 0
	ans = 0
	for i in range(ind):
		if mas[i] == 1:
			z = 1
		if z and mas[i] == 0:
			ans += 1
	print(ans)


from sys import stdin

def main(n, a):
	(start, end) = (None, None)
	for i in range(n):
		if start is None and a[i] == 1:
			start = i
		if a[i] == 1:
			end = i + 1
	print(a[start:end].count(0))
t = int(stdin.readline())
cases = [(int(stdin.readline()), [int(s) for s in stdin.readline().split()]) for _ in range(t)]
for (n, a) in cases:
	main(n, a)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = a[::-1]
	al = a.index(1)
	ar = b.index(1)
	oc = a.count(1)
	print(n - al - ar - oc)


for i1 in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		print(0)
		continue
	start = 0
	for i in range(len(l)):
		if l[i] == 1:
			start = i
			break
	c = l.copy()
	c.reverse()
	end = n
	for i in range(len(c)):
		if c[i] == 1:
			end = n - i
			break
	ones = l.count(1)
	if end - start == ones:
		print(0)
		continue
	l = l[start:end]
	ans = l.count(0)
	print(ans)


l = int(input())
for i in range(0, l):
	b = int(input())
	c = list(map(int, input().split()))
	i = 0
	while c[i] == 0:
		i += 1
	j = -1
	while c[j] == 0:
		i += 1
		j -= 1
	print(c.count(0) - i)


def solve(n, bookshelf):
	shifts = 0
	i = 0
	while i < n and bookshelf[i] == 0:
		i += 1
	first_book = i
	i = n - 1
	while i >= 0 and bookshelf[i] == 0:
		i -= 1
	last_book = i
	for i in range(first_book + 1, last_book):
		if bookshelf[i] == 0:
			shifts += 1
	return shifts
t = int(input())
for _ in range(0, t):
	n = int(input())
	bookshelf = list(map(int, input().split(' ')))
	print(solve(n, bookshelf))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr.count(1) == 1:
		print(0)
		continue
	if arr == sorted(arr) or arr == sorted(arr)[::-1]:
		print(0)
		continue
	first_one_index = arr.index(1)
	count = 0
	for i in range(first_one_index + 1, n):
		if arr[i:].count(1) == 0:
			break
		if arr[i] == 0:
			count += 1
	print(count)


t = int(input())
while t:
	size = input()
	array = list(map(int, input().split()))
	diff = 0
	for i in range(0, len(array) - 1):
		if array[i] == 1 and array[i + 1] == 0:
			firstindex = i
			for j in range(i + 1, len(array)):
				if array[j] == 1:
					lastindex = j
					diff += lastindex - firstindex - 1
					break
	print(diff)
	t -= 1


for _ in range(0, int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	c = 0
	i = 0
	while i < n:
		if a[i] == 1:
			c += 1
			i = i + 1
		elif c == 0 and a[i] == 0:
			i = i + 1
		elif c != 0 and a[i] == 0:
			j = i
			while j < n:
				if a[j] == 1:
					s = s + (j - i)
					c = 0
					break
				j = j + 1
			i = j
	print(s)


from typing import *

def read_block() -> List[int]:
	elements_count = int(input())
	return [int(i) for i in input().split()]

def count_delta(l: List[int]) -> int:
	index = 0
	for i in l:
		if i:
			break
		index += 1
	index += 1
	result = 0
	delta = 0
	while index < len(l):
		if not l[index]:
			delta += 1
		else:
			result += delta
			delta = 0
		index += 1
	return result

def main() -> None:
	n = int(input())
	results: List[int] = []
	for _ in range(n):
		block = read_block()
		results.append(count_delta(block))
	for result in results:
		print(result)
main()


t = int(input())
for i in range(t):
	n = int(input())
	bookshelf = list(map(int, input().split()))
	l = bookshelf.index(1)
	r = n - 1 - bookshelf[::-1].index(1)
	moves = 0
	for j in range(l, r + 1):
		if bookshelf[j] == 0:
			moves = moves + 1
	print(moves)


n = int(input())
x = []
for _ in range(n * 2):
	a = input()
	x.append(a)
for i in range(1, n * 2, 2):
	p = x[i].split()
	i = 0
	b = 0
	j = 0
	for ad in p:
		j = j + 1
		if ad == '0':
			if '1' in p[:j]:
				i = i + 1
		elif ad == '1':
			b = b + i
			i = 0
	print(b)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(s, st, ans) = (-1, -1, 0)
	for i in range(n):
		if l[i] == 1:
			s = i
			break
	for j in range(n - 1, -1, -1):
		if l[j] == 1:
			st = j
			break
	if s != -1 and st != -1:
		print(l[s:st + 1].count(0))
	else:
		print(0)


for _ in range(int(input())):
	x = int(input())
	(*li,) = map(int, input().split())
	a = li.index(1)
	b = li[::-1].index(1)
	cnt = 0
	for i in range(a + 1, x - b - 1):
		if li[i] == 0:
			cnt += 1
	print(cnt)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	n = int(data())
	arr = l()
	temp = arr.index(1)
	rev = n - arr[::-1].index(1)
	answer = 0
	for i in range(temp, rev):
		if not arr[i]:
			answer += 1
	out(answer)


from math import *
import sys
from sys import stdin
from sys import stdout
for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if 1 not in a:
		print(0)
	else:
		x = a.index(1)
		y = x + 1
		ans = 0
		while y < n:
			if a[y] == 1:
				ans += y - x - 1
				x = y
			y += 1
		print(ans)


from typing import Iterator, Optional

def get_num_input() -> Iterator[int]:
	return map(int, input().split())

def main() -> None:
	input()
	previous: Optional[int] = None
	total: int = 0
	index: int
	value: int
	for (index, value) in enumerate(get_num_input()):
		if value:
			if previous is not None:
				total += index - previous - 1
			previous = index
	print(total)
ONLY_ONCE: bool = False
for _ in range(1 if ONLY_ONCE else int(input())):
	main()


from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	l = list()
	s = input()
	l = s.split(' ')
	try:
		min = l.index('1')
	except ValueError:
		print('0')
	else:
		max = len(l) - 1 - l[::-1].index('1')
		a = 0
		for i in range(min + 1, max):
			if l[i] == '0':
				a += 1
		print(a)


for g in range(int(input())):
	n = int(input())
	a = input()
	d = []
	a = a.replace(' ', '')
	l = list(a)
	if l == reversed(l):
		print(l.count('0'))
	if l.count('1') == 1:
		print(0)
	else:
		for i in range(len(l)):
			if l[i] == '1':
				d.append(i)
		s = 0
		for k in range(1, len(d)):
			s = s + d[k] - d[k - 1]
		print(s + 1 - len(d))


t = int(input())
for _ in range(t):
	n = int(input())
	bookshelf = list(map(int, input().split()))
	if sum(bookshelf) == 1:
		print(0)
	else:
		start = -1
		end = -1
		onecount = bookshelf.count(1)
		tempcount = 0
		answer = 0
		for i in range(n):
			if bookshelf[i] == 1 and start == -1:
				start = i
				tempcount += 1
			elif bookshelf[i] == 1 and tempcount == onecount - 1:
				end = i
				break
			elif bookshelf[i] == 1:
				tempcount += 1
			elif bookshelf[i] == 0 and start != -1 and (end == -1):
				answer += 1
		print(answer)


for _ in range(int(input())):
	n = int(input())
	arr = input().split()
	flag = False
	j = 0
	for i in range(len(arr)):
		if arr[i] == '1':
			j = i
			break
	first = j
	second = j
	ans = 0
	for i in range(j + 1, len(arr)):
		if arr[i] == '1':
			second = i
			flag = True
		if flag:
			ans += second - first - 1
		flag = False
		first = second
	print(ans)


for i in range(int(input())):
	n = int(input())
	l = input().split()
	s = l[::-1]
	k = l.index('1')
	z = n - s.index('1')
	print(l[k:z].count('0'))


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	dif = 0
	a = list(map(int, input().strip().split()))[:n]
	temp = a.index(1)
	for i in range(temp, n):
		try:
			dif = dif - 1 + a.index(1, temp + 1) - temp
			temp = a.index(1, temp + 1)
		except ValueError:
			break
	print(dif)


k = []
t = int(input())
for i in range(t):
	n = int(input())
	c = 0
	a = list(map(int, input().split()))
	(n1, n2) = (a.index(1), n - 1 - a[::-1].index(1))
	while n1 < n2:
		if a[n1] == 0:
			c += 1
		n1 += 1
	k.append(c)
for i in k:
	print(i)


t = int(input())
for i in range(t):
	n = int(input())
	li = list(map(int, input().split()))[:n]
	s = 0
	li2 = []
	for j in range(len(li)):
		if li[j] == 1:
			li2.append(j)
	if len(li2) > 1:
		for k in range(1, len(li2)):
			s += li2[k] - li2[k - 1] - 1
		print(s)
	else:
		print(0)


cases = int(input())
for tc in range(cases):
	l = input()
	s = ''.join(input().split()).strip('0')
	print(s.count('0'))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	k = l[::-1]
	if 1 not in l or l.count(1) == 1:
		print(0)
	else:
		i1 = l.index(1)
		i2 = k.index(1)
		i2 = n - i2
		l = l[i1:i2]
		print(l.count(0))


t = int(input())
while t > 0:
	t -= 1
	ans = 0
	n = int(input())
	l = list(map(int, input().split(' ')))
	ones = []
	for i in range(0, len(l)):
		if l[i] == 1:
			ones.append(i)
	for i in range(1, len(ones)):
		ans += ones[i] - ones[i - 1] - 1
	print(ans)


from sys import stdin, stdout
from collections import defaultdict
input = stdin.readline
print = stdout.write
for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().split()))
	if array.count(1) <= 1:
		print('0\n')
	else:
		while array[-1] == 0:
			array.pop()
		first = 0
		for i in range(len(array)):
			if array[i] == 1:
				first = i
				break
		myanswer = 0
		for i in range(first, len(array)):
			if array[i] == 0:
				myanswer += 1
		print(str(myanswer) + '\n')


for _ in range(int(input())):
	n = int(input())
	st = input()
	ind = st.find('1')
	ind1 = st.rfind('1')
	c1 = st[ind:ind1].count('0')
	print(c1)


cases = int(input())
for i in range(0, cases):
	input()
	shelf = input()
	print(shelf[shelf.find('1'):shelf.rfind('1') + 1].count('0'))


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	n = II()
	a = input().split()
	a = ''.join(a)
	a = a.strip('0')
	print(a.count('0'))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	firstOneFound = False
	counterOnes = 0
	counterZeros = 0
	if a.count(1) == 1:
		print(0)
	else:
		for j in a:
			if firstOneFound and j == 0:
				counterZeros = counterZeros + 1
			elif j == 1 and firstOneFound == False:
				firstOneFound = True
				counterOnes = counterOnes + 1
			elif j == 1:
				counterOnes = counterOnes + 1
			if counterOnes == a.count(1):
				break
		print(counterZeros)


def ordena(bookshelf, longitud):
	if bookshelf.count(1) == 1:
		return 0
	indices = []
	k = enumerate(bookshelf)
	indices = [index for (index, numero) in k if numero == 1]
	gaps = len(range(indices[0], indices[-1] + 1)) - len(indices)
	return gaps
test = int(input())
for i in range(test):
	longitud = int(input())
	bookshelf = list(map(int, input().split()))
	print(ordena(bookshelf, longitud))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	start = 0
	while a[start] == 0:
		start += 1
	end = n - 1
	while a[end] == 0:
		end -= 1
	answer = end - start - sum(a[start:end])
	print(answer)


import os

def compress(s, n):
	prev = None
	for i in range(n):
		if s[n - i - 1] == prev and prev == 1:
			s.pop(n - i)
		else:
			prev = s[n - i - 1]

def main():
	test_cases = int(input())
	ans = [None] * test_cases
	for t in range(test_cases):
		n = int(input())
		s = list(map(int, list(input().split())))
		compress(s, n)
		idxs = []
		for (i, v) in enumerate(s):
			if v == 1:
				idxs.append(i)
		if not idxs:
			ans[t] = 0
		else:
			(l, r) = (min(idxs), max(idxs))
			ans[t] = s[l:r].count(0)
	os.write(1, '\n'.join(map(str, ans)).encode())
main()


from math import *
from cmath import *
from itertools import *
from decimal import *
from fractions import *
from sys import *
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	(l, r) = (-1, -1)
	for i in range(n):
		if a[i] == 1:
			l = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			r = i
			break
	ans = 0
	for i in range(l, r):
		ans += a[i] == 0
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	zo = a.count(1)
	if zo == 1:
		print(0)
	else:
		i = 0
		ans = 0
		for i in range(n):
			if a[i] == 1:
				b = a[i:]
				zo1 = b.count(1)
				if zo1 > 1:
					for j in range(1, len(b)):
						if b[j] == 0:
							ans += 1
						else:
							break
		print(ans)


t = int(input())
for i in range(t):
	size = int(input())
	books = input().replace(' ', '').strip('0').replace('1', '')
	print(len(books))


t = int(input())
for i in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	res = 0
	countl = 0
	countr = 0
	count = 0
	for i in range(len(b)):
		if b[i] == 1:
			break
		else:
			countl += 1
	for i in range(1, len(b)):
		if b[-i] == 1:
			break
		else:
			countr += 1
	for i in range(countl + 1, len(b) - countr):
		if b[i] == 0:
			count += 1
	print(count)


for _ in range(int(input())):
	N = int(input())
	arr = list(map(str, input().split()))
	str_ = ''
	for i in arr:
		str_ += i
	str_ = str_.strip('0')
	print(str_.count('0'))


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	g = 0
	i = 0
	while i < n - 1:
		if a[i] == 1:
			for j in range(i + 1, n):
				if a[j] == 1:
					g += j - i - 1
					break
			i = j
		else:
			i += 1
	print(g)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	first_1 = arr.index(1)
	for i in range(n)[::-1]:
		if arr[i] == 1:
			last_1 = i
			break
	if first_1 == last_1:
		print(0)
	else:
		print(arr[first_1:last_1 + 1].count(0))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	while a[-1] == 0:
		a.pop()
	a.reverse()
	while a[-1] == 0:
		a.pop()
	print(a.count(0))


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math
from collections import defaultdict
for _ in range(ri()):
	n = ri()
	l = ria()
	i = 0
	for i in range(n):
		if l[i] == 1:
			break
	for j in range(n - 1, -1, -1):
		if l[j] == 1:
			break
	cnt = 0
	for i in range(i, j + 1):
		if l[i] == 0:
			cnt += 1
	wi(cnt)


def main():
	n = int(input())
	arr = list()
	for _ in range(n):
		k = int(input())
		arr.append(input().strip().replace(' ', ''))
	for item in arr:
		delays = list()
		k = 0
		start = 0
		for i in range(len(item)):
			if item[i] == '1':
				start = i
				break
		for i in range(start + 1, len(item)):
			tmp = item[i - 1:i + 1]
			if tmp == '10':
				k += 1
			elif tmp == '00':
				k += 1
			elif tmp == '01':
				delays.append(k)
				k = 0
			elif tmp == '11':
				k = 0
		print(sum(delays))
main()


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = a.count(0)
	i = 0
	while a[i] == 0:
		s -= 1
		i += 1
	i = n - 1
	while a[i] == 0:
		s -= 1
		i -= 1
	print(s)


def sp():
	return map(int, input().split())

def lit():
	return list(sp())

def fun(x):
	return sum((int(i) for i in str(x)))

def find(n):
	if n == 3:
		return 3
	while 1:
		flag = 0
		for i in range(2, int(sqrt(n)) + 1):
			if n % i == 0:
				n += 1
				break
			if i == int(sqrt(n)):
				flag = 1
				break
		if flag:
			break
	return n
t = int(input())
for _ in range(t):
	n = int(input())
	l = lit()
	if l.count(1) == 0 or l.count(1) == 1:
		print(0)
	else:
		ans = 0
		got = 0
		for i in range(n):
			if l[i] == 1:
				got = 1
			if l[i] == 0 and got == 1:
				ans += 1
		i = n - 1
		while l[i] == 0:
			i -= 1
			ans -= 1
		print(ans)


t = int(input(''))
for i in range(t):
	n = int(input(''))
	p = input('').split(' ')
	zc = 0
	f = False
	sf = False
	su = 0
	ch = 0
	chf = 0
	old = p[0]
	azz = 0
	counter = 0
	acount = 0
	for c in p:
		if c == '1':
			acount += 1
	while counter < n:
		c = p[counter]
		if c == '1':
			if old == '0':
				ch += 1
				old = '1'
				if f:
					chf += 1
			f = True
		if c == '0':
			azz += 1
			if old == '1':
				ch += 1
				old = '0'
				if f:
					chf += 1
			sf = True
		if c == '0' and f:
			zc += 1
		su += int(c)
		counter += 1
	ccacount = 0
	ff = False
	res = 0
	for c in p:
		if c == '1':
			ff = True
			ccacount += 1
		if c == '0' and ff:
			res += 1
		if ccacount == acount:
			break
	if su == 0:
		print('0')
		continue
	if su == n:
		print('0')
		continue
	if ch == 1:
		print('0')
		continue
	print(res)


n = int(input())
s = str()
for i in range(0, n):
	k = int(input())
	s = input()
	g2 = int(s.rfind('1'))
	g1 = int(s.find('1'))
	r = int(0)
	for j in range(g1, g2):
		if s[j] == '0':
			r += 1
	print(r)


for i in range(int(input())):
	n = int(input())
	s = input().split(' ')
	bs = ''
	pos = 0
	for i in range(n):
		bs = bs + s[i]
	while True:
		if bs[pos] == '0':
			pos = pos + 1
		else:
			break
	bs = bs[pos:]
	pos = len(bs) - 1
	while True:
		if bs[pos] == '0':
			pos = pos - 1
		else:
			break
	bs = bs[:pos + 1]
	print(bs.count('0'))


from itertools import permutations
from collections import defaultdict
from math import *
import os
import sys
from io import BytesIO, IOBase
from heapq import nlargest
from bisect import *
import copy
import itertools
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	(fp, lp) = (0, n - 1)
	for i in range(n):
		if arr[i] == 1:
			fp = i
			break
	for i in range(n - 1, -1, -1):
		if arr[i] == 1:
			lp = i
			break
	if fp >= lp:
		print('0')
	else:
		ans = 0
		for i in range(fp, lp + 1):
			if arr[i] == 0:
				ans += 1
		print(ans)


import math
from decimal import *
import random
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(start, end) = (-1, 0)
	ans = 0
	for i in range(n):
		if arr[i] == 1:
			if start == -1:
				start = int(i)
			else:
				end = i
	for i in range(start, end + 1):
		if arr[i] == 0:
			ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = ''.join(list(map(str, input().split())))
	arr = arr.strip('0')
	n = len(arr)
	arr0 = ['0'] * n
	for i in range(n):
		if arr[i] == '0':
			arr0[i] = '1'
	arr0 = ''.join(arr0).strip('0')
	sm = 0
	for i in arr0:
		sm += int(i)
	print(sm if arr.count('1') > 1 else 0)


t = int(input())
for _ in range(t):
	flag = False
	z = 0
	o = 0
	n = int(input())
	l = list(input().split())
	for val in l:
		if val == '1':
			flag = True
			o += 1
			c = 0
		if flag == True and val == '0':
			z += 1
			c += 1
	if o > 1:
		print(z - c)
	else:
		print(0)


n = int(input())
for i in range(n):
	l = int(input())
	num = list(map(int, input().split()))
	ans = 0
	a = 0
	flag = False
	for j in range(l):
		if num[j] == 1:
			if flag:
				ans += j - a - 1
			flag = True
			a = j
	print(ans)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] == 1:
			st = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			en = i
			break
	if en != n - 1:
		en += 1
	c = 0
	for i in range(st, en):
		if a[i] == 0:
			c += 1
	print(c)
	t = t - 1


a = int(input())
for i in range(a):
	b = int(input())
	l = list(map(int, input().split()))
	a1 = 0
	a2 = 0
	for i in range(b):
		if l[i] == 1:
			a1 = i
			break
	for i in range(b - 1, -1, -1):
		if l[i] == 1:
			a2 = i
			break
	if a1 == a2:
		print(0)
	else:
		co = 0
		for i in range(a1, a2):
			if l[i] == 0:
				co += 1
		print(co)


try:

	def numOfMoves(arr, n):
		c0 = arr.count(1)
		if c0 == 1:
			return 0
		else:
			ans = 0
			l = []
			for i in range(n):
				if arr[i] == 1:
					l.append(i)
			for j in range(0, len(l) - 1):
				ans += abs(l[j] - l[j + 1])
				ans -= 1
			return ans
	for _ in range(int(input())):
		n = int(input())
		arr = [int(x) for x in input().split()]
		ans = numOfMoves(arr, n)
		print(ans)
except:
	pass


for _ in range(int(input())):
	n = input()
	a = list(map(int, input().split()))
	flag = False
	cnt = 0
	count = 0
	for i in range(len(a)):
		if flag:
			if a[i] == 0:
				cnt += 1
			else:
				count += cnt
				cnt = 0
		elif a[i] == 1:
			flag = True
	print(count)


import sys
input = sys.stdin.buffer.readline
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	while a[-1] == 0:
		a.pop()
	a.reverse()
	while a[-1] == 0:
		a.pop()
	print(a.count(0))


for T in range(int(input())):
	n = int(input())
	s = ''.join(list(map(str, input().split())))
	first = s[0]
	last = s[-1]
	s = s.split('1')
	s = [i for i in s if i != '']
	val = 0
	for st in s[first == '0':len(s) - (last == '0')]:
		val += len(st)
	print(val)


for i in range(int(input())):
	x = int(input())
	l = list(map(int, input().split()))
	(s, e) = (0, 0)
	for i in range(x):
		if l[i] is 1:
			s = i
			break
	for i in range(x - 1, -1, -1):
		if l[i] is 1:
			e = i
			break
	print(e - s + 1 - sum(l[s:e + 1]))


t = int(input())
for i in range(t):
	k = 0
	n = int(input())
	a = list(map(int, input().split()))
	for j in range(len(a)):
		if a[j] == 1:
			p = j
			break
	for j in a[::-1]:
		if j == 1:
			po = len(a) - 1 - a[::-1].index(j)
			break
	for j in range(p, po):
		if a[j] == 0:
			k += 1
	print(k)


t = int(input())
for x in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	if l.count(1) == 1:
		print(0)
	else:
		while l[0] != 1:
			l.pop(0)
		l.reverse()
		while l[0] != 1:
			l.pop(0)
		print(l.count(0))


a = input()
a = int(a)
for i in range(a):
	b = input()
	b = int(b)
	zz = []
	zz = input().split(' ')
	z = ''
	for i in zz:
		z = z + i
	L = None
	ans = 0
	R = 0
	pos = 0
	while True:
		if pos == len(z) - 1:
			break
		if L == None:
			L = z.find('1')
		else:
			R = z.find('1', L + 1)
			if R == -1:
				break
			ans = R - L - 1 + ans
			L = R
		pos += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input().split()
	start_count = False
	ct = 0
	for i in a:
		if i == '1':
			start_count = True
		if start_count:
			if i == '0':
				ct += 1
	for i in a[::-1]:
		if i == '1':
			break
		ct -= 1
	print(ct)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	t = []
	nz = 0
	for i in range(n):
		if a[i] and (not t):
			t.append(i)
			t.append(0)
			nz = 0
		elif a[i]:
			t[-1] += nz
			nz = 0
		else:
			nz += 1
	print(t[-1] if t[-1] else 0)


for j in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = str(a)
	p = 0
	s = b.find('1')
	c = b.rfind('1')
	for i in range(s, c):
		if b[i] == '0':
			p = p + 1
	print(p)


import sys

def solve():
	n = int(input())
	li = [int(i) for i in input().split()]
	l = False
	(ans, t) = map(int, [0, 0])
	for i in li:
		if i == 0:
			t += 1
		else:
			if l == True:
				ans += t
			else:
				l = True
			t = 0
	print(ans)
while True:
	line = sys.stdin.readline()
	if not line:
		break
	for cas in range(int(line)):
		solve()


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	is_start = 0
	end = 0
	answer = 0
	for i in range(n):
		if a[i] == 0:
			if is_start == 1:
				end += 1
		else:
			answer += end
			end = 0
			is_start = 1
	print(answer)


testcases = int(input())
for testcase in range(testcases):
	segments = int(input())
	books = [int(book) for book in input().strip().split()]
	flag = False
	firstBookIndex = lastBookIndex = 0
	for bookIndex in range(len(books)):
		if books[bookIndex]:
			if not flag:
				firstBookIndex = bookIndex
				flag = True
			else:
				lastBookIndex = bookIndex
	total = sum(books[firstBookIndex:lastBookIndex + 1])
	emptySpaces = lastBookIndex - firstBookIndex - total + 1
	print(emptySpaces if emptySpaces > 0 else 0)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	c1 = []
	c0 = 0
	for i in range(n):
		if l[i] == 1:
			c1.append(i)
	count = 0
	for i in range(len(c1) - 1):
		count += c1[i + 1] - c1[i] - 1
	print(count)


for i in range(int(input())):
	n = int(input())
	s = list(input())
	l = []
	for i in range(len(s)):
		if s[i] == '1':
			l.append(i)
	l1 = s[l[0]:l[-1] + 1]
	print(l1.count('0'))


t = int(input())
for i in range(t):
	x = int(input())
	poses = input().split()
	e = 0
	b = len(poses) - 1
	while poses[e] != '1':
		e += 1
	while poses[b] != '1':
		b -= 1
	turns = 0
	hlp = ''
	for j in range(e, b + 1, 1):
		hlp += poses[j]
	for j in hlp:
		if j == '0':
			turns += 1
	print(turns)


t = int(input())

def get_gaps(ls):
	i = 0
	gaps = []
	while i < len(ls) and ls[i] == 0:
		i += 1
	ls = ls[i:]
	i = 0
	while i >= 0 and ls[len(ls) - 1 - i] == 0:
		i += 1
	ls = ls[0:len(ls) - i]
	i = 0
	while i < len(ls):
		beg = i
		while ls[i] == 0:
			i += 1
		last = i
		i += 1
		gap = last - beg
		if gap != 0:
			gaps.append(gap)
	return gaps
for _ in range(t):
	n = int(input())
	books = list(map(int, input().split()))
	print(sum(get_gaps(books)))


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	n = iinp()
	arr = lmp()
	print(arr[arr.index(1):n - 1 - arr[::-1].index(1)].count(0))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	pre = a[0]
	l = []
	cnt = 0
	for i in range(n):
		if a[i] == pre:
			cnt += 1
		else:
			l.append(cnt)
			cnt = 1
			pre = a[i]
	if a[0] == 0:
		ans = sum(l[2::2])
	else:
		ans = sum(l[1::2])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	start = l.index(1)
	end = n - 1 - l[::-1].index(1)
	if start == end:
		print(0)
	else:
		ans = 0
		for i in range(start, end + 1):
			if l[i] == 0:
				ans += 1
		print(ans)


T = int(input())
for ti in range(T):
	n = int(input())
	A = [int(i) for i in input().split()]
	new = []
	for i in A:
		if len(new) == 0:
			new.append(i)
		elif new[-1] == 1 and i == 1:
			continue
		else:
			new.append(i)
	ans = 10000000
	seenone = False
	cur = 0
	since = 0
	for i in new:
		if seenone == False and i == 0:
			continue
		if i == 1 and seenone == False:
			seenone = True
		if seenone == True and i == 0:
			since += 1
		elif seenone and i == 1:
			cur += since
			since = 0
	ans = min(ans, cur)
	cur = 0
	since = 0
	for i in new[::-1]:
		if seenone == False and i == 0:
			continue
		if i == 1 and seenone == False:
			seenone = True
		if seenone == True and i == 0:
			since += 1
		elif seenone and i == 1:
			cur += since
			since = 0
	ans = min(ans, cur)
	print(ans)


caseNum = int(input())
for i in range(caseNum):
	shelfNum = int(input())
	start = -1
	end = -1
	bookPos = list(map(int, input().split(' ')))
	for j in range(len(bookPos)):
		if bookPos[j] == 1 and start == -1:
			start = j
		if bookPos[j] == 1 and j >= end:
			end = j
	ans = end - start - sum(bookPos[start:end])
	print(ans)


n = int(input())
while n:
	l = []
	su = 0
	a = int(input())
	s = [i for i in input().split(' ')]
	for i in range(0, len(s)):
		if s[i] == '1':
			l.append(i)
	for i in range(0, len(l) - 1):
		su = su + (l[i + 1] - l[i] - 1)
	print(su)
	n = n - 1


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	x = [0]
	pp = -1
	for j in range(n):
		if a[j] == 1:
			pp = j
			break
	brk = 0
	for j in range(pp + 1, n):
		if a[j] == 1:
			x.append(brk)
			brk = 0
		else:
			brk += 1
	print(sum(x))


t = int(input())
for i in range(t):
	n = int(input())
	s = str(input())
	s1 = s.replace(' ', '')
	a = s1.find('1')
	b = s1.rfind('1')
	print(s1.count('0', a, b))


tests = int(input())
for t in range(tests):
	size = int(input())
	A = list(map(int, input().split()))
	firstfound = False
	summ = 0
	tempsumm = 0
	for i in A:
		if i == 0:
			if firstfound:
				tempsumm += 1
		if i == 1:
			if not firstfound:
				firstfound = True
			else:
				summ += tempsumm
				tempsumm = 0
	print(summ)


for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = a.count(1)
	if c == 1:
		print(0)
	else:
		(first, last) = (-1, -1)
		for i in range(n):
			if a[i] == 1:
				if first == -1:
					first = i
				last = i
		answer = 0
		for i in range(first + 1, last):
			if a[i] == 0:
				answer += 1
		print(answer)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	for j in range(n):
		if a[j] == 1:
			f = j
			break
	for h in range(n - 1, -1, -1):
		if a[h] == 1:
			l = h
			break
	a = a[f:l + 1]
	print(a.count(0))


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	c = s.count(0)
	a = s.index(1)
	b = s[-1::-1].index(1)
	c = c - a - b
	print(c)


import sys
import itertools

def get_line():
	return list(map(int, sys.stdin.readline().strip().split()))

def in1():
	return int(input())
for _ in range(in1()):
	n = in1()
	a = get_line()
	i = -1
	j = -1
	c = 0
	for k in range(n):
		if a[k] == 1 and j == -1 and (i == -1):
			i = k
		elif a[k] == 1 and i != -1 and (j == -1):
			c += k - i - 1
			i = k
			j = -1
	print(c)


import sys

def input():
	return sys.stdin.readline().strip()

def mod():
	return 10 ** 9 + 7
t = int(input())
while t:
	n = int(input())
	a = -1
	arr = list(map(int, input().split()))
	x = arr.index(1)
	for i in range(n - 1, 0, -1):
		if arr[i] == 1:
			a = i
			break
	li = arr[x:a + 1]
	print(li.count(0))
	t -= 1


import sys
import math
input = sys.stdin.readline

def algo(n, arr):
	f = False
	ans = 0
	j = 0
	for i in range(n):
		if arr[i] == 1:
			f = True
			ans += j
			j = 0
		if arr[i] == 0 and f:
			j += 1
	return ans
for _ in range(int(input())):
	n = int(input().strip())
	arr = list(map(int, input().split()))
	res = algo(n, arr)
	print(res)


def solve(n, a):
	return (n, a)

def run():
	(t, *_) = list(map(int, input().split()))
	for item in range(t):
		(n, *_) = list(map(int, input().split()))
		a = len(''.join(list(map(str, input().split()))).strip('0').split('0')) - 1
		print(a)
run()


for i in range(0, int(input())):
	n = int(input())
	l = input().split()
	l = [int(x) for x in l]
	l1 = []
	s = 0
	for j in range(0, n):
		if l[j] == 1:
			l1.append(j)
	for j in range(1, len(l1)):
		if l1[j - 1] + 1 != l1[j]:
			s += l1[j] - l1[j - 1] - 1
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	l = r = a.index(1)
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			r = i
			break
	print(a[l:r].count(0))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
from collections import Counter, defaultdict, deque

def int1():
	return int(input())

def map1():
	return map(int, input().split())

def list1():
	return list(map(int, input().split()))
mod = pow(10, 9) + 7

def solve():
	n = int1()
	l1 = list1()
	l2 = []
	for i in range(n):
		if l1[i] == 1:
			l2.append(i)
	v = len(l2)
	if v == 0 or v == 1:
		print(0)
	else:
		flag = 0
		count = 0
		for i in range(v - 1):
			if l2[i] + 1 != l2[i + 1]:
				flag = 1
				count += l2[i + 1] - l2[i] - 1
		if flag == 0:
			print(0)
		else:
			print(count)
for _ in range(int(input())):
	solve()


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	ans = A[A.index(1):N - A[::-1].index(1)].count(0)
	print(ans)


t = int(input())
for i in range(t):
	(ans, o) = (0, -1)
	n = int(input())
	ar = list(map(int, input().split()))
	for j in range(len(ar)):
		if ar[j] == 1:
			if o == -1:
				o = j
				continue
			ans += j - o - 1
			o = j
	print(ans)


for i in range(int(input())):
	input()
	line = input().replace(' ', '')
	line = line[line.find('1'):][::-1]
	line = line[line.find('1'):][::-1]
	print(line.count('0'))


t = int(input())
for i in range(t):
	num = int(input())
	a = list(map(int, input().split()))
	i = 1
	su = 0
	while i < num - 1:
		p1 = 0
		if a[i - 1] == 1:
			while a[i] == 0 and i < num - 1:
				p1 += 1
				i += 1
		if a[i] == 1:
			su += p1
		i += 1
	print(su)


def remove(string):
	return string.replace(' ', '')
for _ in range(int(input())):
	n = int(input())
	s = str(input())
	s = remove(s)
	print(s.strip('0').count('0'))


def fun(z):
	c = 0
	while 1:
		if all(z):
			return c
		if z[-1] == 0:
			z = z[:len(z) - 1]
			continue
		if z[0] == 0:
			z = z[1:]
			continue
		else:
			c = c + z.count(0)
			break
	return c
t = int(input())
for i in range(t):
	n = int(input())
	z = list(map(int, input().split()))
	k = fun(z)
	print(k)


for _ in range(int(input())):
	n = int(input())
	list = [str(num) for num in input().split()]
	l = ''.join(list).strip('0')
	print(l.count('0'))


for _ in range(int(input())):
	hahaha = int(input())
	sisya = list(map(int, input().split()))
	pidr = []
	for (zhopa, i) in enumerate(sisya):
		if i == 1:
			pidr.append(zhopa)
	loh = len(pidr)
	dounil = pidr[0]
	hui = len(sisya) - 1 - pidr[-1]
	print(len(sisya) - loh - dounil - hui)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = a[::-1]
	x = a.index(1)
	y1 = b.index(1)
	y = len(a) - 1 - y1
	a = a[x:y + 1]
	print(a.count(0))


t = int(input())
for j in range(t):
	input()
	a = input()
	first = a.index('1')
	last = a.rindex('1')
	a = a[first:last + 1]
	print(a.count('0'))


for _ in range(int(input())):
	N = int(input())
	s = list(map(int, input().split()))
	(r, a) = (0, s.index(1))
	for i in range(a + 1, N):
		if s[i] == 1:
			r += i - a - 1
			a = i
	print(r)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	for i in range(len(a)):
		if a[i] == 1:
			start = i
			break
	for j in range(n - 1, -1, -1):
		if a[j] == 1:
			end = j
			break
	if start == end:
		print(0)
	else:
		for i in range(start, end):
			if a[i] == 0:
				count += 1
		print(count)


t = int(input())
for i in range(t):
	s = input()
	s = input()
	s1 = s.split()
	l = [int(i) for i in s1]
	start = -1
	end = -1
	for i in range(len(l)):
		if l[i] == 1:
			if start == -1:
				start = i
			end = i
	if start == -1 or start == end:
		print(0)
	else:
		cnt = 0
		for i in range(start, end + 1):
			if l[i] == 0:
				cnt = cnt + 1
		print(cnt)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(str, input().strip().split()))
	ans = 0
	for i in range(n):
		if arr[i] == '1':
			break
	for j in range(n - 1, -1, -1):
		if arr[j] == '1':
			break
	if i == n - 1 or j == 0:
		print(ans)
		continue
	elif i == j:
		print(ans)
		continue
	else:
		ans += j - i + 1
		for k in range(i, j + 1):
			ans -= int(arr[k])
		print(ans)


def cntLeft(a):
	cnt = 0
	cnt0 = 0
	j = 0
	while a[j] != 1:
		j += 1
	for i in range(j, len(a)):
		if a[i] == 0:
			cnt0 += 1
		else:
			cnt += cnt0
			cnt0 = 0
	return cnt
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(j) for j in input().split()]
	print(min(cntLeft(a), cntLeft(a[::-1])))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	p = -1
	for i in range(n):
		if a[i] == 1:
			if p == -1:
				p = i
			q = i
	if p == -1:
		print(0)
		continue
	print(a[p:q + 1].count(0))


for _ in range(int(input())):
	n = int(input())
	books = list(input().split())
	l = []
	for i in range(n):
		if books[i] == '1':
			l.append(i + 1)
	moves = 0
	for i in range(len(l) - 1):
		moves += l[i + 1] - l[i] - 1
	print(moves)


for _ in range(int(input())):
	n = int(input())
	s = input()
	print(s.strip('0 ').count('0'))


t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	s = sum(A)
	j = 0
	while A[j] != 1:
		j += 1
	j1 = n - 1
	while A[j1] != 1:
		j1 -= 1
	print(j1 - j + 1 - s)


def loop(a):
	no_step = 0
	for i in a:
		if i == '1':
			break
		no_step += 1
	return no_step
for i in range(int(input())):
	input()
	a = input()
	a = a.replace(' ', '')
	step = a.count('0') - (loop(a) + loop(a[::-1]))
	if '1' * a.count('1') in a:
		print(0)
	else:
		print(step)


mod = 10 ** 9 + 7

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	ok = False
	tmp = 1
	for i in range(n):
		if a[i] == 1:
			if ok:
				ans += tmp
			ok = True
			tmp = 0
		elif a[i] == 0:
			tmp += 1
	print(ans)
t = 1
t = int(input())
while t > 0:
	solve()
	t -= 1


t = int(input())
for i in range(t):
	ans = 0
	ans1 = 0
	fl = 0
	n = int(input())
	a = list(map(int, input().split()))
	for j in range(n):
		if fl == 1:
			if a[j] == 0:
				ans += 1
			else:
				fl = 0
				ans1 += ans
				ans = 0
		if a[j] == 1:
			fl = 1
	print(ans1)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		n = ri()
		a = ria()
		d = Counter(a)
		n1 = d[1]
		for i in range(n):
			if a[i] == 1:
				fi = i
				break
		for i in range(n - 1, -1, -1):
			if a[i] == 1:
				li = i
				break
		if n1 == 0:
			print(0)
		else:
			print(li - fi + 1 - n1)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


def rindex(mylist: list, myvalue):
	return len(mylist) - mylist[::-1].index(myvalue) - 1

def main():
	t = int(input())
	for s in range(t):
		n = int(input())
		lst = list((int(i) for i in input().split()))
		f_element_index = lst.index(1)
		l_element_index = rindex(lst, 1)
		cnt_zero = lst[f_element_index:l_element_index].count(0)
		if (f_element_index == l_element_index or cnt_zero == 0) and (f_element_index == 0 or l_element_index == len(lst) - 1):
			print(0)
		else:
			print(cnt_zero)
main()


def mi():
	return map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	i = n - 1
	while arr[i] != 1:
		i -= 1
	x = i
	i = 0
	while arr[i] != 1:
		i += 1
	out = 0
	while i <= x:
		if arr[i] == 0:
			out += 1
		i += 1
	print(out)


for _ in [*open(0)][2::2]:
	arr = list(map(int, _.split()))
	k = len(arr)
	for i in range(k):
		if arr[i]:
			x = i
			break
	for j in range(k - 1, -1, -1):
		if arr[j]:
			y = j
			break
	print(arr[x:y + 1].count(0))


t = int(input())
for case in range(t):
	n = int(input())
	a = input()
	ans = a[a.index('1'):a.rindex('1') + 1].count('0')
	print(ans)


try:
	T = int(input())
	for _ in range(T):
		N = int(input())
		L = input()
		M = L.strip('0 ')
		O = []
		for i in M:
			if i == ' ':
				pass
			else:
				O.append(int(i))
		print(O.count(0))
except EOFError:
	pass


t = int(input())
for z in range(t):
	myList = list()
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	oneCount = 0
	for i in range(n):
		if a[i] == 1:
			oneCount = oneCount + 1
			myList.append(i)
	if oneCount <= 1:
		print(0)
		continue
	count = 0
	for j in range(len(myList)):
		if j + 1 < len(myList) and myList[j + 1] - myList[j] > 1:
			count = count + myList[j + 1] - myList[j] - 1
	print(count)


for _ in range(int(input())):
	lens = int(input())
	poss = [int(x) for x in input().split()]
	(lidx, ridx) = (-1, -1)
	for (i, v) in enumerate(poss):
		if v == 1:
			if lidx == -1:
				lidx = i
			ridx = i
	answer = sum([1 for x in poss[lidx:ridx + 1] if x == 0])
	print(answer)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	l = 0
	r = 0
	for i in range(n):
		if arr[i] == 1:
			l = i
			break
	for i in range(n - 1, -1, -1):
		if arr[i] == 1:
			r = i
			break
	count = 0
	for i in range(l, r + 1):
		if arr[i] == 0:
			count += 1
	print(count)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		first = last = -1
		for i in range(n):
			if a[i] == 1:
				last = i
				if first == -1:
					first = i
		total = 0
		for j in range(first, last):
			if a[j] == 0:
				total += 1
		print(total)
main()


w = int(input())
for i in range(w):
	number = input()
	str = input().split(' ')
	a = 0
	b = 0
	for j in range(len(str)):
		if str[j] == '1':
			a = j
			break
	for j in range(len(str) - 1, 0, -1):
		if str[j] == '1':
			b = j
			break
	count = 0
	for q in range(a, b):
		if str[q] == '0':
			count += 1
	print(count)


for tc in range(int(input())):
	n = int(input())
	line = input().split()
	arr = []
	pos = []
	for i in range(n):
		arr.append(int(line[i]))
		if arr[i] == 1:
			pos.append(i)
	maxx = max(pos)
	minn = min(pos)
	count = 0
	for i in range(minn + 1, maxx):
		if arr[i] == 0:
			count += 1
	print(count)


test_cases = int(input())
for testcase in range(test_cases):
	items = int(input())
	bookshelf = [int(i) for i in input().split()]
	list_one = []
	count = 0
	if bookshelf.count(1) == 1:
		print(0)
	else:
		for book in bookshelf:
			count += 1
			if book == 1:
				list_one.append(count - 1)
		print(bookshelf[list_one[0]:list_one[-1]].count(0))


a = int(input())
for i in range(a):
	b = int(input())
	n = input().replace(' ', '')
	i = 0
	l = 0
	while n[i] != '1':
		i += 1
		l += 1
	i = b - 1
	r = i
	while n[i] != '1':
		i -= 1
		r -= 1
	n += '#'
	print(n[l:r + 1].count('0'))


import array
T = int(input())
for i in range(T):
	ans = 0
	n = int(input())
	a = array.array('i', map(int, input().split()))
	(f, s) = (0, 0)
	for i in range(n):
		if a[i] == 1:
			ans = ans + s
			f = 1
			s = 0
		else:
			s = s + f
	print(ans)


T = int(input())
for t in range(T):
	n = int(input())
	A = input().split()
	one = []
	for i in range(n):
		if A[i] == '1':
			one.append(i)
	if len(one) == 1:
		print(0)
	else:
		ans = 0
		for i in range(one[0] + 1, one[-1]):
			if A[i] == '0':
				ans += 1
		print(ans)


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
import random
import re
import heapq
t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	st = False
	zsf = 0
	ans = 0
	for a in arr:
		if not st:
			if a == 1:
				st = True
		elif a == 1:
			ans += zsf
			zsf = 0
		else:
			zsf += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	temp = []
	for i in range(n):
		if arr[i] == 1:
			temp.append(i)
	res = 0
	for i in range(1, len(temp)):
		res += temp[i] - temp[i - 1] - 1
	print(res)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c for j in range(b)] for i in range(a)]

def list3d(a, b, c, d):
	return [[[d for k in range(c)] for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** (-10)
for _ in range(INT()):
	N = INT()
	A = LIST()
	l = r = -1
	for i in range(N):
		if A[i]:
			if l == -1:
				l = i
			r = i
	ans = 0
	if l != -1:
		for i in range(l, r + 1):
			if not A[i]:
				ans += 1
	print(ans)


import math
t = int(input())
for w in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	k = l.index(1)
	for i in range(n - 1, -1, -1):
		if l[i] == 1:
			k1 = i
			break
	c = 0
	for i in range(k, k1 + 1):
		if l[i] == 0:
			c += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	si = -1
	ei = -1
	for i in range(n):
		if arr[i] == 1:
			si = i
			break
	for i in range(n - 1, -1, -1):
		if arr[i] == 1:
			ei = i
			break
	sarr = arr[si:ei + 1]
	print(sarr.count(0))


for x in range(int(input())):
	n = int(input())
	m = list(map(int, input().split()))
	t = 0
	ans = 0
	c = 0
	for i in range(n):
		if m[i] and t == 1:
			ans += c
			c = 0
		elif m[i] == 0 and t == 1:
			c += 1
		elif m[i]:
			t = 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	while arr[-1] == 0:
		arr.pop()
	while arr[0] == 0:
		arr.pop(0)
	print(arr.count(0))


for _i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	for i in range(n):
		if a[i] == 1:
			b = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			c = i
			break
	x = a[b:c + 1]
	print(x.count(0))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(0)
		continue
	(d1, d2) = (-1, -1)
	for i in range(n):
		if a[i]:
			if d1 < 0:
				d1 = i
			d2 = i
	print(d2 - d1 - sum(a) + 1)


import re
for _ in range(int(input())):
	n = int(input())
	s = ''.join(input().split())
	count1 = 0
	while re.search('10+1', s):
		m = re.search('1(0+)1', s)
		(l, i) = (len(m.group(1)), m.end())
		count1 += l
		s = s[i - 1:]
	count2 = 0
	t = s[::-1]
	while re.search('10+1', t):
		m = re.search('1(0+)1', t)
		(l, i) = (len(m.group(1)), m.end())
		count2 += l
		t = t[i - 1:]
	print(max(count1, count2))


n = int(input())
for i in range(n):
	t = int(input())
	a = [int(i) for i in input().split()]
	c = a.count(1)
	if c <= 1:
		print(0)
	else:
		(m1, m2) = ([], [])
		for j in range(len(a) - 1):
			if a[j] == 1 and a[j + 1] == 0 and (j + 1 != len(a) - 1):
				m1.append(j)
			elif a[j] == 0 and a[j + 1] == 1 and (len(m1) != 0):
				m2.append(j + 1)
		if len(m2) == 0 or len(m1) == 0:
			print(0)
		else:
			c = m2[-1] - m1[0] - 1
			for j in range(m1[0] + 1, m2[-1]):
				if a[j] == 1:
					c -= 1
			print(c)


t = int(input())
for i in range(t):
	n = int(input())
	texto = input()
	texto = texto.replace(' ', '')
	texto = texto.rstrip('0')
	texto = texto.lstrip('0')
	texto = texto.replace('1', '')
	print(len(texto))


t = int(input())
while t > 0:
	count_of_elems = int(input())
	info = list(map(int, input().split()))
	if info.count(1) == 1:
		print(0)
	else:
		counter = 0
		first_index = info.index(1)
		last_index = count_of_elems - 1 - info[::-1].index(1)
		for i in range(first_index, last_index + 1):
			if info[i] == 0:
				counter += 1
		print(counter)
	t -= 1


import sys
read = sys.stdin.read
from itertools import accumulate

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = tuple(map(int, input().split()))
		aa = tuple(accumulate(a))
		p1 = aa.index(1)
		pm = aa.index(max(aa))
		ans = pm - p1 - max(aa) + 1
		print(ans)
main()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	idx = 0
	d = 0
	out = 0
	f = 0
	for i in l:
		if i == 1:
			f = 1
			idx = i
			out += d
			d = 0
		elif f == 1:
			d += 1
	print(out)


t = int(input())
k = 0
z = 0
while t > 0:
	n = int(input())
	l = [int(x) for x in input().split()]
	for i in range(len(l)):
		if l[i] == 1:
			k = i
			break
	for i in range(len(l) - 1, -1, -1):
		if l[i] == 1:
			z = i
			break
	if k != z:
		print(l[k:z].count(0))
	else:
		print(0)
	t -= 1


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	n = ip()
	arr = list(inp())
	gap = []
	st = arr.index(1)
	for i in range(n - 1, -1, -1):
		if arr[i] == 1:
			end = i
			break
	ct = 0
	for i in range(st, end + 1):
		if arr[i] == 0:
			ct += 1
		else:
			if ct != 0:
				gap.append(ct)
			ct = 0
	if ct != 0:
		gap.append(ct)
	ans = sum(gap)
	out(ans)


n = int(input())
for i in range(n):
	flag = False
	k = int(input())
	a = list(map(int, input().split()))
	nl = 0
	nlo = 0
	for i in range(k):
		if a[i] == 1:
			flag = True
		if flag:
			if a[i] == 0:
				nl += 1
			elif a[i] == 1:
				nlo += nl
				nl = 0
	print(nlo)


t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	(left, right) = (-1, -1)
	ans = 0
	for i in range(len(l)):
		if l[i] == 1:
			if left == -1:
				left = i
			else:
				right = i
				ans += right - left - 1
				left = right
	print(ans)


import sys

def main():
	t = Iint()
	for _ in range(t):
		n = Iint()
		a = Ilist()
		start = False
		ans = 0
		for (i, ai) in en(a):
			if not start and ai == 1:
				start = True
				x = i
			elif start and ai == 1:
				ans += i - x - 1
				x = i
		print(ans)
en = enumerate
FIO = 10

def debug(*args, c=6):
	pass
	print('\x1b[3{}m'.format(c), *args, '\x1b[0m', file=sys.stderr)
BUFSIZE = 8 * 1024

def Istr():
	return input()

def Iint():
	return int(input())

def Ilist():
	return list(map(int, input().split()))

def Imap():
	return map(int, input().split())

def Plist(li, s=' '):
	print(s.join(map(str, li)))
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
else:
	from io import BytesIO, IOBase
	import os

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	a = input().split()
	l = ''.join(a)
	x = a.index('1')
	a.reverse()
	y = n - a.index('1')
	l = l[x:y]
	print(l.count('0'))


N = int(input())
for i in range(N):
	n = int(input())
	p = list(map(int, input().split()))
	isLeft1 = 0
	res = 0
	subRes = 0
	for i in range(n):
		if isLeft1 == 1 and p[i] == 0:
			subRes += 1
		elif isLeft1 == 1 and p[i] == 1:
			res += subRes
			subRes = 0
		elif isLeft1 == 0 and p[i] == 1:
			isLeft1 = 1
	print(res)


def solution():
	num = int(input())
	res = []
	for i in range(num):
		out = []
		indices = []
		nm = int(input())
		test = list(map(str, input().split()))
		for i in range(len(test)):
			if test[i] == '1':
				indices.append(i)
		idx = test[indices[0]:indices[-1]].count('0')
		print(idx)
solution()


test = int(input())
counter1 = 0
list = []
while counter1 < test:
	answer = 0
	length = int(input())
	list2 = input()
	i = 0
	firstone = 0
	while int(list2[2 * i]) == 0:
		i += 1
		firstone += 1
	lastone = length - 1
	i = -1
	while int(list2[2 * i + 1]) == 0:
		i -= 1
		lastone -= 1
	while firstone < lastone:
		firstone += 1
		if int(list2[2 * firstone]) == 0:
			answer += 1
	counter1 += 1
	list.append(answer)
counter1 = 0
while counter1 < test:
	print(list[counter1])
	counter1 += 1


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	try:
		s = a.index(1)
		a.reverse()
		e = n - a.index(1)
		a.reverse()
		print(a[s:e].count(0))
	except ValueError:
		print(0)


t = int(input())
n = [0] * t
for i in range(0, t):
	a = input()
	a = input()
	if a.find('1') != a.rfind('1'):
		a = a[a.find('1'):a.rfind('1')]
		n[i] = a.count('0')
	else:
		n[i] = 0
for i in range(t):
	print(n[i])


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	new = []
	c = 0
	for i in range(n):
		if l[i] == 1:
			new.append(i + 1)
	for i in range(len(new) - 1):
		c += new[i + 1] - new[i] - 1
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	A = [int(n) for n in input().split()]
	(left, right) = (0, len(A) - 1)
	while left < right and A[left] != 1:
		left += 1
	while right > left and A[right] != 1:
		right -= 1
	res = sum((a == 0 for a in A[left:right + 1]))
	print(res)


testCase = int(input())
for i in range(testCase):
	number = int(input())
	arr = [int(x) for x in input().split()]
	rindex = 0
	for i in arr:
		if i == 1:
			break
		rindex = rindex + 1
	count = 0
	lindex = 0
	for i in arr:
		if i == 1:
			lindex = count
		count = count + 1
	result = 0
	for i in arr[rindex:lindex + 1]:
		if i == 0:
			result = result + 1
	print(result)


n = int(input())
for i in range(n):
	t = int(input())
	a = input().split()
	i = 0
	j = len(a) - 1
	while a[i] != '1':
		i += 1
	while a[j] != '1':
		j -= 1
	print(a[i:j + 1].count('0'))


import sys
amt = int(sys.stdin.readline())
for i in range(0, amt):
	leng = sys.stdin.readline()
	vlist = sys.stdin.readline().split()
	for j in range(0, len(vlist)):
		vlist[j] = int(vlist[j])
	while vlist[0] == 0:
		vlist.pop(0)
	while vlist[len(vlist) - 1] == 0:
		vlist.pop(len(vlist) - 1)
	c = 0
	for j in vlist:
		c += 1 - j
	sys.stdout.write(str(c))
	sys.stdout.write('\n')


t = int(input())
r = []
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	total = 0
	if a.count(1) == 1:
		r.append(0)
	else:
		indices = [i for (i, x) in enumerate(a) if x == 1]
		m = max(indices)
		n = min(indices)
		for x in a[n:m]:
			if x == 0:
				total += 1
			else:
				pass
		r.append(total)
for x in r:
	print(x)


for _ in range(int(input())):
	input()
	x = input().split()
	start = False
	sm = 0
	sm_temp = 0
	for v in x:
		if v == '1':
			if start:
				sm += sm_temp
				sm_temp = 0
			else:
				start = True
		elif start:
			sm_temp += 1
	print(sm)


t = int(input())
for q in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	r = 0
	ml = 0
	ab = False
	for i in range(n):
		if ab:
			if b[i] == 0:
				ml += 1
			else:
				r = ml
		elif b[i] == 1:
			ab = True
	print(r)


T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	l = []
	f = 0
	cnt = 0
	for i in arr:
		if i == 0 and f:
			cnt += 1
		elif i == 1:
			f = 1
			if cnt:
				l.append(cnt)
			cnt = 0
	print(sum(l))


for _ in range(int(input())):
	n = input()
	a = list(map(int, input().split()))
	if a.count(1) == 1 or a.count(1) == 0:
		print(0)
	else:
		count = 0
		p = a.index(1)
		j = 0
		for i in range(len(a) - 1, p, -1):
			if a[i] == 1:
				j = i
				break
		for i in range(p, j):
			if a[i] == 0:
				count += 1
		print(count)


t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	a = list(map(str, input().split()))
	ind = []
	c = 0
	for i in range(len(a)):
		if a[i] == '1':
			ind.append(i)
	for i in range(0, len(ind) - 1):
		c += ind[i + 1] - ind[i] - 1
	ans.append(c)
for i in ans:
	print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(n):
		if l[i] == 1:
			st = i
			break
	for i in range(n - 1, -1, -1):
		if l[i] == 1:
			en = i
			break
	count = 0
	for i in range(st, en):
		if l[i] == 0:
			count += 1
	print(count)


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		ans = 0
		l = -1
		while a[l + 1] != 1 and l < n - 1:
			l += 1
		l += 1
		r = n
		while a[r - 1] != 1 and r > 0:
			r -= 1
		r -= 1
		if a[r] == 1 and a[l] == 1:
			for i in range(l, r):
				if a[i] == 0:
					ans += 1
		print(ans)
main()


import math
t = int(input())
for k1 in range(t):
	n = int(input())
	nums = list(map(int, input().rstrip().split()))
	l = 0
	r = 0
	total = 0
	con1 = True
	for i in range(len(nums)):
		if nums[i] == 1 and con1:
			l = i
			con1 = False
		if nums[i] == 1:
			r = i
	for j in range(l, r + 1):
		if nums[j] == 0:
			total += 1
	print(total)


from sys import stdin
nii = lambda : map(int, stdin.readline().split())
lnii = lambda : list(map(int, stdin.readline().split()))
t = int(input())
for i in range(t):
	n = int(input())
	a = lnii()
	ans = 0
	inx = -1
	for i in range(n):
		if a[i] == 1 and inx == -1:
			inx = i
		elif a[i] == 1:
			ans += i - inx - 1
			inx = i
	print(ans)


def median(sortedArray):
	n = len(sortedArray)
	if n % 2 == 0:
		return sortedArray[n // 2 - 1]
	else:
		return sortedArray[n // 2]
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	books = [i for i in range(n) if a[i]]
	med = median(books)
	dist = [i - med for i in books]
	total = sum([abs(dist[i] - dist[i + 1]) - 1 for i in range(len(books) - 1)])
	print(total)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(input().split())
	s = ''
	for i in range(n):
		s += a[i]
	s = s.strip('0')
	print(s.count('0'))


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2, floor
from bisect import bisect_right, bisect_left, bisect
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def sumDigits(no):
	return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
MOD = 1000000007
PMOD = 998244353
N = 10 ** 9 + 7
LOGN = 30
T = 1
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	ix = []
	for i in range(n):
		if a[i] == 1:
			ix.append(i + 1)
	ans = 0
	for i in range(len(ix) - 1):
		ans += ix[i + 1] - ix[i] - 1
	print(ans)


import sys
import math
import time
from functools import lru_cache
from collections import Counter
import heapq

def Update(X, AX, BX, CX, DX, k, n):
	for i in range(k, n):
		tem = (AX * X[i - 2] + BX * X[i - 1] + CX) % DX + 1
		X.append(tem)
try:
	for _ in range(int(input())):
		na = int(input())
		art = [int(i) for i in input().split()]
		tptr = 0
		cptr = na - 1
		while tptr < na - 1:
			if art[tptr] == 1:
				break
			tptr += 1
		while cptr > tptr:
			if art[cptr] == 1:
				break
			cptr -= 1
		ns = 0
		for i in range(tptr, cptr):
			if art[i] == 0:
				ns += 1
		print(ns)
except EOFError as e:
	print(e)


def solve(n):
	first = -1
	last = 0
	c = 0
	for i in range(n):
		if a[i] == 1:
			last = i
			if first == -1:
				first = i
			c += 1
	return last - first - c + 1
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n))


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
t = sInt()
for _ in range(t):
	n = sInt()
	a = lInt()
	c1 = a.count(1)
	f = a.index(1) + 1
	ans = 0
	c1 -= 1
	while f < n and c1 > 0:
		if a[f] == 0:
			ans += 1
		else:
			c1 -= 1
		f += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	l = s.index(1)
	r = n - s[::-1].index(1)
	ans = 0
	for i in range(l, r):
		ans += 1 - s[i]
	print(ans)


for _ in range(int(input())):
	no_of_books = int(input())
	books = list(map(int, input().split()))
	if 1 in books:
		first = books.index(1)
		last = no_of_books - books[::-1].index(1) - 1
		print(len([i for i in range(first + 1, last) if books[i] == 0]))
	else:
		print(0)


import math
t = int(input())
for tt in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	i = 0
	while i < len(arr) and arr[i] == 0:
		i += 1
	j = n - 1
	while j >= 0 and arr[j] == 0:
		j -= 1
	if i > j:
		print(0)
		continue
	ans = 0
	for ii in range(i, j + 1):
		if arr[ii] == 0:
			ans += 1
	print(ans)


from collections import *
from functools import *
import math
import sys
inp = sys.stdin.readline
out = sys.stdout.write

def mi():
	return map(int, inp().split())

def li():
	return list(mi())

def ii():
	return int(inp())

def main():
	for _ in range(ii()):
		n = ii()
		a = li()
		ans = 0
		prev = -1
		for i in range(n):
			if a[i] == 1:
				if prev == -1:
					prev = i
				else:
					ans += i - prev - 1
					prev = i
		print(ans)
main()


t = int(input())
for _ in range(t):
	length = int(input())
	n = ''.join(input().split())
	red_zeros = 0
	for i in range(0, len(n)):
		if n[i] == '0':
			red_zeros += 1
		else:
			break
	for j in range(len(n) - 1, -1, -1):
		if n[j] == '0':
			red_zeros += 1
		else:
			break
	print(n.count('0') - red_zeros)


for __ in range(int(input())):
	n = int(input())
	a = list(map(str, input().split()))
	ar = ''.join(a)
	a = ar.split('1')
	ans = 0
	for i in range(len(a)):
		g = a[i]
		if g != '':
			ans += len(g)
	if ar[0] != '1':
		ans -= len(a[0])
	if ar[-1] != '1':
		ans -= len(a[-1])
	print(ans)


(z, zz) = (input, lambda : list(map(int, z().split())))
fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = 1
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = 1
num = int(z())
for _ in range(num):
	n = int(z())
	arr = zzz()
	ans = 0
	l = 0
	r = n - 1
	d = 0
	c = 0
	while l <= r:
		if arr[l] == 0 and c == 0:
			l += 1
		else:
			c = 1
		if arr[r] == 0 and d == 0:
			r -= 1
		else:
			d = 1
		if d + c == 2:
			break
	ans = 0
	for i in range(l, r + 1):
		if arr[i] == 0:
			ans += 1
	print(ans)


def solve():
	n = int(input())
	l = list(map(int, input().split()))
	if l.count(1) == 1:
		print(0)
	else:
		a = [i for i in range(len(l)) if l[i] == 1]
		x = l[a[0]:a[-1] + 1].count(0)
		l.reverse()
		b = [i for i in range(len(l)) if l[i] == 1]
		y = l[b[0]:b[-1] + 1].count(0)
		print(min(x, y))
for t in range(int(input())):
	solve()


t = int(input())
while t:
	n = int(input())
	s = input()
	s = s.replace(' ', '')
	s = s.strip('0')
	ans = s.count('0')
	print(ans)
	t -= 1


import collections
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = {1: 0}
	for j in a:
		if j == 1:
			b[1] += 1
	if b[1] == 1:
		print(0)
		continue
	index = a.index(1)
	c = 0
	k = a[::-1]
	lastindex = k.index(1)
	for i in range(index + 1, len(a) - lastindex - 1):
		if a[i] == 0:
			c += 1
		else:
			continue
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	while a[i] != 1:
		i += 1
	j = len(a) - 1
	while a[j] != 1:
		j -= 1
	new_a = a[i:j + 1]
	c = 0
	for i in new_a:
		if i == 0:
			c += 1
	print(c)


from sys import stdin, stdout

def read_input():
	lines = []
	for line in stdin:
		if 'exit' == line.lower().rstrip():
			break
		lines.append(line.rstrip())
	return lines

def write(s):
	stdout.write(str(s) + '\n')

def finish():
	stdout.flush()
lines = read_input()
t = int(lines[0])
for case in range(1, 2 * t + 1, 2):
	n = int(lines[case])
	a = [int(x) for x in lines[case + 1].split()]
	seen_one = False
	count = 0
	last_one = -1
	for (i, num) in enumerate(a):
		if seen_one and num == 0:
			count += 1
		if num == 1:
			seen_one = True
			last_one = i
	extras = len(a) - (last_one + 1)
	write(count - extras)
finish()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = f = ans = 0
	if l.count(1) == 1:
		print('0')
	else:
		for i in l:
			if i == 1 and f == 0:
				f = 1
			elif i == 1 and f == 1:
				ans += c
				c = 0
			elif i == 0 and f == 1:
				c += 1
		print(ans)


tsts = int(input())
for tst in range(tsts):
	ln = int(input())
	bks = list(map(int, input().split(' ')))
	fst = 0
	lst = 0
	stps = 0
	for i in range(ln):
		if bks[i] == 1:
			fst = i
			break
	for j in range(ln - 1, -1, -1):
		if bks[j] == 1:
			lst = j
			break
	if fst == lst:
		print(stps)
	else:
		for k in range(fst, lst):
			if bks[k] == 0:
				stps += 1
		print(stps)


def solve(arr, n):
	first_occ = 0
	last_occ = n - 1
	total_occ = sum(arr)
	for i in range(n):
		if arr[i] == 1:
			first_occ = i
			break
	for i in range(n - 1, -1, -1):
		if arr[i] == 1:
			last_occ = i
			break
	return last_occ - first_occ + 1 - total_occ

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		arr = [int(a) for a in input().split()]
		assert len(arr) == n
		output = solve(arr, n)
		print(output)
main()


from sys import stdin
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	arr = [int(x) for x in stdin.readline().strip().split(' ')]
	count = 0
	first = False
	zeroes = 0
	last_one = -1
	total_zeroes = 0
	for (idx, val) in enumerate(arr):
		if val == 1 and (not first):
			first = True
			last_one = idx
		if last_one != -1 and last_one != idx and (val == 1):
			total_zeroes += zeroes
			zeroes = 0
		if first:
			if val == 1:
				count += 1
				last_one = idx
			else:
				zeroes += 1
	if count <= 1:
		print(0)
	else:
		print(total_zeroes)


a = int(input())

def my_sort(a1):
	while a1[0] == '0' or a1[-1] == '0':
		if a1[0] == '0':
			del a1[0]
		if a1[-1] == '0':
			del a1[-1]
	return a1
for i in range(a):
	n = int(input())
	values = input()
	val1 = values.split()
	val = my_sort(val1)
	print(val.count('0'))


tc = int(input())
for t in range(tc):
	n = int(input())
	ans = input().lstrip('0 ').rstrip(' 0')
	print(ans.count('0'))


for i in range(int(input())):
	n = int(input())
	a = input().split()
	(cnt, quantity) = (0, 0)
	if a.count(str(1)) == 1:
		print(0)
		continue
	else:
		for j in range(a.index(str(1)), len(a)):
			if int(a[j]) == 1:
				cnt += 1
				if cnt == a.count(str(1)):
					break
			else:
				quantity += 1
	print(quantity)


a = int(input())
for q in range(a):
	b = int(input())
	c = input()
	q = c.index('1')
	n = c.rfind('1')
	c = c[q:n]
	s = 0
	for i in range(len(c)):
		if c[i] == '0':
			s = s + 1
	print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	left = -1
	right = -1
	for i in range(n):
		if a[i] == 1:
			left = i
			break
	if left == -1:
		print(0)
		continue
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			right = i
			break
	count1 = 0
	for i in range(n):
		if a[i] == 1:
			count1 += 1
	print(right - left - count1 + 1)


def solve(array):
	toggle = counter = 0
	while True:
		if len(array) == 0:
			break
		if array[-1] == '0':
			array.pop()
		else:
			break
	for i in range(len(array)):
		if toggle == 1:
			if array[i] == '0':
				counter += 1
		if array[i] == '1':
			toggle = 1
	print(counter)
num = int(input())
for i in range(num):
	j = int(input())
	lst = input().split(' ')
	solve(lst)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr = arr[arr.index(1):]
	arr.reverse()
	arr = arr[arr.index(1):]
	arr.reverse()
	ans = 0
	for i in range(len(arr) - 1):
		if arr[i] == 1 and arr[i + 1] == 0:
			arr[i + 1] = 1
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(val) for val in input().split(' ')]
	arr_idx = [idx for (idx, val) in enumerate(arr) if val]
	c = 0
	for i in range(len(arr_idx) - 1):
		c += arr_idx[i + 1] - arr_idx[i] - 1
	print(c)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RS():
	return input()

def RN():
	return int(input())

def RM():
	return map(int, input().split())

def RL():
	return list(map(int, input().split()))
for _ in range(RN()):
	n = RN()
	ls = RL()
	f = False
	(l, r) = (-1, -1)
	for i in range(n):
		if ls[i]:
			l = i
			break
	for i in range(n - 1, -1, -1):
		if ls[i]:
			r = i
			break
	cnt = 0
	for i in range(l, r + 1):
		cnt += int(ls[i] == 0)
	print(cnt)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	for i in range(len(a)):
		if a[i] == 1:
			b.append(i)
	if len(b) == 1:
		print(0)
	else:
		count = 0
		for i in range(1, len(b)):
			count += b[i] - b[i - 1] - 1
		print(count)


for ___ in range(int(input())):
	x = int(input())
	a = [int(i) for i in input().split()]
	n = a.count(1)
	start = False
	ans = 0
	for i in a:
		if i == 1:
			start = True
			n -= 1
		elif start and n > 0:
			ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	gaps = []
	count = 0
	if arr[0] == 0:
		count += 1
	for i in range(1, len(arr)):
		if arr[i] == 0:
			count += 1
		if arr[i] == 1 and arr[i - 1] == 0:
			gaps.append(count)
			count = 0
	if arr[0] == 0:
		gaps.pop(0)
	ans = sum(gaps)
	print(ans)


import sys, io, os, time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
for ii in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr.count(1) == 1 or arr.count == 0:
		print(0)
		continue
	start = 0
	end = n - 1
	while start < n and arr[start] == 0:
		start += 1
	while end >= 0 and arr[end] == 0:
		end -= 1
	ans = 0
	for i in range(start, end + 1):
		ans += arr[i] == 0
	print(ans)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(c, a) = (0, 0)
	flag = 0
	for i in range(n):
		if l[i] == 1 and flag == 0:
			flag = 1
			a = 0
		elif l[i] == 0 and flag == 1:
			a += 1
		elif l[i] == 1 and flag == 1:
			c += a
			a = 0
	print(c)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	k = l.index(1)
	p = 0
	for i in range(len(l) - 1, -1, -1):
		if l[i] == 1:
			p = i
			break
	if p == k:
		print(0)
	else:
		c = 0
		for i in range(k, p + 1):
			if l[i] == 0:
				c += 1
		print(c)


t = int(input())
while t > 0:
	n = int(input())
	arr = []
	arr = [int(item) for item in input().split()]
	zero = 0
	flag = -1
	for i in range(len(arr)):
		if arr[i] == 1:
			flag = i
		elif flag != -1 and arr[i] == 0:
			zero = zero + 1
	ans = zero - (len(arr) - flag - 1)
	print(ans)
	t = t - 1


import math
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(100000)

def put():
	return map(int, stdin.readline().split())
for _ in range(int(input())):
	n = int(input())
	s = input()
	s = s.replace(' ', '')
	ind = s.find('1')
	s = s[ind:]
	s = s[-1::-1]
	ind = s.find('1')
	s = s[ind:]
	s = s[-1::-1]
	ans = 0
	for i in s:
		if i == '0':
			ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	p = list1.index(1)
	list1.reverse()
	q = list1.index(1)
	q = n - q
	if p - q == 0:
		print(0)
	else:
		print(q - p - list1.count(1))


import sys, os.path

def mod():
	return 1000000007

def ii():
	return int(sys.stdin.readline())

def si():
	return sys.stdin.readline().strip()

def li():
	return list(sys.stdin.readline().strip())

def mii():
	return map(int, sys.stdin.readline().split())

def lii():
	return list(map(int, sys.stdin.readline().strip().split()))
for i in range(ii()):
	n = ii()
	s = si()
	s = s.replace(' ', '')
	s = s.strip('0')
	while s.count('11') != 0:
		s = s.replace('11', '1')
	print(s.count('0'))


x = int(input())
for i in range(0, x):
	n = int(input())
	m = list(map(int, input().split()))[:n]
	ar = []
	for j in range(0, n):
		if m[j] == 1:
			ar.append(j)
	s = 0
	for k in range(1, len(ar)):
		s = s + abs(ar[k] - ar[k - 1] - 1)
	print(s)


for i in range(int(input())):
	n = int(input())
	lis = [int(x) for x in input().split()]
	ans = 0
	count = 0
	for i in lis[lis.index(1):]:
		if i == 1:
			ans = count
		else:
			count += 1
	print(ans)


t = int(input())
while t:
	cnt = 0
	n = int(input())
	s = ''.join(input().split()[:n])
	for i in range(s.find('1'), s.rfind('1')):
		if s[i] == '0':
			cnt += 1
	print(cnt)
	t -= 1


t = int(input())
for i in range(t):
	n = input()
	l = [int(x) for x in input().split()]
	(s1, s2) = (0, 0)
	for i in range(len(l)):
		if l[i] == 1:
			s1 = i
			break
	for i in range(len(l) - 1, -1, -1):
		if l[i] == 1:
			s2 = i
			break
	if s1 == s2:
		print(0)
	else:
		s = 0
		for i in range(s1, s2):
			if l[i] == 0:
				s += 1
		print(s)


t = int(input())
for i in range(t):
	n = int(input())
	l = input()
	L = l.split()
	for i in range(n):
		L[i] = int(L[i])
	first = L.index(1)
	L.reverse()
	s = 0
	last = n - 1 - L.index(1)
	L.reverse()
	for i in range(first, last):
		if L[i] == 0:
			s += 1
	print(s)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	fs = []
	for i in range(len(arr)):
		if arr[i] == 1:
			fs.append(i)
	count = 0
	for i in range(fs[0], fs[-1]):
		if arr[i] == 0:
			count += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 0
	i = 0
	while i < n and a[i] != 1:
		i += 1
	p = n - 1
	while p >= 0 and a[p] != 1:
		p -= 1
	for j in range(i + 1, p):
		if a[j] == 0:
			cnt += 1
	print(cnt)


t = int(input())
for j in range(t):
	n = int(input())
	d = str(input())
	sub = d[d.index('1'):d.rfind('1')].split(' ')
	cnt = 0
	for i in sub:
		if i == '0':
			cnt += 1
	print(cnt)


t = int(input())
for j in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = a[a.index(1):len(a)]
	c = 0
	for i in b[::-1]:
		if i == 0:
			c += 1
		elif i == 1:
			break
	b = b[::-1]
	b = b[c:len(b)]
	print(b.count(0))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	i = a.index(1)
	j = len(a) - 1 - list(reversed(a)).index(1)
	print(a[i:j + 1].count(0))


t = int(input())
for i in range(t):
	n = int(input())
	lst = [int(i) for i in input().split()]
	stack = []
	total = 0
	count = 0
	for i in range(len(lst)):
		if lst[i] == 1:
			stack.append(1)
			if stack:
				total = total + count
				count = 0
		elif stack:
			count = count + 1
	print(total)


for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(status, sum, count) = (0, 0, 0)
	for i in a:
		if i == 1 and (not status):
			status = 1
		elif status and i == 0:
			count += 1
		elif i == 1 and status:
			sum += count
			count = 0
	print(sum)


q = int(input())
for _ in range(q):
	n = int(input())
	arr = [int(x) for x in input().split()]
	quantity = 0
	t = arr.count(1)
	ones = 0
	b = False
	for i in arr:
		if i == 0 and b and (ones != t):
			quantity += 1
		elif i == 1:
			ones += 1
			b = True
	print(quantity)


import re

def count(arr):
	allmatch = re.findall('0+', arr)
	if arr[0] == '0':
		allmatch.pop(0)
	if allmatch and arr[len(arr) - 1] == '0':
		allmatch.pop()
	ans = 0
	for i in range(len(allmatch)):
		ans += len(allmatch[i])
	return ans
for i in range(int(input())):
	n = int(input())
	a = ''.join([str(x) for x in input().split()])
	ans = min(count(a), count(a[::-1]))
	print(ans)


import sys
t = int(input())
for tc in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = count_begin = count_end = 0
	for i in range(n):
		if a[i] == 1:
			count_begin = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			count_end = i
			break
	for i in range(count_begin, count_end):
		if a[i] == 0:
			ans += 1
	print(ans)


tc = int(input())
for k in range(tc):
	N = int(input())
	A = input().replace(' ', '')
	A = A.strip('0')
	print(A.count('0'))


t = int(input())
for i in range(t):
	n = int(input())
	L = list(map(int, input().split()))
	a = b = 0
	c = L.count(1)
	for i in L:
		if i == 1:
			a = a + 1
		elif i == 0 and a > 0 and (a < c):
			b = b + 1
	print(b)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = 0
	for i in range(n):
		if a[i] == 1:
			k = i
			break
	for j in range(n - 1, -1, -1):
		if a[j] == 1:
			l = j
			break
	if l == 0:
		print(0)
	else:
		c = 0
		for m in range(k, l + 1):
			if a[m] == 0:
				c += 1
		print(c)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	k = 0
	l = True
	r = True
	for i in range(0, len(a)):
		if l:
			if a[i]:
				l = False
			else:
				k += 1
		if r:
			if a[len(a) - 1 - i]:
				r = False
			else:
				k += 1
		if r == False and l == False:
			break
	print(len(a) - k - sum(a))


import sys, math, collections, itertools
from collections import defaultdict
from functools import reduce

def file():
	sys.stdin = open('input.py', 'r')
	sys.stdout = open('output.py', 'w')

def get_array():
	l = list(map(int, input().split()))
	return l

def get_ints():
	return map(int, input().split())

def sod(n):
	(n, c) = (str(n), 0)
	for i in n:
		c += int(i)
	return c

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def getFloor(A, x):
	(left, right) = (0, len(A) - 1)
	floor = -1
	while left <= right:
		mid = (left + right) // 2
		if A[mid] == x:
			return A[mid]
		elif x < A[mid]:
			right = mid - 1
		else:
			floor = A[mid]
			left = mid + 1
	return floor

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def chk_power_of_2(n):
	return n & n - 1 == 0

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def main():
	for tt in range(int(input())):
		n = int(input())
		l = get_array()
		c = 0
		for i in range(n):
			if l[i] == 1:
				for j in range(i + 1, n):
					if l[j] == 1:
						c += j - i - 1
						break
		print(c)
main()


t = int(input())
while t:
	n = int(input())
	l = []
	l = list(map(int, input().split()))
	g = 0
	s = l.count(1)
	if s > 1:
		for i in range(n):
			if l[i] == 1:
				p = i
				break
		for i in range(n - 1, -1, -1):
			if l[i] == 1:
				pp = i
				break
		ss = l[p:pp + 1]
		z = ss.count(0)
		print(z)
	elif s <= 1:
		print(0)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	flag = 0
	ans = n
	ans -= a.count(1)
	i = n - 1
	while i >= 0 and a[i] == 0:
		ans -= 1
		a.pop()
		n -= 1
		i -= 1
	i = 0
	while i < n and a[i] == 0:
		ans -= 1
		i += 1
	print(ans)


def f(arr):
	l = 0
	while arr[l] == 0:
		l += 1
	r = len(arr) - 1
	while arr[r] == 0:
		r -= 1
	c = 0
	for i in range(l, r):
		if arr[i] == 0:
			c += 1
	return c
for _ in range(int(input())):
	int(input())
	print(f(list(map(int, input().split()))))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	f = 0
	l = 0
	r = 0
	rc = 0
	for i in a:
		if i == 0 and f == 0:
			rc += 1
		if i == 1 and f == 0:
			l = 0
			f = 1
		if i == 0 and f == 1:
			l += 1
	f = 0
	lc = 0
	for i in a[::-1]:
		if i == 0 and f == 0:
			lc += 0
		if i == 1 and f == 0:
			r = 0
			f = 1
		if i == 0 and f == 1:
			r += 1
	print(min(l - lc, r - rc))


def solve(n, a):
	onepresent = False
	cntone = 0
	onekapehlaindex = 0
	onekalastindex = 0
	for i in range(n):
		if a[i] == 1:
			if onepresent == False:
				onekapehlaindex = i
			onepresent = True
			cntone += 1
			if onepresent:
				onekalastindex = i
	if onepresent == False or cntone == 1:
		return 0
	if cntone > 1:
		cntzero = 0
		for i in range(onekapehlaindex, onekalastindex):
			if a[i] == 0:
				cntzero += 1
		return cntzero
noOfTestCases = int(input())
a = [1, 11, 111, 1111, 2, 22, 222, 2222, 3, 33, 333, 3333, 4, 44, 444, 4444, 5, 55, 555, 5555, 6, 66, 666, 6666, 7, 77, 777, 7777, 8, 88, 888, 8888, 9, 99, 999, 9999]
for i in range(noOfTestCases):
	n = int(input())
	a = list(map(int, input().split()))
	ans = solve(n, a)
	print(ans)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	s = input().split()
	n = len(s)
	p1 = n + 1
	p2 = -1
	for i in range(n):
		if s[i] == '1':
			p1 = min(p1, i)
			p2 = max(p2, i)
	s1 = ''.join(s[p1:p2 + 1])
	l = s1.split('1')
	print(sum((len(ss) for ss in l)))


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	l = a.index(1)
	r = n - a[::-1].index(1)
	a = a[l:r]
	print(a.count(0))


def solve(n, arr):
	start = 0
	end = 0
	count = 0
	for i in range(len(arr)):
		if arr[i] == 1:
			start = i
			break
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] == 1:
			end = i
			break
	for i in range(start, end):
		if arr[i] == 0:
			count += 1
	return count
for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve(n, arr))


def solve(L):
	SL = list()
	first = True
	for l in L:
		if l == 0 and first:
			continue
		elif l == 0 and (not first):
			SL.append(l)
		elif l == 1 and first:
			SL.append(l)
			first = False
		elif l == 1 and (not first):
			if SL[-1] != 1:
				SL.append(1)
	while SL[-1] == 0:
		SL.pop()
	result = 0
	start_pos = 1
	while start_pos < len(SL):
		count = 1
		while start_pos + count < len(SL) and SL[start_pos + count] != 1:
			count += 1
		result += count
		start_pos += count + 1
	return result
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(a))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	m2 = -1
	m1 = 2 ** 32
	for i in range(n):
		if l[i] == 1:
			m1 = min(c, m1)
			m2 = max(c, m2)
		c += 1
	k = l[m1:m2 + 1]
	ans = k.count(0)
	print(ans)


n = int(input())
for i in range(n):
	a = int(input())
	s = [int(i) for i in input().split(' ')]
	j = 0
	while s[j] == 0:
		j += 1
	b = a - 1
	while s[b] == 0:
		b -= 1
	count = 0
	for k in range(j, b):
		if s[k] == 0:
			count += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = [int(t) for t in input().split()]
	one_indexes = [i for (i, a_i) in enumerate(a) if a_i == 1]
	print(sum((one_indexes[i] - one_indexes[i - 1] - 1 for i in range(1, len(one_indexes)))))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	for i in range(n):
		if arr[i] == 1:
			first = i
			break
	i = first
	gap = 0
	while i < n - 1:
		if arr[i + 1] == 0:
			gap += 1
			i += 1
		else:
			i += 1
	tail = 0
	for i in range(n - 1, 0, -1):
		if arr[i] == 0:
			tail += 1
		else:
			break
	print(gap - tail)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
sys.setrecursionlimit(10 ** 6)
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def valid(row, col, rows, cols, rcross, lcross):
	return rows[row] == 0 and cols[col] == 0 and (rcross[col + row] == 0) and (lcross[col - row] == 0)

def main():
	ans = ''
	for _ in range(ii()):
		n = ii()
		arr = li()
		i = 0
		cnt = 0
		while i < n:
			if arr[i] == 1:
				break
			i += 1
		j = i + 1
		while j < n:
			if arr[j] == 1:
				cnt += j - i - 1
				i = j
			j += 1
		ans += str(cnt) + '\n'
	print(ans)
main()


t = int(input())
for q in range(t):
	n = int(input())
	c = input()
	c = c.replace(' ', '')
	l = c.find('1')
	r = c.rfind('1')
	c = c[l:r + 1]
	c = c.replace('', ' ')
	a = list(map(int, c.split()))
	print(a.count(0))


from sys import stdin
t = int(stdin.readline())
for i in range(t):
	n = int(stdin.readline())
	bookshelf = list(map(int, stdin.readline().split()))
	ptr = 0
	ans = 0
	tmp = 0
	while not bookshelf[ptr]:
		ptr += 1
	while ptr < n:
		if bookshelf[ptr] == 0:
			tmp += 1
		else:
			ans += tmp
			tmp = 0
		ptr += 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(str, input().split()))
	first = [index for (index, char) in enumerate(a) if char == '1']
	count = 0
	for j in range(len(first) - 1):
		count += abs(first[j] - first[j + 1]) - 1
	print(count)


for test in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	m = []
	for (i, j) in enumerate(arr):
		if j == 1:
			m.append(i)
	count = 0
	for i in range(m[0] + 1, m[-1]):
		if arr[i] == 0:
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	books = [int(i) for i in input().split()]
	idx = 0
	start = False
	chainSum = 0
	total = 0
	while idx < n:
		if not start and books[idx]:
			start = True
		if start:
			if books[idx]:
				total += chainSum
				chainSum = 0
			else:
				chainSum += 1
		idx += 1
	print(total)


n = int(input())
lis = []
sol = []
for i in range(n):
	length = int(input())
	lis.append(input().split())
for shelf in lis:
	for i in range(len(shelf)):
		shelf[i] = int(shelf[i])
	while shelf[0] == 0:
		shelf.pop(0)
	while shelf[-1] == 0:
		shelf.pop(-1)
for shelf in lis:
	sol.append(shelf.count(0))
for ans in sol:
	print(ans)


for _ in range(int(input())):
	n = int(input())
	li = []
	a = list(map(int, input().strip().split(' ')))
	for i in range(n):
		if a[i] == 1:
			li.append(i)
	try:
		print(a[min(li):max(li)].count(0))
	except:
		print('0')


t = int(input())
while t != 0:
	t -= 1
	ans = 10
	n = int(input())
	zer = 0
	flag = 0
	ans = 0
	li = list(map(int, input().split()))
	for i in range(n):
		if flag == 1:
			if li[i] == 0:
				zer += 1
			else:
				ans += zer
				zer = 0
		elif li[i] == 1:
			flag = 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = [int(num) for num in input().split(' ')]
	ans = 0
	f = 0
	i = 0
	while i < n:
		if arr[i] == 1:
			j = i
			f = 1
			while j < n and arr[j] != 1:
				j = j + 1
			i = j + 1
		elif arr[i] == 0 and f == 1:
			ans = ans + 1
			i = i + 1
		elif arr[i] == 0 and f == 0:
			i = i + 1
	a = 0
	if arr[-1] == 0:
		i = n - 1
		a = 0
		while i >= 0:
			if arr[i] == 1:
				a = i
				break
			i = i - 1
		print(ans - n + 1 + a)
	else:
		print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] == 1:
			break
	for j in range(n - 1, -1, -1):
		if a[j] == 1:
			break
	print(j - i + 1 - a.count(1))


def bookshelf(arr, n):
	count_1 = arr.count(1)
	counting = 0
	index1 = []
	for i in range(0, n):
		if arr[i] == 1:
			index1.append(i)
	mn1 = min(index1)
	mx1 = max(index1)
	count = 0
	for j in range(mn1, mx1):
		if arr[j] == 0:
			count += 1
	return count
for i in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	print(bookshelf(arr, n))


testcases = int(input())
for testcase in range(testcases):
	n = int(input())
	temparr = input()
	temparr = temparr.split()
	arr = []
	for i in temparr:
		arr.append(int(i))
	flag = 0
	prev1 = -1
	ans = 0
	for i in range(n):
		if arr[i] == 1 and flag == 0:
			flag = 1
			prev1 = i
		elif arr[i] == 1 and flag == 1 and (i - prev1 == 1):
			prev1 = i
		elif arr[i] == 1 and flag == 1 and (i - prev1 > 1):
			ans += i - prev1 - 1
			prev1 = i
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = []
	flag = False
	s = 0
	for i in range(n):
		if a[i] == 0:
			if flag:
				l.append((s, i - 1))
				flag = False
			continue
		if flag:
			continue
		else:
			flag = True
			s = i
	if flag:
		l.append((s, n - 1))
	ans = 99999999999999999
	for i in range(0, 1):
		diff = 0
		diff1 = 0
		diff2 = 0
		for j in range(i - 1, -1, -1):
			diff1 = diff1 + l[j + 1][0] - l[j][1] - 1
		for j in range(i + 1, len(l)):
			diff2 = diff2 + l[j][0] - l[j - 1][1] - 1
		ans = min(ans, diff1 + diff2)
	print(ans)


for _ in range(int(input())):
	size = int(input())
	arr = list(map(int, input().split()))
	gaps = 0
	temp = 0
	flag = False
	for c in arr:
		if flag == False and c == 1:
			flag = True
		if flag == True and c == 0:
			temp += 1
		if flag == True and c == 1:
			gaps += temp
			temp = 0
	print(gaps)


t = int(input())
for test in range(t):
	n = int(input())
	s = ''.join(input().split())
	z = 0
	for i in range(len(s)):
		if s[i] == '1':
			first_one = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			last_one = i
			break
	for i in s[first_one:last_one]:
		if i == '0':
			z += 1
	print(z)


import io, os, math
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
rr = lambda : input()
rri = lambda : int(input())
rrm = lambda : list(map(int, input().split()))
INF = float('inf')

def solve(N, A):
	shift = 0
	zeroes = 0
	started = False
	for v in A:
		if v == 1:
			if started:
				shift += zeroes
			else:
				started = True
			zeroes = 0
		else:
			zeroes += 1
	return shift
t = rri()
for _ in range(t):
	N = rri()
	A = rrm()
	print(solve(N, A))


t = int(input())
for tc in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(l, r) = (min((i for i in range(n) if a[i] == 1)), max((i for i in range(n) if a[i] == 1)))
	cnt = sum(a)
	print(r - l + 1 - cnt)


import os, sys
from collections import defaultdict, Counter
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		a = [int(x) for x in input().split()]
		x = []
		an = 0
		flag = False
		for i in range(n):
			if not flag:
				if a[i] == 1:
					flag = True
			elif a[i] == 1 and a[i - 1] == 0:
				x.append(an)
				an = 0
			elif a[i] == 0:
				an += 1
		print(sum(x))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for i in range(t):
	n = int(input())
	l = input().split()
	l2 = [int(i2) for i2 in l]
	ip = 0
	c = 0
	op = 0
	s = 0
	while 1 in l2:
		ip = l2.index(1)
		l2[ip] = 0
		c = c + 1
		if c > 1:
			s = s + (ip - op - 1)
		op = ip
	print(s)


while True:
	try:
		t = eval(input())
		for i in range(t):
			n = eval(input())
			list0 = list(map(int, input().split()))
			if sum(list0) == 1:
				print(0)
			else:
				cnt = 0
				while list0[0] != 1:
					del list0[0]
				len1 = len(list0) - 1
				while len1 >= 0 and list0[len1] != 1:
					del list0[len1]
					len1 -= 1
				print(len1 + 1 - sum(list0))
	except:
		break


def cnt(A, r, l):
	cnt = 0
	check = 0
	for i in range(l, r):
		if A[i] == 1:
			check = 1
		elif A[i] == 0 and check == 1:
			cnt += 1
	return cnt
t = int(input())
for i in range(t):
	j = 0
	l = -1
	r = -1
	n = int(input())
	A = list(map(int, input().split()))
	while l == -1:
		if A[j] == 1:
			l = j
		j += 1
	j = 0
	while r == -1:
		if A[n - j - 1] == 1:
			r = n - j - 1
		j += 1
	print(cnt(A, r, l))


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		l = list(In())
		l1 = l.copy()
		ans = 100000000.0
		for i in range(n):
			if l[i] == 1:
				temp = 0
				no0 = 0
				for j in range(i - 1, -1, -1):
					if l[j] == 1:
						temp += no0
						no0 = 0
					else:
						no0 += 1
				no0 = 0
				for j in range(i + 1, n):
					if l[j] == 1:
						temp += no0
						no0 = 0
					else:
						no0 += 1
				ans = min(ans, temp)
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


t = int(input())
for p in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	left = 0
	for i in range(n):
		if array[i] == 1:
			left = i
			break
	right = 0
	for i in range(n - 1, left - 1, -1):
		if array[i] == 1:
			right = i
			break
	ans = 0
	for i in range(left, right + 1):
		if array[i] == 0:
			ans += 1
	print(ans)


testCase = int(input())
for case in range(testCase):
	nInput = int(input())
	binaryInput = input().split()
	s = ''.join(binaryInput).strip('0')
	print(s.count('0'))


from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(I()):
	n = I()
	a = LI()
	(b, c) = (0, 0)
	for i in range(0, n):
		if a[i] == 1:
			b = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			c = i
			break
	gaps = 0
	for i in range(b, c):
		if a[i] == 0:
			gaps += 1
	print(gaps)


from sys import stdin
input = stdin.readline
from itertools import groupby

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	cnt = a.count(0)
	(left, right) = (0, 0)
	for i in range(n):
		if a[i] == 0:
			left += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 0:
			right += 1
		else:
			break
	print(max(0, cnt - left - right))
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	i = l.index(1)
	if len(set(l)) == 1:
		print(0)
		continue
	c = 0
	z = 0
	for j in range(i + 1, n):
		if l[j] == 1:
			z += c
			c = 0
			continue
		c += 1
	print(z)


t = int(input())
k = 1
while t > 0:
	t = t - 1
	n = int(input())
	arr = list(map(int, input().split()))
	count = []
	counting = False
	reverse = False
	for i in range(n):
		if arr[i] == 1:
			counting = True
		if counting:
			count.append(arr[i])
	l = len(count)
	var = 0
	for i in range(l):
		if count[l - i - 1] == 0:
			count[l - i - 1] = 'a'
		if count[l - i - 1] == 1:
			break
	ans = 0
	for i in range(l):
		if count[i] == 0:
			ans = ans + 1
	print(ans)


def si():
	return str(input())

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
t = int(input())
for _ in range(t):
	n = ii()
	a = li()
	last = -1
	ans = 0
	for (i, v) in enumerate(a):
		if v == 1:
			if last > -1:
				ans += i - last - 1
			last = i
	print(ans)


import sys
LI = lambda : list(map(int, sys.stdin.readline().strip('\n').split()))
MI = lambda : map(int, sys.stdin.readline().strip('\n').split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline().strip('\n'))
for _ in range(II()):
	n = II()
	s = LI()
	(l, r) = (0, n - 1)
	while l < n and s[l] == 0:
		l += 1
	while r >= 0 and s[r] == 0:
		r -= 1
	ans = 0
	for i in range(l, r + 1):
		if s[i] == 0:
			ans += 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
import math
import itertools as ITR
from collections import defaultdict as D
from collections import Counter as C
from collections import deque as Q
import threading
from functools import lru_cache, reduce
from functools import cmp_to_key as CMP
from bisect import bisect_left as BL
from bisect import bisect_right as BR
import random as R
import cmath, time
start_time = time.time()
MOD = 1000000007
MA = float('inf')
MI = float('-inf')

def increase_stack():
	sys.setrecursionlimit(2 ** 32 // 2 - 1)
	threading.stack_size(1 << 27)
	t = threading.Thread(target=main)
	t.start()
	t.join()

def prints(a):
	print(a, end='')

def binary(n):
	return bin(n)[2:]

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	l.sort()
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countchar(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def str_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def lis(arr):
	n = len(arr)
	lis = [1] * n
	maximum = 0
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
				maximum = max(maximum, lis[i])
	return maximum

def lcm(arr):
	a = arr[0]
	val = arr[0]
	for i in range(1, len(arr)):
		gcd = gcd(a, arr[i])
		a = arr[i]
		val *= arr[i]
	return val // gcd

def ncr(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

def inint():
	return int(input())

def inarr():
	return list(map(int, input().split()))

def invar():
	return map(int, input().split())

def instr():
	s = input()
	return list(s)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
TestCases = 1

def solve():
	n = inint()
	s = inarr()
	r = -1
	q = -1
	res = 0
	for i in range(n):
		if q == -1 and s[i] == 1:
			q = i
		if s[i] == 1:
			r = i
	for i in range(q, r + 1):
		if s[i] == 0:
			res += 1
	print(res)

def main():
	flag = 0
	try:
		sys.stdin = open('c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/input.txt', 'r')
		sys.stdout = open('c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/output.txt', 'w')
	except:
		flag = 1
	t = 1
	if TestCases:
		t = inint()
	for _ in range(1, t + 1):
		solve()
	if not flag:
		print('Time: %.4f sec' % (time.time() - start_time))
		localtime = time.asctime(time.localtime(time.time()))
		print(localtime)
		sys.stdout.close()
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 10 ** 20
	for i in range(n):
		if arr[i] == 0:
			continue
		cnt = 0
		var = 0
		pos = i - 1
		for j in range(i - 1, -1, -1):
			if arr[j] == 1:
				cnt += abs(j - pos)
				pos = j - 1
		pos = i + 1
		for j in range(i, n):
			if j == i:
				continue
			if arr[j] == 1:
				cnt += abs(j - pos)
				pos = j + 1
		ans = min(ans, cnt)
	print(ans)


tests = int(input())
for test in range(tests):
	total = int(input())
	massiv = [int(num) for num in input().split()]
	while massiv[0] != 1:
		massiv = massiv[1:]
	while massiv[-1] != 1:
		massiv = massiv[:-1]
	answer = massiv.count(0)
	print(answer)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	x = A.index(1)
	A = A[x:]
	while A[-1] == 0:
		A.pop()
	R = [0] * (len(A) + 1)
	L = [0] * (len(A) + 1)
	for i in range(len(A)):
		if A[i] == 0:
			R[i] = R[i - 1] + 1
		else:
			R[i] = R[i - 1]
	for i in range(len(A) - 1, -1, -1):
		if A[i] == 0:
			L[i] = L[i + 1] + 1
		else:
			L[i] = L[i + 1]
	ANS = 1 << 30
	for i in range(len(A)):
		ANS = min(R[i] + L[i], ANS)
	print(ANS)


for test in range(int(input())):
	q = int(input())
	books = list(map(int, input().split()))[:q]
	lng = len(books)
	(first, last) = (None, None)
	for i in range(lng):
		if books[i]:
			first = i
			break
	for i in range(lng - 1, -1, -1):
		if books[i]:
			last = i
			break
	usefull_books = books[first:last + 1]
	cnt = usefull_books.count(0)
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	i = 0
	count = arr.count(0)
	count0 = 0
	while arr[i] == 0:
		count0 += 1
		i += 1
	i = n - 1
	while arr[i] == 0:
		count0 += 1
		i -= 1
	print(count - count0)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	x = 0
	f = 1
	c = 0
	for i in range(n):
		if l[i] == 1:
			if f > 1:
				c += x
				x = 0
			else:
				x = 0
				f += 1
		else:
			x += 1
	print(c)


from typing import List

def solve(n: int, a: List[int]) -> int:
	while a[-1] == 0:
		a.pop()
	while a[0] == 0:
		a.pop(0)
	return sum((1 - _ for _ in a))
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	r = solve(n, a)
	print(r)


t = int(input())
for k in range(t):
	n = int(input())
	lista = list(map(int, input().split()))
	start = False
	totalcount = 0
	count = 0
	for i in range(n):
		if not start:
			if lista[i] == 1:
				start = True
		elif lista[i] == 1:
			totalcount += count
			count = 0
		else:
			count += 1
	print(totalcount)


for i in range(int(input())):
	a = int(input())
	b = input().split(' ')
	for i in range(a):
		b[i] = int(b[i])
	c = 0
	d = 0
	e = 0
	for i in b:
		c = i == 1 or c
		d += int(i == 0 and c)
		e += (d - e) * int(i == 1)
	print(e)


t = int(input())
while t:
	n = int(input())
	arr = input().split()
	i = 0
	j = n - 1
	if arr.count('1') == 1:
		print(0)
	else:
		while i < j:
			if arr[i] == '1' and arr[j] == '1':
				break
			if arr[i] != '1':
				i += 1
			if arr[j] != '1':
				j -= 1
		new = arr[i:j + 1]
		c = new.count('0')
		print(c)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	s = list(map(int, input().split(' ')))
	d = 1
	k = 0
	a = []
	for i in range(0, len(s)):
		if s[i] == 1:
			for j in range(i + 1, len(s)):
				if s[j] != 1:
					k += 1
				else:
					a.append(k)
					k = 0
					break
	print(sum(a))


t = int(input())
for j in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	dic = {}
	aavi_gayo = False
	eknocount = 0
	zeronocount = 0
	for i in a:
		dic[i] = dic.get(i, 0) + 1
	totalcount = dic[1]
	for i in a:
		if i == 1:
			eknocount += 1
			if eknocount == 1:
				aavi_gayo = True
			if eknocount == totalcount:
				aavi_gayo = False
		elif aavi_gayo:
			zeronocount += 1
	print(zeronocount)


t = int(input())
while t > 0:
	n = int(input())
	a = [int(i) for i in input().split()]
	a += [0]
	tot = 0
	i = 0
	while i < n:
		if a[i] == 1 and a[i + 1] == 0:
			i += 1
			po = 0
			f = 0
			while a[i] == 0 and i < n:
				i += 1
				if a[i] == 1:
					f = 1
				po += 1
			if f:
				tot += po
		else:
			i += 1
	print(tot)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	if a.count(1) == 1:
		print(0)
	else:
		s = ''.join(map(str, a))
		s = s.strip('0')
		ans = 0
		for i in range(len(s)):
			if s[i] == '0':
				ans += 1
		print(ans)


n = int(input())
for i in range(n):
	l = input()
	shelf = input()
	l = shelf.find('1')
	r = shelf.rfind('1')
	sum = 0
	if l >= 0 and r >= 0 and (l is not r):
		for i in range(l, r):
			if shelf[i] == '0':
				sum += 1
	print(sum)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	ct = 0
	for i in range(n):
		if a[i] == 0:
			ans += 1
		else:
			ct += 1
	if ct > 1:
		for i in range(n):
			if a[i] == 0:
				ans -= 1
			else:
				break
		for i in range(n):
			if a[-i - 1] == 0:
				ans -= 1
			else:
				break
		print(ans)
	else:
		print(0)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a = a + [0]
	g = []
	if sum(a) == 0:
		print(0)
		continue
	for i in range(n):
		if a[i] == 1:
			u = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			v = i
			break
	print(a[u:v + 1].count(0))


t = int(input())
while t != 0:
	n = int(input())
	list1 = list(map(int, input().split()))
	ans = []
	i = 0
	while i < len(list1):
		p = list1[i]
		if p == 0:
			while i < len(list1) and list1[i] == p:
				i += 1
				ans.append(p)
		else:
			ans.append(p)
			while i < len(list1) and list1[i] == p:
				i += 1
	fa = 0
	flag = 0
	while len(ans) > 0 and ans[-1] == 0:
		ans.pop()
	for i in range(len(ans)):
		if ans[i] == 1:
			flag = 1
		if ans[i] == 0 and flag == 1:
			fa += 1
	print(fa)
	t -= 1


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	n = int(sys.stdin.readline())
	list_num = list(map(int, sys.stdin.readline().split()))
	isThere = 0
	res = 0
	now = 0
	for ai in list_num:
		if ai:
			if isThere:
				res += now
			isThere = 1
			now = 0
		else:
			now += 1
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(i) for i in input().strip('0 ').split(' ')]
	print(len(l) - sum(l))


from collections import defaultdict

def solve(n, a):
	ans = 0
	m = defaultdict(list)
	for i in range(n):
		if a[i] == 1:
			m[a[i]].append(i)
	for v in m.values():
		for i in range(len(v) - 1, 0, -1):
			ans += v[i] - v[i - 1] - 1
	return ans
t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n, a))
	t -= 1


t = int(input())
for r in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	w = []
	c = 0
	for i in range(n):
		if l[i] == 1:
			w.append(i)
	if len(w) == 1:
		c = 0
	else:
		for i in range(len(w) - 1):
			if w[i + 1] - w[i] > 1:
				c += w[i + 1] - w[i] - 1
	print(c)


def solve(n, a):
	cnt = 0
	for i in range(n):
		if a[i] == 1:
			start = i
			break
	for j in reversed(range(n)):
		if a[j] == 1:
			end = j
			break
	if i == j:
		return 0
	else:
		for elem in a[start:end]:
			if elem == 0:
				cnt += 1
	return cnt
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n, a))


l = int(input())
while l:
	p = input()
	n = list(map(int, input().split()))
	su = 0
	f = 0
	y = []
	for i in range(len(n)):
		if n[i] == 1 and f == 1:
			y.append(su)
		elif n[i] == 1 and f == 0:
			f = 1
		elif n[i] == 0 and f == 1:
			su += 1
	y.append(0)
	print(max(y))
	l -= 1


s = input()
t = int(s)
l = [[]] * t
i = 0
for i in range(t):
	n = input()
	a = input().split()
	l[i].append(int(n))
	for j in range(int(n)):
		a[j] = int(a[j])
	l[i].append(a)
l = l[0]

def set(b, x, y, z=0):
	i = x + 1
	while i < y:
		if b[i] == 0:
			z += 1
		i += 1
	return z
for i in range(0, 2 * t, 2):
	u = l[i + 1].index(1)
	l[i + 1].reverse()
	v = l[i + 1].index(1)
	v = l[i] - v
	l[i + 1].reverse()
	print(set(l[i + 1], u, v))


for t in range(int(input())):
	n = int(input())
	a = [j for j in input().split()]
	k = a.count('1')
	if k <= 1:
		print(0)
	else:
		h1 = a.index('1')
		a.reverse()
		h2 = a.index('1')
		print(a[h2:len(a) - h1].count('0'))


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = []
	for i in range(n):
		if a[i] == 1:
			b.append(i)
	mid = b[len(b) // 2]
	ans = 0
	for i in range(len(b) - 1):
		ans += b[i + 1] - b[i] - 1
	print(ans)


import os
from sys import stdin, stdout

def solve(tc):
	n = int(stdin.readline().strip())
	seq = list(map(int, stdin.readline().split()))
	(l, r) = (-1, -1)
	for i in range(n):
		if seq[i] == 1:
			if l < 0:
				l = i
			r = i
	cnt = 0
	for i in range(l, r + 1):
		if seq[i] == 0:
			cnt += 1
	print(cnt)
	return
tcs = 1
tcs = int(stdin.readline().strip())
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


for i in range(int(input())):
	n = input()
	arr = input().split()
	i = ct = 0
	while i + 1 < len(arr):
		if arr[i] == '1' and arr[i + 1] == '0':
			ct2 = 0
			j = 1
			while arr[i + j] == '0':
				ct2 += 1
				j += 1
				if i + j == len(arr):
					ct2 = 0
					break
			ct += ct2
		i += 1
	print(ct)


for _ in range(int(input())):
	n = int(input())
	lst = [int(i) for i in input().split()]
	count = 0
	for i in range(lst.index(1), n - lst[::-1].index(1)):
		if lst[i] == 0:
			count += 1
	print(count)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	m = []
	temp = 0
	curr = 0
	for i in range(n):
		if l[i] == curr:
			temp += 1
		else:
			m.append(temp)
			temp = 1
			curr = l[i]
	ans = 0
	if l[0] == 0 and l[-1] == 0:
		for i in range(2, len(m) - 1, 2):
			ans += m[i]
	else:
		for i in range(2, len(m), 2):
			ans += m[i]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a.count(1) == 1:
		print(0)
	else:
		zeros = 0
		cnt = 0
		ans = False
		for i in range(n):
			if a[i] == 1:
				zeros += cnt
				cnt = 0
				ans = True
			if ans and a[i] == 0:
				cnt += 1
		print(zeros)