You are playing a very popular computer game. The next level consists of $n$ consecutive locations, numbered from $1$ to $n$, each of them containing either land or water. It is known that the first and last locations contain land, and for completing the level you have to move from the first location to the last. Also, if you become inside a location with water, you will die, so you can only move between locations with land.

You can jump between adjacent locations for free, as well as no more than once jump from any location with land $i$ to any location with land $i + x$, spending $x$ coins ($x \geq 0$).

Your task is to spend the minimum possible number of coins to move from the first location to the last one.

Note that this is always possible since both the first and last locations are the land locations.


-----Input-----

There are several test cases in the input data. The first line contains a single integer $t$ ($1 \leq t \leq 100$) — the number of test cases. This is followed by the test cases description.

The first line of each test case contains one integer $n$ ($2 \leq n \leq 100$) — the number of locations.

The second line of the test case contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \leq 1$), where $a_i = 1$ means that the $i$-th location is the location with land, and $a_i = 0$ means that the $i$-th location is the location with water. It is guaranteed that $a_1 = 1$ and $a_n = 1$.


-----Output-----

For each test case print a single integer — the answer to the problem.


-----Examples-----

Input
3
2
1 1
5
1 0 1 0 1
4
1 0 1 1
Output
0
4
2


-----Note-----

In the first test case, it is enough to make one free jump from the first location to the second one, which is also the last one, so the answer is $0$.

In the second test case, the only way to move from the first location to the last one is to jump between them, which will cost $4$ coins.

In the third test case, you can jump from the first location to the third for $2$ coins, and then jump to the fourth location for free, so the answer is $2$. It can be shown that this is the optimal way.

Difficulty: EASY

Solutions:
for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	i = 1
	r = n - 2
	while i <= n - 1:
		if l[i] == 1:
			i += 1
		else:
			break
	while r >= 0:
		if l[r] == 1:
			r -= 1
		else:
			break
	if r - i + 2 <= 0:
		print(0)
	else:
		print(r - i + 2)


def solve():
	input()
	xs = list(map(int, input().split()))
	if 0 not in xs:
		return 0
	return len(xs) - xs[::-1].index(0) - xs.index(0) + 1

def main():
	t = int(input())
	for i in range(t):
		print(solve())
main()


for i in range(int(input())):
	lenn = int(input())
	list1 = list(map(int, input().split()))
	list2 = list1[::-1]
	count1 = 0
	count2 = 0
	for i in list2:
		if i == 0:
			break
		else:
			count1 += 1
	for i in list1:
		if i == 0:
			break
		else:
			count2 += 1
	if list1.count(0) == 0:
		print(0)
	else:
		print(lenn - (count1 + count2) + 1)


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


for s in [*open(0)][2::2]:
	d = len(''.join(s[::2]).strip('1'))
	print(d + (d > 0))


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


for _ in range(int(input())):
	(N, A) = (int(input()), list(map(int, input().split(' '))))
	S = -1
	E = -1
	for i in range(1, N):
		if A[i] == 0:
			S = i - 1
			break
	if S < 0:
		print(0)
	else:
		for i in range(N - 2, 0, -1):
			if A[i] == 0:
				E = i + 1
				break
		print(E - S)


for i in range(int(input())):
	n = int(input())
	a = ''.join(input().split())
	if '0' in a:
		print(a.rfind('0') - a.find('0') + 2)
	else:
		print(0)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	idx1 = idx2 = -1
	for i in range(n):
		if a[i] == 0:
			idx1 = i - 1
			break
	for i in range(n - 1, -1, -1):
		if a[i] == 0:
			idx2 = i + 1
			break
	print(idx2 - idx1)


for _ in range(int(input())):
	n = int(input())
	a = ''.join(input().split())
	if a.count('0') == 0:
		print(0)
	else:
		print(abs(a.index('0') - 1 - a.rfind('0')) + 1)


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


def solve(n, arr):
	first = 0
	last = 0
	for i in range(n):
		if arr[i] == 0:
			if first == 0:
				first = i
			last = i
	if first == 0 and last == 0:
		return 0
	return last + 1 - (first - 1)
from sys import stdin
input = stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	print(solve(n, arr))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	index_of_0 = [i for (i, x) in enumerate(a) if x == 0]
	if len(index_of_0) == 0:
		print(0)
	elif len(index_of_0) == 1:
		print(2)
	else:
		print(index_of_0[-1] - index_of_0[0] + 2)


def main():
	s = []
	t = int(input())
	for test in range(t):
		n = int(input())
		sequence = list(input().split())
		r_i = 0
		r_f = n
		for i in range(n):
			if int(sequence[i]) == 0:
				break
			else:
				r_i += 1
		sequence.reverse()
		for i in range(0, n):
			if int(sequence[i]) == 1:
				r_f = n - i
			else:
				break
		if r_f - r_i > 0:
			s.append(r_f - r_i)
		else:
			s.append(0)
	for ss in s:
		print(ss)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = ''.join(list(input().split()))
	a1 = [i for i in a.split('1') if i != '']
	cnt = 0
	if len(a1) > 1:
		print(a.rfind('0') - a.find('0') + 2)
	elif len(a1) == 1:
		print(len(a1[0]) + 1)
	else:
		print(0)


import sys
import math
for _ in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	l = list(map(int, sys.stdin.readline().split()))
	y = n - 1
	x = 0
	for i in range(1, n - 1):
		if l[i] == 0:
			x = i
			break
	for i in range(n - 2, 0, -1):
		if l[i] == 0:
			y = i
			break
	if y == n - 1 and x == 0:
		print(0)
	else:
		print(y - x + 2)


def task(a):
	n = int(input())
	arr = list(map(int, input().split()))
	(count, i, e) = (0, 0, 0)
	while i < n - 1:
		(n1, n2) = (arr[i], arr[i + 1])
		if n1 == 0 and n2 == 1:
			count += 1
			e = i + 1
		i += 1
	if count == 0:
		print(0)
		return
	else:
		f = 0
		for i in range(n):
			if arr[i] == 0:
				f = i - 1
				break
		print(e - f)
t = int(input())
for a in range(1, t + 1):
	task(a)


def solveA(n, a):
	left = 0
	right = n - 1
	while left < n and a[left] == 1:
		left += 1
	while right >= 0 and a[right] == 1:
		right -= 1
	left -= 1
	right += 1
	if left >= right:
		return 0
	else:
		return right - left
num_tests = int(input().split()[0])
for t in range(num_tests):
	n = int(input())
	a = [int(value) for value in input().split()]
	print(solveA(n, a))


t = int(input())
result = []
for case in range(t):
	Y = int(input())
	n = input().replace(' ', '')
	d = n.split('0')
	g = n.split('1')
	dict1 = {1: [], 0: []}
	for x in d:
		if x:
			dict1[1].append(x)
	for x in g:
		if x:
			dict1[0].append(x)
	if len(dict1[0]) == 0:
		result.append(0)
	elif len(dict1[0]) == 1:
		result.append(1 + len(dict1[0][0]))
	else:
		result.append(n.rfind('0') - n.find('0') + 2)
for x in result:
	print(x)


from sys import stdin
input = stdin.readline

def main():
	for _ in range(int(input())):
		n = int(input())
		loc = input().split()
		first_1 = 0
		last_1 = 0
		for (x, y) in enumerate(loc):
			if y == '0':
				first_1 = x - 1
				break
		for i in range(n - 1, -1, -1):
			if loc[i] == '0':
				last_1 = i + 1
				break
		print(last_1 - first_1)
main()


t = int(input())
result = []
for i1 in range(t):
	n = int(input())
	level = [int(i2) for i2 in input().split()]
	for i3 in range(n):
		if level[i3] == 0:
			left_zero_index = i3
			break
	else:
		result.append(0)
		continue
	for i4 in range(n):
		if level[n - i4 - 1] == 0:
			right_zero_index = n - i4 - 1
			break
	result.append(right_zero_index - left_zero_index + 2)
for i5 in result:
	print(i5)


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


for i in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	l = 0
	r = n - 1
	if sum(a) == n:
		print(0)
	else:
		while a[l] == 1:
			l += 1
		while a[r] == 1:
			r -= 1
		print(r + 1 - (l - 1))


from math import ceil
t = int(input())
for _ in range(t):
	n = int(input())
	lst = input().split()
	i = 0
	while i < n - 1 and lst[i + 1] == '1':
		i += 1
	j = n - 1
	while j > i and lst[j - 1] == '1':
		j -= 1
	print(j - i)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x = False
	start = 0
	end = 0
	flag = False
	for i in range(n):
		if a[i] == 0 and (not x):
			start = i - 1
			while i < n and a[i] != 1:
				i += 1
			end = i
			x = True
		elif a[i] == 0:
			flag = True
			break
	print(end - start if not flag else n - a[::-1].index(0) - start)


class Solution(object):

	def __init__(self, n, gameItems):
		self.n: int = n
		self.gameItems: list = gameItems
		self.exist: int = -1
		self.land: int = self.n

	def main(self) -> int:
		while self.exist < self.land:
			if self.gameItems[self.land - 1]:
				self.land -= 1
			elif self.gameItems[self.exist + 1]:
				self.exist += 1
			else:
				break
		return self.land - self.exist

	def __str__(self) -> str:
		return str(Solution.main(self))
t = int(input())
for _ in range(t):
	n = int(input())
	gameItems: list = list(map(int, input().split()))
	print(Solution(n, gameItems))


class Solution(object):

	def __init__(self):
		self.n: int = int(input())
		self.gameItems: list = list(map(int, input().split()))

	def main(self) -> int:
		self.exist: int = -1
		self.land: int = self.n
		while self.exist < self.land:
			if self.gameItems[self.land - 1]:
				self.land -= 1
			elif self.gameItems[self.exist + 1]:
				self.exist += 1
			else:
				break
		return self.land - self.exist

	def __str__(self) -> str:
		return str(Solution.main(self))

class Run(object):

	def __init__(self):
		self.cases = int(input())
		while self.cases > 0:
			print(Solution())
			self.cases -= 1
Run()


for _ in range(int(input())):
	n = int(input())
	spic = list(map(int, input().split()))
	if spic.count(0) == 0:
		print(0)
		continue
	if spic.count(0) == 1:
		print(2)
		continue
	k = n
	while spic[k - 2] == 1:
		k -= 1
	print(k - spic.index(0))


n = int(input())
for i in range(n):
	a = int(input())
	ind = list(map(int, input().split()))
	R = ind[::-1]
	if 0 in ind:
		ind1 = ind.index(0)
		ind2 = a - R.index(0) + 1
		print(ind2 - ind1)
	elif 0 not in ind:
		print('0')


for _ in range(int(input())):
	n = int(input())
	nums = input().split(' ')
	res = 0
	i = 0
	j = n - 1
	while i + 1 < n and nums[i] == nums[i + 1] == '1':
		i += 1
	while j - 1 >= 0 and nums[j] == nums[j - 1] == '1':
		j -= 1
	print(max(0, j - i))


for tc in range(int(input())):
	n = int(input())
	arr = list(input().split())
	arr = ''.join(arr)
	first = arr.find('0')
	last = arr.rfind('0')
	if '0' not in arr:
		print(0)
	else:
		print(last - first + 2)


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


import sys
LI = lambda : list(map(int, sys.stdin.readline().split()))
MI = lambda : map(int, sys.stdin.readline().split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline())
for _ in range(II()):
	n = II()
	a = LI()
	cnt = 0
	for i in range(n - 1):
		if a[i] == 1 and a[i + 1] == 0:
			cnt += 1
	if cnt > 1:
		(i, j) = (a.index(0), n - a[::-1].index(0))
		print(j - i + 1)
	else:
		for i in range(n):
			if a[i] == 0:
				j = i
				while a[j] == 0:
					j += 1
				print(j - i + 1)
				break
		else:
			print(0)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	cost = []
	sum = 0
	count0 = 0
	for a in range(n):
		if l[a] == 0:
			count0 += 1
	for j in range(n):
		if l[j] == 0:
			cost.append(j)
			break
	for k in range(n):
		if l[n - k - 1] == 0:
			cost.append(n - k - 1)
			break
	if count0 == 0:
		print(0)
	elif count0 == 1:
		print(2)
	else:
		print(cost[1] - cost[0] + 2)


for _ in range(int(input())):
	n = int(input())
	nums = input().replace(' ', '')
	nums.replace
	if '0' in nums:
		left = nums.find('0') - 1
		right = nums.rfind('0')
		print(right - left + 1)
	else:
		print(0)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	i = n - 1
	while i >= 0:
		if a[i] == 0:
			break
		i -= 1
	j = 0
	while j < n:
		if a[j] == 0:
			break
		j += 1
	if i == -1 and j == n:
		print(0)
	else:
		print(i + 1 - (j - 1))


def solve(lis, n):
	start = end = 0
	i = 0
	while i < n:
		if lis[i] == 0:
			start = i - 1
			i = n + 1
		i += 1
	i = n - 1
	while i >= 0:
		if lis[i] == 0:
			end = i + 1
			i = -1
		i -= 1
	return end - start
for i in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	print(solve(lis, n))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if 0 not in a:
		print(0)
	elif a.count(0) == 1:
		print(2)
	else:
		x = a.index(0)
		a_reverse = a[::-1]
		y = a_reverse.index(0)
		answer = n - 1 - (y - 1) - (x - 1)
		print(answer)


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


j = int(input())
k = 0
for i in range(j):
	n = int(input())
	a = input()
	x = a.find('0')
	if x == -1:
		print(0)
	else:
		y = a.rfind('0')
		print((y + 1) // 2 + 1 - ((x + 1) // 2 - 1))


import sys
input = sys.stdin.readline

def solve(n, arr):
	f = 0
	b = n - 1
	ans = n - 1
	while b > f and arr[f] == arr[b] == 1:
		ans = min(ans, b - f)
		if arr[f + 1] == 1:
			f += 1
		elif arr[b - 1] == 1:
			b -= 1
		else:
			break
	if b == f and arr[f] == 1:
		print(0)
	else:
		print(ans)
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	solve(n, arr)


import sys
from math import sqrt, gcd, factorial
from collections import deque, Counter, OrderedDict
sys.setrecursionlimit(10 ** 6)
input = lambda : sys.stdin.readline()
I = lambda : int(input())
S = lambda : input().strip()
M = lambda : map(int, input().strip().split())
L = lambda : list(map(int, input().strip().split()))
mod = 1000000007
for _ in range(I()):
	n = I()
	a = L()
	(i, j) = (0, n - 1)
	while i < n and a[i]:
		i += 1
	while j >= 0 and a[j]:
		j -= 1
	print(max(0, j - i + 2))


t = int(input())
for _ in range(t):
	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 >= 0 and arr[r] == 1:
		r -= 1
	print(max(0, r - l + 2))


for i in range(int(input())):
	input()
	s = input().replace(' ', '')
	if '0' in s:
		print(s.rfind('0') - s.find('0') + 2)
	else:
		print(0)


import sys

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

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

def main():
	for _ in range(int(input())):
		n = int(input())
		ls = get_ls()
		l = 0
		r = 0
		for i in range(len(ls)):
			if ls[i] == 0:
				l = i - 1
				break
		for i in range(len(ls) - 1, 0, -1):
			if ls[i] == 0:
				r = i + 1
				break
		print(r - l)
main()


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


def print_hi(name):
	pass
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	l_zero = 0
	l_flag = 0
	r_zero = 0
	for j in range(len(a)):
		if a[j] == 0:
			r_zero = j
			if not l_flag:
				l_zero = j
				l_flag = 1
	if l_flag == 0:
		print(0)
	else:
		print(r_zero - l_zero + 2)


T_cases = int(input())
for i in range(T_cases):
	n = int(input())
	Location = list(map(int, input().split()))
	G = list(Location)
	G.reverse()
	if 0 in Location:
		print(n - G.index(0) + 1 - Location.index(0))
	else:
		print(0)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	(l, r) = (0, n - 1)
	while r >= 0 and a[r] == 1:
		r -= 1
	while l < n and a[l] == 1:
		l += 1
	if l > r:
		print(0)
	else:
		print(r - l + 2)


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split(' ')))
	if len(set(li)) == 1:
		print(0)
	else:
		(l, r) = (0, n - 1)
		while l <= r:
			if li[l] == 0 and li[r] == 0:
				print(r - l + 2)
				break
			elif li[l] == 0:
				r -= 1
			else:
				l += 1


for _ in range(int(input())):
	n = int(input())
	a = ''.join(input().split())
	if '0' in set(a):
		print(a.rfind('0') - a.find('0') + 2)
	else:
		print('0')


for t in range(int(input())):
	n = int(input())
	arr = ''.join(input().split())
	if '0' not in arr:
		print(0)
	else:
		i = arr.find('0')
		j = arr.rfind('0')
		j += 1
		i -= 1
		print(j - i)


def solve_problem():
	for _ in range(int(input())):
		_ = input()
		locations = [int(i) for i in input().split()]
		l = len(locations)
		begin_water = -1
		end_water = -1
		for i in range(l):
			if locations[i] == 0 and begin_water == -1:
				begin_water = i
			if locations[l - 1 - i] == 0 and end_water == -1:
				end_water = l - 1 - i
		if begin_water != -1:
			print(end_water - begin_water + 2)
		else:
			print(0)
solve_problem()


n = int(input())
for i in range(n):
	k = int(input())
	arr = list(map(int, input().split()))
	if 0 not in arr:
		print(0)
	elif arr.count(0) == 1:
		print(2)
	else:
		f = arr.index(0)
		arr.reverse()
		e = arr.index(0)
		print(len(arr) - f - e + 1)


for _ in range(int(input())):
	input()
	arr = input().split()
	s = ''.join(arr).strip('1')
	coins = len(s)
	if coins != 0:
		print(coins + 1)
	else:
		print(coins)


t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	j = -1
	k = 0
	for i in range(len(a)):
		if a[i] == 0 and j == -1:
			j = i
			k = 1
		if a[i] == 0 and j != -1:
			k = i - j + 2
	print(k)


import sys
t = int(sys.stdin.readline())
for k in range(0, t):
	n = int(sys.stdin.readline())
	a = list(sys.stdin.readline().split())
	n_f = 0
	n_l = 0
	for i in range(0, n):
		if a[i] == '0':
			n_f = i
			break
	for i in range(0, n):
		if a[-i] == '0':
			n_l = n - i
			break
	if n_f == 0:
		c = 0
	else:
		c = n_l - n_f + 2
	sys.stdout.write(str(c) + '\n')


tn = int(input())
for _ in range(tn):
	ln = int(input())
	ls = [int(x) for x in input().split(' ')]
	s = 0
	e = 0
	for i in range(len(ls)):
		if ls[i] == 0:
			e = i
		elif e == 0:
			s = i
	if e > 0:
		print(e + 1 - s)
	else:
		print(0)


mod = 10 ** 9 + 7

def ri():
	return int(input())

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

def rls():
	return list(map(str, input().split()))

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

def isPowerOfTwo(x):
	return x and (not x & x - 1)
for _ in range(ri()):
	n = ri()
	a = rl()
	if 0 not in a:
		print(0)
		continue
	l = a.index(0)
	a.reverse()
	r = n - a.index(0)
	print(r - l + 1)


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


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a.count(0) == 0:
		d = 0
	else:
		b = a.index(0)
		a.reverse()
		c = a.index(0)
		d = n - c - b + 1
	print(d)


tc = int(input())
for i in range(tc):
	n = int(input())
	path = input()
	path = path[::2]
	inv = path[::-1]
	if '0' not in path:
		ans = 0
	else:
		st0loc = path.index('0')
		last0loc = n - inv.index('0') - 1
		ans = last0loc - st0loc + 2
	print(ans)


t = int(input())
x = 1
while x <= t:
	n = int(input())
	location = str(input())
	list = location.split()
	coin = n - 1
	i = 1
	while i < n:
		if int(list[i]) == 1:
			i = i + 1
		else:
			break
	j = n
	while j > 0:
		if int(list[j - 2]) == 1:
			j = j - 1
		else:
			break
	if i == n:
		coin = 0
	else:
		coin = j - i
	print(coin)
	x = x + 1


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


def cost(locations: str) -> int:
	locations = locations.split()
	n = len(locations)
	j = n - 1
	while j >= 0 and locations[j] == '1':
		j -= 1
	j += 1
	i = 0
	while i < n and locations[i] == '1':
		i += 1
	i -= 1
	return max(0, j - i)
t = int(input())
for i in range(t):
	n = input()
	locations = input()
	print(cost(locations))


test = int(input())
for test_i in range(test):
	n = int(input())
	a = [int(i) for i in input().split()]
	st = ed = 0
	for i in range(n):
		if a[i] == 0:
			if st == 0:
				st = i
			ed = i
	if st:
		print(ed - st + 2)
	else:
		print(0)


for i in range(int(input())):
	n = int(input())
	x = len(''.join(input().split()).strip('1'))
	print(x + (x > 0))


t = int(input())
if 1 <= t and t <= 10 ** 4:
	while t:
		n = int(input())
		if 1 <= n and n <= 10 ** 4:
			s = input()
			arr = []
			for i in s:
				if i == '1' or i == '0':
					arr.append(int(i))
			if len(arr) == n:
				start = 0
				finish = 0
				for i in range(0, n):
					if arr[i] == 1:
						start = i
					else:
						break
				for i in range(n - 1, -1, -1):
					if arr[i] == 1:
						finish = i
					else:
						break
				if finish != 0:
					final = finish - start
				else:
					final = 0
				print(final)
		t -= 1


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


out = []

def game():
	x = int(input())
	y = list(map(int, input().strip().split()))
	coins = 0
	i = 0
	j = x - 1
	while j >= 0 and y[j]:
		j -= 1
	while i < x and y[i]:
		i += 1
	if j < 0:
		out.append(0)
	else:
		out.append(j - i + 2)
iter = int(input())
while iter > 0:
	game()
	iter -= 1
for i in range(0, len(out)):
	print(out[i])


def solve(n):
	a = c = 0
	for i in range(len(n)):
		if not n[i]:
			if not a + c:
				a = i - 1
			c = i + 1
	return c - a
for i in range(int(input())):
	input()
	print(solve([*map(int, input().split())]))


tests = int(input())
for _ in range(tests):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr.count(0) == 0:
		print(0)
	else:
		i = 0
		j = n - 1
		while i < j and arr[i + 1] == 1:
			i += 1
		while j > i and arr[j - 1] == 1:
			j -= 1
		print(j - i)


def main():
	times = int(input())
	for _ in range(times):
		n = int(input())
		data = list(map(int, input().split()))
		l = 0
		r = n - 1
		for l in range(0, n, 1):
			if data[l] == 0:
				break
		for r in range(n - 1, -1, -1):
			if data[r] == 0:
				break
		if l > r:
			print(0)
		else:
			print(r - l + 2)
main()


for _ in [0] * int(input()):
	n = int(input())
	s = input().split()
	w = s[::-1]
	if '0' not in w:
		print(0)
	else:
		a = s.index('0')
		b = w.index('0')
		print(len(w[a:n - b + 1]))


loopcount = int(input())
for loop in range(loopcount):
	a = int(input())
	x = input()
	x = x.split(' ')
	x = list(map(int, x))
	first_land = 0
	last_land = 0
	if 0 not in x:
		print(0)
		continue
	for i in range(a - 2, 0, -1):
		if x[i] == 0:
			last_land = i + 1
			break
	for i in range(a):
		if x[i] == 0:
			first_land = i - 1
			break
	print(last_land - first_land)


t = int(input())
for i in range(t):
	n = int(input())
	s = [int(x) for x in input().split()]
	lg = 0
	rg = n
	j = 0
	while s[j] != 0:
		lg = j
		if j < n - 1:
			j += 1
		else:
			break
	j = 0
	while s[n - j - 1] != 0:
		rg = n - j - 1
		if j < n - 2:
			j += 1
		else:
			break
	if rg - lg > 0:
		print(rg - lg)
	else:
		print(0)


zeros = list()
for t in range(int(input())):
	m = int(input())
	s = input().split()
	for i in range(m):
		if int(s[i]) != 1:
			zeros.append(i)
	if not zeros:
		print('0')
	else:
		print(zeros[-1] + 1 - (zeros[0] - 1))
		zeros = list()


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


n = int(input())
for i in range(n):
	k = int(input())
	l = [int(x) for x in input().split()]
	zero = l.count(0)
	if zero == 0:
		answer = 0
	elif zero == 1:
		answer = 2
	else:
		first = 0
		second = 0
		for x in range(k):
			if l[x] == 0:
				if first != 0:
					second = x
				else:
					first = x
		answer = second - first + 2
	print(answer)


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


def test():
	n = int(input())
	l = [int(i) for i in input().split()]
	fi = 0
	li = 0
	for i in range(n - 1):
		if l[i] == 0:
			fi = i - 1
			break
	for i in range(n - 1, 0, -1):
		if l[i] == 0:
			li = i + 1
			break
	print(li - fi)
	return
T = int(input())
for i in range(T):
	test()


t = int(input())
for _ in range(t):
	(n, a) = (int(input()), [int(i) for i in input().split()])
	(s, e) = (0, n - 1)
	while s + 1 < n and a[s + 1] > 0:
		s += 1
	while e - 1 >= 0 and a[e - 1] > 0:
		e -= 1
	res = max(e - s, 0)
	print(res)


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


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	p = 0
	while p < n and a[p]:
		p += 1
	if p == n:
		print(0)
		continue
	q = n
	while q > p and a[q - 1]:
		q -= 1
	print(q - p + 1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	left = 0
	while left + 1 < n and a[left + 1]:
		left += 1
	right = n - 1
	while right > 0 and a[right - 1]:
		right -= 1
	cost = max(right - left, 0)
	print(cost)