You are given a string $s$. Each character is either 0 or 1.

You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.

You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?


-----Input-----

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

Then $t$ lines follow, each representing a test case. Each line contains one string $s$ ($1 \le |s| \le 100$); each character of $s$ is either 0 or 1.


-----Output-----

Print $t$ integers, where the $i$-th integer is the answer to the $i$-th testcase (the minimum number of 0's that you have to erase from $s$).


-----Example-----
Input
3
010011
0
1111000

Output
2
0
0



-----Note-----

In the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).

Difficulty: EASY
Tags: String algorithms

Implementation

Starter code:

Solutions:
n = int(input())
for i in range(0, n):
	k = list(input())
	if '1' in k:
		j = 0
		while j < len(k):
			if k[j] == '1':
				p = j
				break
			j += 1
		l = len(k) - 1
		while l > 0:
			if k[l] == '1':
				q = l
				break
			l -= 1
		print(k[j:l + 1].count('0'))
	else:
		print('0')


t = int(input())
while t:
	s = input()
	i = 0
	sum = 0
	c = 0
	while i < len(s):
		if s[i] == '1':
			c = 0
			while i < len(s) - 1 and s[i + 1] != '1':
				c += 1
				i += 1
			if i + 1 == len(s):
				sum += 0
			else:
				sum += c
		i += 1
	print(sum)
	t -= 1


for _ in range(int(input())):
	str = input()
	s = str.find('1')
	e = str.rfind('1')
	res = 0
	if s != -1:
		for c in str[s + 1:e]:
			if c == '0':
				res += 1
	print(res)


for _ in range(int(input())):
	s = input()
	i = 0
	first = -1
	for i in range(len(s)):
		if s[i] == '1' and first == -1:
			first = i
		if s[i] == '1':
			last = i
	count = 0
	if first != -1:
		for i in range(first, last + 1):
			if s[i] == '0':
				count += 1
	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

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

def solve():
	s = inp()
	n = len(s)
	st = en = -1
	for i in range(n):
		if s[i] == '1':
			st = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			en = i
			break
	if st == -1:
		print(0)
		return
	c = 0
	for i in range(st, en):
		if s[i] == '0':
			c += 1
	print(c)
testcase(int(inp()))


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


import fileinput
numOfLines = int(input())
for i in range(numOfLines):
	s = input()
	first = 0
	while first < len(s) and s[first] != '1':
		first += 1
	if first == len(s):
		print(0)
		continue
	last = len(s) - 1
	while last > 0 and s[last] != '1':
		last -= 1
	numOfZero = 0
	for i in range(first + 1, last):
		if s[i] == '0':
			numOfZero += 1
	print(numOfZero)


for _ in range(int(input())):
	s = input()
	if s.count('1') == 0 or s.count('1') == 1:
		print(0)
	else:
		s1 = s[::-1]
		print(len(s) - s.index('1') - s1.index('1') - s.count('1'))


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


t = int(input())
for _ in range(t):
	s = list(input())
	count = 0
	i = 0
	tem_count = 0
	if '1' in s:
		ind = s.index('1')
		s = s[ind:]
	while i < len(s):
		if s[i] == '1':
			count += tem_count
			tem_count = 0
			i += 1
		else:
			tem_count += 1
			i += 1
	print(count)


n = int(input())
for i in range(n):
	s = input()
	q = 0
	for i in s:
		if i == '0':
			q += 1
		else:
			break
	for i in s[::-1]:
		if i == '0':
			q += 1
		else:
			break
	ans = len(s) - q - s.count('1')
	print(ans if ans > 0 else 0)


def solve():
	s = input()
	index = s.find('1')
	end = len(s) - s[::-1].find('1') - 1
	if index == -1:
		print(0)
		return
	count = 0
	while index < end:
		if s[index] == '0':
			count += 1
		index += 1
	print(count)
T = int(input())
for _ in range(T):
	solve()


for _ in range(int(input())):
	a = input()
	if '1' in a:
		print(a.rindex('1') - a.index('1') + 1 - a.count('1'))
	else:
		print(0)


from collections import deque
t = int(input())
for _ in range(t):
	s = deque(input())
	while len(s) > 0:
		if s[0] == '0':
			s.popleft()
		else:
			break
	while len(s) > 0:
		if s[-1] == '0':
			s.pop()
		else:
			break
	n = 0
	for s_i in s:
		if s_i == '0':
			n += 1
	print(n)


t = int(input())
for _ in range(t):
	s = input()
	ind = []
	count = 0
	for i in range(len(s)):
		if s[i] == '1':
			ind.append(i)
	for i in range(len(ind) - 1):
		count += ind[i + 1] - ind[i] - 1
	print(count)


while True:
	try:
		t = eval(input())
		for i in range(t):
			s = list(input())
			while len(s) != 0 and s[0] != '1':
				s.pop(0)
			while len(s) != 0 and s[len(s) - 1] != '1':
				s.pop()
			print(s.count('0'))
	except:
		break


n = int(input())
l = [input() for i in range(n)]
for st in l:
	sum = 0
	cur_sum = 0
	f = 0
	for num in st:
		if f == 0 and num == '1':
			f = 1
		elif f == 1 and num == '0':
			cur_sum += 1
		elif f == 1 and num == '1':
			sum += cur_sum
			cur_sum = 0
	print(sum)


t = int(input())
for tt in range(t):
	s = input()
	bz = 0
	on = 0
	z = 0
	for i in s:
		if i == '0':
			if on != 0:
				z += 1
		if i == '1':
			on += 1
			if z != 0:
				bz += z
				z = 0
	print(bz)


def minimum_deletions(string):
	string = string.strip('0')
	result = 0
	for i in string:
		if i == '0':
			result += 1
	return result
T = int(input().strip())
for t in range(T):
	print(minimum_deletions(input().strip()))


test = int(input())
for t in range(test):
	n = str(input())
	L = []
	for s in range(len(n)):
		if n[s] == '1':
			L.append(s)
	cnt = 0
	for i in range(len(L) - 1):
		cnt += L[i + 1] - L[i] - 1
	print(cnt)


def solution():
	from sys import stdin, stdout
	from re import findall
	(_input, _print, _range, _int, _len, _str) = (stdin.readline, stdout.write, range, int, len, str)
	_findall = findall
	for _ in _range(_int(_input())):
		s = _input()
		a = _findall('(?<=1)(0*)(?=1)', s)
		sum = 0
		for i in a:
			sum += _len(i)
		_print(_str(sum) + '\n')
solution()


def cz(l):
	d = 0
	for i in l:
		if i == '1':
			break
		else:
			d += 1
	return d
n = int(input())
ans = []
for i in range(n):
	a = input()
	if a.count('1') == 0:
		ans.append(0)
	else:
		ans.append(a.count('0') - (cz(a) + cz(a[::-1])))
print(*ans, sep='\n')


INF = 10 ** 10

def main():
	print = out.append
	st = list(input().strip('0'))
	print(st.count('0'))
import sys
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
[main() for _ in range(int(input()))]
print(*out, sep='\n')


n = input()
n = int(n)
for i in range(n):
	s = str(input())
	k = -1
	l = -1
	for j in range(len(s)):
		if s[j] == '1':
			k = int(j)
			break
	for j in range(len(s) - 1, -1, -1):
		if s[j] == '1':
			l = int(j + 1)
			break
	co = 0
	for j in range(k, l):
		if s[j] == '0':
			co = co + 1
	print(co)


t = int(input())
while t:
	s = input()
	l = list(s)
	l2 = []
	s = 0
	for i in range(len(l)):
		if l[i] == '1':
			l2.append(i)
	for i in range(1, len(l2)):
		if l2[i] - l2[i - 1] > 1:
			s += l2[i] - l2[i - 1] - 1
	print(s)
	t = t - 1


import sys
import math
import itertools
import functools
import collections
import operator

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

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

def li():
	return list(map(int, 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):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
t = ii()
for _ in range(t):
	s = list(input())
	ans = 0
	lpos = 0
	while lpos < len(s) and s[lpos] == '0':
		lpos += 1
	rpos = len(s) - 1
	while rpos > 0 and s[rpos] == '0':
		rpos -= 1
	print(s[lpos:rpos].count('0'))


t = int(input())
while t > 0:
	s = input()
	ones = s.count('1')
	if ones == 0:
		print('0')
	else:
		a = s.index('1')
		b = s.rindex('1')
		print(b - a + 1 - ones)
	t -= 1


for t in range(int(input())):
	s = input()
	a = 0
	b = 0
	x = 0
	y = 0
	k = s[0]
	for i in range(len(s)):
		if k == s[i]:
			x += 1
		elif k != s[i] or i + 1 == len(s):
			if k == '0':
				a += 1
			else:
				b += 1
			if b > 0 and k == '0':
				y += x
			x = 1
			k = s[i]
	print(y)


import math
I = lambda : int(input())
ID = lambda : map(int, input().split())
IL = lambda : list(ID())
t = I()
for _ in range(t):
	s = input()
	s = s.strip('0')
	print(s.count('0'))


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
import bisect
import heapq as hq

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

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

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	try:
		for _ in range(I()):
			l = list(input())
			ans = []
			if len(l) == 1:
				print(0)
			else:
				for x in range(len(l)):
					if l[x] == '1':
						ans.append(x)
						break
				for x in range(len(l) - 1, -1, -1):
					if l[x] == '1':
						ans.append(x)
						break
				j = 0
				if len(ans) == 0 or len(ans) == 1:
					print(0)
				else:
					for x in range(ans[0], ans[1] + 1):
						if l[x] == '0':
							j += 1
					ans.clear()
					print(j)
	except:
		pass
main()


t = int(input())
while t > 0:
	t -= 1
	n = input()
	answer = 0
	temp = 0
	firstOne = False
	for char in n:
		if char == '0':
			if firstOne:
				temp += 1
		elif firstOne:
			answer += temp
			temp = 0
		else:
			firstOne = True
	print(answer)


t = int(input())
while t != 0:
	s = input()
	l = len(s)
	if l == 1:
		print(0)
	else:
		c = 0
		previndx = -1
		for i in range(0, l):
			if s[i] == '1':
				if i != 0:
					if previndx != -1:
						c += i - previndx - 1
					previndx = i
				else:
					previndx = 0
		if c > 0:
			print(c)
		else:
			print(0)
	t -= 1


cases = input()
case_list = [input() for i in range(int(cases))]
for case in case_list:
	removed = 0
	met_first = 0
	uncommited_removed = 0
	for c in case:
		if not met_first and c == '1':
			met_first = 1
		if met_first and c == '0':
			uncommited_removed += 1
		if c == '1':
			removed += uncommited_removed
			uncommited_removed = 0
	print(removed)


T = int(input())
for i in range(T):
	s = input()
	count = 0
	ans = 0
	flag = 0
	ze = 0
	for j in range(len(s)):
		if s[j] == '0':
			ze += 1
		else:
			break
	for j in range(ze, len(s)):
		if s[j] == '1':
			flag = 1
			if flag == 1:
				ans += count
				count = 0
		else:
			count += 1
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	n = len(s)
	f = -1
	l = -1
	c = 0
	for j in range(n):
		if s[j] == '1':
			l = j
			c += 1
			if f == -1:
				f = j
	if f == -1:
		print(0)
		continue
	print(l - f + 1 - c)


t = int(input())
for i in range(t):
	num = input()
	zeroes = 0
	maybe = 0
	one_check = False
	for j in range(len(num)):
		if num[j] == '1':
			if one_check == False:
				one_check = True
			elif num[j - 1] == '0':
				zeroes += maybe
				maybe = 0
		if num[j] == '0' and one_check == True:
			maybe += 1
	print(zeroes)


t = int(input())
while t:
	s = input()
	print(s.strip('0').count('0'))
	t -= 1


t = int(input())
for _ in range(t):
	s = str(input())
	if '1' in s:
		i = s.index('1')
		j = s.rindex('1')
		print(s[i:j + 1].count('0'))
	else:
		print(0)


t = int(input())
out = []
for i in range(t):
	s = input()
	li = 0
	ri = 0
	found_leftmost = False
	for (j, c) in enumerate(s):
		if c == '1':
			if not found_leftmost:
				li = j
				found_leftmost = True
			ri = j
	ss = s[li:ri + 1]
	ct = 0
	if found_leftmost:
		for c in ss:
			if c == '0':
				ct += 1
	out.append(ct)
for o in out:
	print(o)


a = int(input())
for i in range(a):
	b = str(input())
	x = b.strip('0')
	o = x.count('0')
	print(o)


t = int(input())
for _ in range(t):
	s = input()
	lc = 0
	gc = 0
	first = True
	for i in range(len(s)):
		if s[i] == '1' and first:
			first = False
			lc = 0
		elif s[i] == '1':
			gc += lc
			lc = 0
		else:
			lc += 1
	print(gc)


t = int(input())
while t:
	s = input()
	l = []
	for i in range(1, len(s)):
		if s[i] == '0' and s[i - 1] == '1':
			l.append(i - 1)
		if s[i] == '1' and s[i - 1] == '0':
			l.append(i)
	res = 0
	if s[0] == '0' and len(l) or len(l) == 1:
		l.pop(0)
	if len(l) % 2:
		l.pop()
	for i in range(0, len(l), 2):
		res += l[i + 1] - l[i] - 1
	print(res)
	t -= 1


t = int(input())

def f(l):
	kol = 0
	last = -1
	for i in range(len(l)):
		if l[i] == '0':
			kol += 1
		elif l[i] == '1':
			last = i
	for i in range(len(l)):
		if l[i] == '1':
			kol -= i
			break
	return kol - (len(l) - last - 1)
for i in range(t):
	l = input()
	print(f(l))


t = int(input())
for j in range(1, t + 1):
	s = input()
	l = len(s)
	i = 0
	chk1 = -1
	chk2 = -2
	while i < l:
		if s[i] == '1':
			chk1 = i
			break
		i += 1
	ii = l - 1
	while ii >= 0:
		if s[ii] == '1':
			chk2 = ii
			break
		ii -= 1
	k = chk1 + 1
	ans = 0
	while k < chk2:
		if s[k] == '0':
			ans += 1
		k += 1
	print(ans)


def numRemZero(string):
	start1 = -1
	end1 = -1
	for i in range(len(string)):
		if string[i] == '1' and start1 == -1:
			start1 = i
		elif string[i] == '1':
			end1 = i
	countZero = 0
	for i in range(start1, end1, 1):
		if string[i] == '0':
			countZero += 1
	return countZero
input()
while True:
	try:
		val = input()
		print(numRemZero(val))
	except EOFError:
		break


def rle(a):
	if not a:
		return []
	res = []
	for x in a:
		if not res or x != res[-1][0]:
			res.append([x, 1])
		else:
			res[-1][1] += 1
	return res

def solve():
	s = input()
	a = rle(s)
	if a and a[0][0] == '0':
		a.pop(0)
	if a and a[-1][0] == '0':
		a.pop()
	if len(a) < 2:
		print(0)
	else:
		print(sum((0 if x[0] == '1' else x[1] for x in a)))
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for i in range(t):
	s = input()
	flag = False
	cnt = 0
	ans = 0
	for j in range(len(s)):
		if flag and s[j] == '1':
			ans += cnt
			cnt = 0
		if s[j] == '1':
			flag = True
		elif flag:
			cnt += 1
	print(ans)


for _ in range(int(input())):
	s = input()
	n = len(s)
	r = s[::-1]
	c = 0
	if s.count('1') and s.count('0') and (n > 1):
		for i in range(s.index('1') + 1, n - r.index('1') - 1):
			if s[i] == '0':
				c += 1
	print(c)


from collections import Counter

def func():
	n = input()
	f = 0
	l = 0
	c = 0
	for i in range(len(n)):
		if n[i] == '1':
			f = i
			break
	for i in range(len(n)):
		if n[i] == '1':
			l = i
	for i in range(f, l + 1):
		if n[i] == '0':
			c += 1
	if f == 0 and l == 0:
		print('0')
	else:
		print(c)
t = 1
t = int(input())
for i in range(t):
	func()


for _ in range(int(input())):
	s = input()
	count = 0
	c = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
	temp = c
	for i in range(len(s)):
		if s[i] == '0' and temp == c:
			continue
		if temp == 0:
			break
		if s[i] == '1':
			temp -= 1
		else:
			count += 1
	print(count)


from sys import stdin, stdout
nmbr = lambda : int(input())
lst = lambda : list(map(int, input().split()))
for _ in range(nmbr()):
	s = input()
	n = len(s)
	p1 = n
	p2 = -1
	ans = 0
	for i in range(n):
		if s[i] == '1':
			p1 = min(p1, i)
			p2 = max(p2, i)
	for i in range(p1, p2 + 1):
		if s[i] == '0':
			ans += 1
	print(ans)


for _ in range(int(input())):
	r = str(input())
	t = 0
	k = len(r)
	ans = 0
	d = 0
	for i in range(k):
		if r[i] == '1' and d == 0:
			t = i
			d = 1
		if r[i] == '1' and d == 1:
			ans += i - t
			t = i + 1
	print(ans)


import re
t = int(input())
for i in range(t):
	s = input()
	last = None
	total = 0
	for i in range(len(s)):
		if s[i] == '1':
			if last is None:
				last = i
				continue
			else:
				total += i - last - 1
				last = i
	print(total)


t = input()
t0 = 1
i = 0
while t0 <= int(t):
	str1 = input()
	i = 0
	pos = 0
	first = 0
	vis = False
	cnt = 0
	for s in str1:
		if s == '1':
			pos = i
			if vis == False:
				first = i
				vis = True
		i += 1
	for k in range(first, pos):
		if str1[k] == '0':
			cnt += 1
	print(cnt)
	t0 += 1


import math, sys, itertools
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
for t in wtf[1:]:
	S = t.rstrip('0').lstrip('0')
	print(S.count('0'))


for _ in range(int(input())):
	s = input()
	flag = 0
	count = 0
	prev = -1
	for i in range(len(s)):
		if s[i] == '1' and flag == 0:
			flag = 1
			prev = i
			continue
		if s[i] == '1' and prev > -1:
			count += i - prev - 1
			prev = i
	print(count)


tc = int(input())
for t in range(tc):
	string = input()
	(i, j) = (-1, -1)
	for k in range(len(string)):
		if string[k] == '1' and i < 0:
			i = k
		if string[k] == '1':
			j = k
	cnt = 0
	for k in range(i, j):
		if string[k] == '0':
			cnt += 1
	print(cnt)


i = int(input())
for _ in range(i):
	string = input()
	processed = string.strip('0')
	count = processed.count('0')
	print(count)


n = int(input())
a = 0
for i in range(n):
	s = input()
	if '1' not in s:
		a = 0
	else:
		s1 = s.index('1')
		s2 = len(s) - s[::-1].index('1') - 1
		a = s[s1:s2].count('0')
	print(a)


t = int(input())
for _ in range(0, t):
	a = input()
	a = list(a)
	count1 = -1
	for i in range(0, len(a)):
		if a[i] == '1':
			count1 = i
			break
	if count1 == -1:
		print(0)
	else:
		z = len(a) - 1
		for i in range(z, -1, -1):
			if a[i] == '1':
				count2 = i
				break
		if count1 == count2:
			print(0)
		else:
			z = a[count1:count2 + 1]
			p = z.count('0')
			print(p)


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


t = int(input())
for i in range(t):
	s = input()
	c = s.count('0')
	n = len(s)
	c1 = 0
	c2 = n - 1
	if c == n:
		print(0)
	else:
		while s[c1] == '0':
			c1 += 1
			c -= 1
		while s[c2] == '0':
			c2 -= 1
			c -= 1
		print(c)


import sys
from sys import stdin, stdout
import bisect
import math
import heapq

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())
import math

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 main():
	t = inin()
	for _ in range(t):
		s = sin()
		n = len(s)
		x = y = -1
		for i in range(n):
			if s[i] == '1' and x == -1:
				y = i
			if s[i] == '1':
				x = i
		ans = 0
		if x >= 0:
			for i in range(y, x):
				if s[i] == '0':
					ans += 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')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


import itertools

def countstrs(s):
	return [(k, len(list(g))) for (k, g) in itertools.groupby(s)]
q = int(input())
for i in range(q):
	s = input()
	c = countstrs(s)
	if c[0][0] == '0':
		del c[0]
	if len(c) > 0:
		if c[-1][0] == '0':
			del c[-1]
	res = 0
	for i in range(len(c)):
		if c[i][0] == '0':
			res += c[i][1]
	print(res)


for _ in range(int(input())):
	s = input()
	(a, b) = (0, 0)
	n = len(s)
	for i in range(n):
		if int(s[i]) == 1:
			a = i
			break
	for j in range(n - 1, -1, -1):
		if int(s[j]) == 1:
			b = j
			break
	print(s[a + 1:b].count('0'))


for i in range(int(input())):
	s = input()
	n = s.find('1')
	m = int(n)
	c = int(0)
	for j in range(len(s)):
		if s[j] == '1':
			m = max(m, j)
			c += 1
	print(c if c == 0 else m - n + 1 - c)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def erase():
	for _ in range(t):
		string = input()
		find = False
		(count1, count2) = (0, 0)
		for ele in string:
			if not find:
				if ele == '1':
					find = True
			elif ele == '0':
				count1 += 1
			else:
				count2 = count1
		yield count2
t = int(input())
ans = erase()
print(*ans, sep='\n')


x = int(input())
while x != 0:
	count = 0
	a = input()
	i = a.find('1')
	j = a.rfind('1')
	for k in range(i, j):
		if a[k] == '0':
			count += 1
	print(count)
	x -= 1


from sys import stdin
N = int(stdin.readline())
tests = []
for i in range(N):
	tests.append(stdin.readline())
for test in tests:
	start = test.find('1')
	end = test.rfind('1') + 1
	count = 0
	for ch in list(test[start:end]):
		if ch == '0':
			count += 1
	print(count)


entrada = int(input())
testes = []
for i in range(entrada):
	testes.append(input())
for teste in testes:
	interrupt = False
	num_zeros_parcial = 0
	num_zeros_total = 0
	for i in range(len(teste)):
		if teste[i] == '0' and interrupt == True:
			num_zeros_parcial += 1
		if teste[i] == '1':
			if interrupt == True:
				if teste[i - 1] == '0':
					num_zeros_total += num_zeros_parcial
					num_zeros_parcial = 0
			else:
				interrupt = True
	print(num_zeros_total)


for _ in range(int(input())):
	ss = input()
	first = ss.find('1')
	if first == -1:
		print('0')
		continue
	second = ss.rfind('1')
	ans = 0
	for i in range(first, second + 1):
		if ss[i] == '0':
			ans += 1
	print(ans)


for i in range(int(input())):
	x = input()
	ones = x.count('1')
	zeros = x.count('0')
	if zeros == len(x) or ones == len(x):
		print(0)
	elif ones == 1:
		print(0)
	else:
		zero = x.find('1')
		x = x[::-1]
		zero += x.find('1')
		ans = zeros - zero
		print(ans)


t = int(input())
while t != 0:
	s = input()
	l = 0
	k = 0
	for i in range(len(s)):
		if s[i] == '1':
			l = i
			break
	for i in range(len(s) - 1, 0, -1):
		if s[i] == '1':
			k = i
			break
	count = 0
	for i in range(l, k, 1):
		if s[i] == '0':
			count += 1
	print(count)
	t -= 1


for s in [*open(0)][1:]:
	print(s[s.find('1'):s.rfind('1')].count('0'))


for t in range(int(input())):
	a = input()
	i = 0
	pr = 0
	cu = 0
	su = 0
	while i < len(a):
		if pr == 0:
			if a[i] == '1':
				pr = 1
		elif a[i] == '0':
			su += 1
			cu += 1
		else:
			cu = 0
		i += 1
	print(su - cu)


t = int(input())
for i in range(t):
	st = input()
	firstone = -1
	for i in range(len(st)):
		if st[i] == '1':
			firstone = i
			break
	if firstone == -1:
		print(0)
	else:
		for i in range(len(st) - 1, -1, -1):
			if st[i] == '1':
				lastone = i
				break
		erasecount = 0
		for i in range(firstone + 1, lastone):
			if st[i] == '0':
				erasecount += 1
		print(erasecount)


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


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


for _ in range(int(input())):
	s = input()
	n = len(s)
	index = -1
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			index = i
			break
	if index == -1:
		print(0)
	else:
		l = s.find('1')
		print(s[l:index].count('0'))


n = int(input())
for j in range(0, n):
	S = list(input())
	count = 0
	Sum = 0
	if '1' in S:
		k = S.index('1')
	else:
		print(0)
		continue
	for i in range(int(k), len(S)):
		if S[i] == '0':
			count = count + 1
		if S[i] == '1':
			Sum = Sum + count
			count = 0
	print(Sum)


def zero_counter(key, first, last):
	i = first
	j = last
	cnt = 0
	while i <= j:
		if key[i] == '0':
			cnt += 1
		i += 1
	return cnt
n = int(input())
for _ in range(n):
	key = input()
	key_rev = key[::-1]
	try:
		first = key.index('1')
		last = len(key) - key_rev.index('1')
	except:
		first = 0
		last = 0
	ans = zero_counter(key, first, last - 1)
	print(ans)


t = int(input())
while t:
	s = input()
	s = list(s)
	n = len(s)
	a = 0
	b = 0
	for i in range(n):
		if s[i] == '1':
			a = i
			break
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			b = j
			break
	if a == b:
		print(0)
	else:
		z = s[a:b + 1]
		zero = z.count('0')
		print(zero)
	t -= 1


from collections import Counter
n = int(input())
for _ in range(n):
	x = input()
	l = x.find('1')
	r = x.rfind('1')
	print(Counter(x[l:r])['0'])


t = int(input())
for _ in range(t):
	s = input()
	tf = False
	ans = 0
	i = 0
	while i < len(s) - 1:
		if s[i] == '1' and s[i + 1] == '0':
			for j in range(i + 1, len(s)):
				if s[j] == '1':
					ans += j - i - 1
					break
			i = j
		else:
			i += 1
	print(ans)


num_of_rows = input()
for row in range(int(num_of_rows)):
	s = input()
	cnt = 0
	cnt_last = 0
	is_first = True
	for c in s:
		if c == '0' and is_first:
			continue
		elif c == '1':
			is_first = False
			cnt_last = 0
		else:
			cnt += 1
			cnt_last += 1
	print(cnt - cnt_last)


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
S = lambda : input().strip()
mod = 1000000007
for i in range(I()):
	s = input()
	(p, q) = (-1, -1)
	f = 0
	for i in range(len(s)):
		if s[i] == '1' and f == 0:
			p = i
			f = 1
		elif s[i] == '1' and f == 1:
			q = i
	c = 0
	if p != -1 and q != -1:
		for i in range(p, q + 1):
			if s[i] == '0':
				c += 1
	print(c)


import math
import sys

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

def main():
	answer = ''
	for test in range(int(input())):
		s = input()
		first_one = -1
		last_one = -1
		to_del = 0
		for index in range(len(s)):
			if s[index] == '1' and first_one == -1:
				first_one = index
			elif s[index] == '1':
				last_one = index
		if last_one == -1:
			answer += '0 \n'
		else:
			for index in range(first_one, last_one + 1):
				if s[index] == '0':
					to_del += 1
			answer += str(to_del) + '\n'
		pass
	print(answer)
main()


t = int(input())
while t > 0:
	t -= 1
	n = input()
	h = list(n)
	k = h
	a = 0
	for i in range(0, len(n)):
		if h[i] == '1':
			a = i
			break
	b = 0
	c = 0
	i = len(n) - 1
	while i >= 0:
		if h[i] == '1':
			b = i
			break
		i -= 1
	if a != b:
		for i in range(a, b + 1):
			if h[i] == '0':
				c += 1
		print(c)
	else:
		print(0)


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


t = int(input())
ans = []
for i in range(t):
	value = input()
	count = 0
	total = 0
	if '1' not in value:
		k = len(value) - 1
	else:
		for i in range(len(value)):
			if value[i] == '1':
				k = i
				break
	for j in range(k + 1, len(value)):
		if value[j] != '1':
			count += 1
		else:
			total += count
			count = 0
	ans.append(total)
for i in ans:
	print(i)


t = int(input())
for _ in range(t):
	s = input()
	prev = 0
	count = 0
	onecount = 0
	for i in range(len(s)):
		if s[i] == '1' and onecount > 0:
			count += i - prev - 1
			prev = i
		if s[i] == '1':
			onecount += 1
			prev = i
	print(count)


def solution(A):
	try:
		first = A.index(1)
		second = len(A) - 1 - A[::-1].index(1)
		return A[first:second].count(0)
	except:
		return 0
n = int(input())
for _ in range(n):
	A = list(map(int, list(input())))
	print(solution(A))


for x in range(int(input())):
	inp = list(map(int, input()))
	count = dict()
	num = int()
	for y in range(len(inp)):
		if inp[0] == 1:
			break
		else:
			inp.remove(inp[0])
	for z in range(len(inp)):
		if inp[-1] == 1:
			break
		else:
			inp.pop(-1)
	num = len(inp) - sum(inp)
	print(num)


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


def main():
	s = input()
	s = s[s.find('1'):s.rfind('1') + 1]
	return len(s) - s.count('1')
t = int(input())
for i in range(t):
	print(main())


for _ in range(int(input())):
	s = list(input())
	if len(s) == 1:
		print(0)
		continue
	try:
		start = s.index('1')
		end = len(s) - s[::-1].index('1')
		count = 0
	except:
		print(0)
		continue
	for i in range(start, end):
		if s[i] == '0':
			count += 1
	print(count)


for _ in range(int(input())):
	s = input()
	c = 0
	ans = 0
	f = 0
	for i in s:
		if i == '1':
			f = 1
		if i == '0' and f == 1:
			c += 1
		if i == '1' and f == 1:
			ans += c
			c = 0
	print(ans)


t = int(input())
for test in range(t):
	s = input()
	n = len(s)
	fi = -1
	for i in range(n):
		if s[i] == '1':
			fi = i
			break
	li = -1
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			li = i
			break
	cnt = 0
	if li == -1:
		print(0)
	else:
		for i in range(fi, li + 1):
			if s[i] == '0':
				cnt += 1
		print(cnt)


t = int(input())
while t > 0:
	t -= 1
	s = input()
	while len(s) > 0 and s[0] == '0':
		s = s[1:]
	while len(s) > 0 and s[-1] == '0':
		s = s[:-1]
	print(s.count('0'))


t = int(input())
for i in range(t):
	st = input()
	st = st.strip('0')
	count = 0
	for i in range(len(st)):
		if st[i] == '0':
			count += 1
	print(count)


from sys import stdin
from bisect import bisect_left as bl
from bisect import bisect_right as br

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

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

def intsput():
	return map(int, sinput())

class RangedList:

	def __init__(self, start, stop, val=0):
		self.shift = 0 - start
		self.start = start
		self.stop = stop
		self.list = [val] * (stop - start)

	def __setitem__(self, key, value):
		self.list[key + self.shift] = value

	def __getitem__(self, key):
		return self.list[key + self.shift]

	def __repr__(self):
		return str(self.list)

	def __iter__(self):
		return iter(self.list)
t = intput()
for _ in range(t):
	s = input()
	cnt = 0
	tcnt = 0
	f = False
	for x in s:
		if not f and x == '1':
			f = True
		if f and x == '0':
			tcnt += 1
		if f and x == '1':
			cnt += tcnt
			tcnt = 0
	print(cnt)


t = int(input())
for k in range(t):
	s = input()
	ans = 0
	kol = 0
	flag = False
	for i in range(len(s)):
		if s[i] == '1':
			if not flag:
				flag = True
				kol = 0
			else:
				ans += kol
				kol = 0
		else:
			kol += 1
	print(ans)


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


a = int(input())
for i in range(a):
	s = list(input())
	if len(s) > 1:
		if len(s) != s.count('0'):
			while s[0] != '1':
				del s[0]
			while s[-1] != '1':
				del s[-1]
			counts = s.count('0')
			print(counts)
		else:
			print(0)
	else:
		print(0)


t = int(input())
while t:
	t -= 1
	s = input().strip()
	ans = 0
	i = 0
	while i < len(s) - 1:
		if s[i] == '1' and s[i + 1] == '0':
			j = i + 2
			p = False
			while j < len(s):
				if s[j] == '1':
					p = True
					break
				j += 1
			if p:
				ans += j - i - 1
			i = j
		else:
			i += 1
	print(ans)


t = int(input())
for i in range(0, t):
	sm = 0
	s = input()
	s = s.strip('0')
	for c in s:
		if c == '0':
			sm = sm + 1
	print(sm)


results = []
S = []
for t in range(int(input())):
	s = input()
	S.append(s)
for s in S:
	s = s.strip('0')
	result = s.count('0')
	results.append(result)
for result in results:
	print(result)


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


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().split())

def li():
	return list(mi())
for i in range(ii()):
	s = si()
	c = 0
	l = []
	if s.count('1') == 0:
		print(0)
		continue
	for i in range(len(s)):
		if s[i] == '1':
			l.append(i)
	if len(l) == 1:
		print(0)
		continue
	l1 = []
	for i in range(1, len(l)):
		l1.append(l[i] - l[i - 1] - 1)
	print(sum(l1))


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


for _ in range(int(input())):
	word = input()
	temp = []
	for i in range(len(word)):
		if word[i] == '1':
			temp.append(i)
	ans = 0
	for i in range(1, len(temp)):
		ans += temp[i] - temp[i - 1] - 1
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	pred = -1
	res = 0
	if s[0] == '1':
		pred = 0
	for j in range(1, len(s)):
		if s[j] == '1' and pred == j - 1:
			pred = j
		elif s[j] == '1' and pred != -1:
			res += j - pred - 1
			pred = j
		elif s[j] == '1':
			pred = j
	print(res)


for i in range(int(input())):
	s = input()
	i1 = s.find('1')
	i2 = s.rfind('1')
	if i1 == -1 or i2 == -1:
		print(0)
		continue
	t = 0
	for i in range(i1, i2 + 1):
		t += int(s[i])
	print(i2 - i1 + 1 - t)


for t in range(int(input())):
	answer = 0
	data = input()
	first_index = data.find('1')
	last_index = data.rfind('1')
	print(data.count('0', first_index, last_index))


for _ in range(int(input())):
	num = int(input())
	count = 0
	lcount = 0
	flag = 0
	while num > 0:
		if num % 10 == 1:
			flag = 1
			count += lcount
			lcount = 0
		elif flag == 1:
			lcount += 1
		num //= 10
	print(count)


import re
t = int(input())
for __ in range(t):
	p = input()
	j = [m.start() for m in re.finditer('1', p)]
	l = [m.start() for m in re.finditer('0', p)]
	if p.count('1') == 0:
		print('0')
	elif p.count('0') == 0:
		print('0')
	elif min(j) == 0 and max(j) == len(p) - 1:
		print(p.count('0'))
	else:
		q = p[min(j):max(j)]
		print(q.count('0'))


t = int(input())
for i in range(t):
	s = input()
	try:
		(first, last) = (s.index('1'), s.rindex('1'))
	except ValueError:
		print(0)
		continue
	print(s[first:last].count('0'))


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


t = int(input())
while t > 0:
	s = input()
	p = 0
	prev = s[0]
	v = []
	cur = s[0]
	s = s[1:]
	for c in s:
		if c == prev:
			cur = cur + c
		else:
			v.append(cur)
			cur = c
			prev = c
	v.append(cur)
	if len(v) == 1:
		print(0)
		t -= 1
		continue
	if v[0][0] == '0':
		v = v[1:]
	if v[len(v) - 1][0] == '0':
		v = v[:-1]
	cnt = 0
	for c in v:
		if c[0] == '0':
			cnt += len(c)
	print(cnt)
	t -= 1


t = int(input())
for _ in range(t):
	s = input()
	array = []
	cnt = 1
	for i in range(len(s) - 1):
		if s[i] == s[i + 1]:
			cnt += 1
		else:
			array.append(cnt)
			cnt = 1
	array.append(cnt)
	if s[0] == '0':
		if len(array) <= 3:
			print(0)
		else:
			ans = 0
			for i in range(2, len(array) - 1, 2):
				ans += array[i]
			print(ans)
	elif len(array) <= 2:
		print(0)
	else:
		ans = 0
		for i in range(1, len(array) - 1, 2):
			ans += array[i]
		print(ans)


t = int(input())
for i in range(t):
	s = input()
	res = 0
	t = 0
	for j in s:
		if j == '1':
			t = 1
		elif t and j == '0':
			res += 1
	if '1' not in s:
		print(0)
		continue
	s = list(s)
	s.reverse()
	res -= s.index('1')
	print(res)


t = int(input())
for test in range(t):
	line = input()
	start = line.find('1')
	end = line.rfind('1')
	count = 0
	if start != -1:
		for i in range(start, end + 1):
			if line[i] == '0':
				count = count + 1
	print(count)


for _ in range(int(input())):
	s = input()
	i = 0
	j = len(s) - 1
	while i < len(s) and s[i] == '0':
		i += 1
	while j > 0 and s[j] == '0':
		j -= 1
	ans = 0
	for k in range(i, j):
		if s[k] == '0':
			ans += 1
	print(ans)


from collections import defaultdict, Counter, deque
from math import sqrt, log10, log, floor, factorial
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations
import sys, io, os
input = sys.stdin.readline
inf = float('inf')
mod = 10 ** 9 + 7

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

def yn(a):
	print('YES' if a else 'NO')
ceil = lambda a, b: (a + b - 1) // b
t = int(input())
for i in range(t):
	s = input().strip()
	index1 = s.find('1')
	index2 = s.rfind('1')
	print(len([i for i in range(len(s)) if s[i] == '0' and index1 <= i <= index2]))


t = int(input())
while t > 0:
	t -= 1
	s = input()
	cnt = 0
	one = []
	zero = []
	for i in range(len(s)):
		if s[i] == '1':
			one.append(i)
		else:
			zero.append(i)
	if len(zero) == 0 or len(one) == 0:
		cnt = 0
	else:
		minn = one[0]
		maxx = one[len(one) - 1]
		for i in range(len(zero)):
			if zero[i] > minn and zero[i] < maxx:
				cnt += 1
	print(cnt)


t = int(input())
for i in range(0, t):
	s = input()
	summ = 0
	count = 0
	active = 0
	for i in range(0, len(s)):
		if int(s[i]) == 1 and active == 0:
			active = 1
		elif int(s[i]) == 0 and active == 1:
			count += 1
		elif int(s[i]) == 1 and active == 1:
			summ = summ + count
			count = 0
	print(summ)


num = int(input())
for _ in range(num):
	mins = 0
	st = input()
	if len(st) > 1:
		for i in st:
			if i == '0':
				mins += 1
			else:
				break
		st = st[mins:]
		j = len(st) - 1
		mins = 0
		try:
			while st[j] == '0':
				mins += 1
				j = j - 1
		except:
			pass
		reqcnt0 = st.count('0') - mins
	else:
		reqcnt0 = 0
	print(reqcnt0)


def solve():
	s = input()
	s_list = []
	for i in s:
		if i == '0':
			s_list.append(-1)
		else:
			s_list.append(100)
	best = 0
	total = 0
	start_ind = 0
	prev_best = 0
	for (ind, k) in enumerate(s_list):
		total = max(k, total + k)
		best = max(best, total)
		if best != 0 and prev_best == 0:
			start_ind = ind
		if best > prev_best:
			end_ind = ind
			prev_best = best
	if best == 0:
		return 0
	else:
		return s_list[start_ind:end_ind + 1].count(-1)
t = int(input())
for i in range(t):
	ans = solve()
	print(ans)


for i in range(int(input())):
	string = input()
	flag = 0
	ans = 0
	s = 0
	for j in string:
		if j == '1':
			flag = 1
			ans += s
			s = 0
		if flag and j == '0':
			s += 1
	print(ans)


def f():
	s = input('')
	c = 0
	d = 0
	k = 0
	if s.count('0') == len(s):
		print(0)
	else:
		for i in range(len(s)):
			if s[i] == '1':
				c = i
				break
		for j in range(len(s) - 1, c - 1, -1):
			if s[j] == '1':
				d = j
				break
		for i in range(c, d + 1):
			if s[i] == '0':
				k = k + 1
		print(k)
n = int(input(''))
for i in range(n):
	f()


for _ in range(int(input())):
	s = input()
	a = list(s.strip('0'))
	print(a.count('0'))


n = int(input())
for i in range(n):
	t = str(input())
	a1 = []
	if len(t) > 1:
		for i in range(len(t)):
			if t[i] == str(1):
				a1.append(i)
		if len(a1) > 0:
			s = a1[0]
			e = a1[-1]
			na = t[s:e + 1]
			t = na.count('0')
			print(t)
		else:
			print(0)
	else:
		print(0)


t = int(input())
for i in range(0, t):
	s = input()
	start = s.find('1')
	end = len(s) - s[::-1].find('1') - 1
	if start == -1 or end == -1:
		print(0)
	else:
		print(s.count('0', start, end))


t = int(input())
for i in range(t):
	s = input()
	f = -1
	l = -1
	cnt = 0
	for j in range(len(s)):
		if s[j] == '1':
			if f == -1:
				f = j
			l = j
		elif f != -1:
			cnt += 1
	if f == -1:
		print(0)
	else:
		print(cnt - len(s) + l + 1)


inp = input
li = list
iinp = lambda : int(inp())
ent = lambda : map(int, inp().split())
lient = lambda : [int(i) for i in inp().split()]
li0 = lambda x: [0 for i in range(x)]
stent = lambda : [i for i in inp()]
t = iinp()
for _ in range(t):
	s = inp()
	cont = 0
	tmp = 0
	ban = False
	for i in range(1, len(s)):
		if s[i] == '0' and s[i - 1] == '1':
			ban = True
			tmp += 1
		elif s[i] == '0' and ban:
			tmp += 1
		elif s[i] == '1' and ban:
			cont += tmp
			tmp = 0
			ban = False
	print(cont)


t = int(input())
for case in range(t):
	left = -1
	right = -1
	arr = input()
	n = len(arr)
	s = [a for a in arr]
	ans = 0
	for i in range(n):
		if s[i] == '1':
			left = i
			break
	for i in reversed(range(n)):
		if s[i] == '1':
			right = i
			break
	if left != -1:
		for i in range(left + 1, right):
			if s[i] == '0':
				ans += 1
	print(ans)


t = int(input())
l = []
for q in range(t):
	s = input()
	start = 0
	end = 0
	for i in range(len(s)):
		if s[i] == '1':
			start = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			end = i
			break
	count = 0
	for i in range(start, end):
		if s[i] == '0':
			count += 1
	print(count)


tests = int(input())
for _ in range(tests):
	s = input()
	res = 0
	(l, r) = (0, len(s) - 1)
	while l < r:
		if s[l] == '0':
			l += 1
		if l < r and s[r] == '0':
			r -= 1
		if s[l] == '1' and s[r] == '1':
			break
	print(len(s[l:r]) - s[l:r].count('1'))


for z in range(int(input())):
	n = input()
	ans1 = -1
	if len(n) == 0:
		print(0)
	for i in range(len(n)):
		if n[i] == '1':
			ans1 = i
			break
	ans2 = -1
	for i in range(len(n) - 1, -1, -1):
		if n[i] == '1':
			ans2 = i
			break
	count = 0
	if ans1 != -1 and ans2 != -1 and (ans1 != ans2):
		for i in range(ans1, ans2):
			if n[i] == '0':
				count = count + 1
	print(count)


num = int(input())
while num:
	str = input()
	lst = []
	count = 0
	for i in range(len(str)):
		if str[i] == '1':
			lst.append(i)
			count += 1
	v = 0
	for i in range(len(lst) - 1):
		v += lst[i + 1] - lst[i] - 1
	print(v)
	num = num - 1


t = int(input())
for i in range(t):
	x = str(input())
	x = x.rstrip('0')
	x = x.lstrip('0')
	if x.count('1') == 0:
		print(0)
	else:
		print(x.count('0'))


t = int(input())
for i in range(t):
	s = input()
	if '1' in s:
		l = s.index('1')
		if '1' in s[len(s) - 1:l:-1]:
			r = len(s) - s[len(s) - 1:l:-1].index('1')
		else:
			r = 0
		print(s[l:r].count('0'))
	else:
		print(0)


t = int(input())
while t:
	t -= 1
	l = []
	r = 0
	s = input()
	for i in range(len(s)):
		if s[i] == '1':
			l.append(i)
	for j in range(len(l) - 1):
		r += l[j + 1] - l[j] - 1
	print(r)


q = int(input(''))
for z in range(0, q):
	s = input('')
	p = 0
	l = 0
	i = 0
	j = 0
	t = 0
	for i in range(0, len(s)):
		if s[i] == '1' and p == 0:
			p = 1
		if s[i] == '0' and p == 1:
			l += 1
		if s[i] == '1' and p == 1:
			t = t + l
			l = 0
	print(t)


n = int(input())
for i in range(n):
	c = 0
	index = 0
	cb = 0
	cd = 0
	string = input()
	inputi = list(string)
	length = len(inputi)
	if inputi[0] == '1':
		for j in range(1, length):
			if inputi[j] == '0':
				c += 1
				index = j
				break
		if c == 1:
			for j in range(index, length):
				if inputi[j] == '1':
					cb += 1
					break
			if cb == 1:
				c = 0
				for j in range(1, length):
					if inputi[j] == '0':
						c += 1
				if inputi[-1] == '0':
					for j in range(length - 1, -1, -1):
						if inputi[j] == '0':
							cd += 1
						if inputi[j] == '1':
							break
				print(c - cd)
			else:
				print('0')
		else:
			print('0')
	else:
		cc = 0
		for j in range(1, length):
			if inputi[j] == '1':
				cc += 1
				index = j
				break
		if cc == 1:
			for j in range(index, length):
				if inputi[j] == '0':
					cc = 0
					break
			if cc == 0:
				for j in range(index, length):
					if inputi[j] == '0':
						c += 1
				if inputi[-1] == '0':
					for j in range(length - 1, -1, -1):
						if inputi[j] == '0':
							cb += 1
						if inputi[j] == '1':
							break
				print(c - cb)
			else:
				print('0')
		else:
			print('0')


tests = int(input())
for test in range(tests):
	print(input().strip('0').count('0'))


t = int(input())
for i in range(t):
	s = input()
	found = False
	start = 0
	end = 0
	for i in range(len(s)):
		if s[i] == '1':
			end = i
			if not found:
				start = i
				found = True
	if not found:
		print(0)
	else:
		print(s[start:end + 1].count('0'))


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		S = input().strip()
		ans = 0
		tmp = 0
		f = False
		for (s, n) in zip(S, S[1:]):
			if f:
				tmp += 1
			if s == '0' and n == '1':
				f = False
				ans += tmp
				tmp = 0
			if s == '1' and n == '0':
				f = True
		print(ans)
main()


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


from sys import stdin, stdout
T = int(stdin.readline())
for i in range(T):
	s = stdin.readline()
	res = 0
	diff = s.rfind('1') - s.find('1') + 1
	count = s.count('1')
	stdout.write(str(0 if count == 0 else diff - count) + '\n')


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


t = int(input())
while t:
	a = input()
	i = 0
	j = len(a) - 1
	if int(a) == 0:
		print(0)
	else:
		while a[i] != '1':
			i += 1
		while a[j] != '1':
			j -= 1
		print(a[i:j + 1].count('0'))
	t -= 1


for _ in range(int(input())):
	n = input()
	if len(n) == 1:
		print(0)
	else:
		(start, last) = (0, len(n) - 1)
		while True:
			if n[start] != '1':
				start += 1
			if n[last] != '1':
				last -= 1
			if n[start] == '1' and n[last] == '1' or last == 0 or start == len(n) - 1:
				break
		c = 0
		for i in range(start, last):
			if n[i] == '0':
				c += 1
		print(c)


import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
	s = ns().strip('0')
	print(s.count('0'))
	return
T = ni()
for _ in range(T):
	solve()


class Solution(object):

	def erasing_zeroes(self, s: str) -> int:
		return s.strip('0').count('0')
for t in range(int(input())):
	print(Solution().erasing_zeroes(input()))


t = int(input())
for case in range(t):
	a = input()
	final = 0
	count = 0
	flag = 0
	for i in range(1, len(a)):
		if a[i] == '1' and a[i - 1] == '1':
			continue
		elif a[i] == '0' and a[i - 1] == '1':
			count += 1
			flag = 1
		elif a[i] == '0' and a[i - 1] == '0' and (flag == 1):
			count += 1
		elif a[i] == '1' and a[i - 1] == '0':
			final += count
			count = 0
			flag = 0
	print(final)


q = int(input())
while q:
	q += -1
	s = input()
	ind1 = -1
	ind2 = -1
	c = 0
	for i in range(len(s)):
		if s[i] == '1' and ind1 == -1:
			ind1 = i
		if s[i] == '1':
			ind2 = i
	for i in range(ind1, ind2):
		if s[i] == '0':
			c -= -1
	print(c)


T = int(input())
for i in range(T):
	string = input()
	a = []
	count = 0
	for i in range(len(string)):
		if string[i] == '1':
			a.append(i)
		else:
			continue
	for i in range(len(a) - 1):
		sum1 = a[i + 1] - a[i] - 1
		if sum1 == 0:
			continue
		else:
			count = count + sum1
	print(count)


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


t = int(input())
for i in range(t):
	s = input()
	j = 0
	while j < len(s) and s[j] == '0':
		j += 1
	if j == len(s):
		print(0)
	else:
		now = 0
		ans = 0
		while j < len(s):
			if s[j] == '0':
				now += 1
			else:
				ans += now
				now = 0
			j += 1
		print(ans)


for _ in range(int(input())):
	s = input()
	if set(s) == {'0'}:
		print('0')
		continue
	s = list(s)
	st = 0
	en = 0
	for i in range(len(s)):
		if s[i] == '1':
			st = i
			break
	for i in range(len(s)):
		if s[len(s) - i - 1] == '1':
			en = len(s) - i - 1
			break
	print(s[st:en + 1].count('0'))


t = int(input())
for _ in range(t):
	s = input()
	posn = []
	for i in range(len(s)):
		if s[i] == '1':
			posn.append(i)
	ans = 0
	for i in range(1, len(posn)):
		ans += posn[i] - posn[i - 1] - 1
	print(ans)


t = int(input().strip())
for i in range(t):
	n = input().strip()
	fOne = False
	lOne = False
	zero = False
	count = 0
	tot = 0
	for i in range(len(n)):
		if n[i] == '0' and fOne:
			zero = True
			count += 1
		elif n[i] == '1' and zero and fOne:
			lOne = True
			tot += count
			count = 0
			zero = False
		elif fOne and lOne and (n[i] == '1'):
			zero = False
			lOne = False
		elif n[i] == '1' and (not fOne):
			fOne = True
	print(tot)


for t in range(int(input())):
	s = input()
	b = False
	tot = 0
	cur = 0
	for c in s:
		if c == '0':
			cur += 1
		elif b:
			tot += cur
			cur = 0
		else:
			b = True
			cur = 0
	print(tot)


for _ in range(int(input())):
	s = list(input())
	while s and s[0] == '0':
		s.pop(0)
	while s and s[-1] == '0':
		s.pop(-1)
	c = 0
	for i in s:
		if i == '0':
			c += 1
	print(c)


for _ in range(int(input())):
	li = list(input())
	n = len(li)
	cnt = 0
	m = 0
	fg1 = 0
	fg2 = 0
	for i in range(n):
		if li[i] == '1':
			if fg1 == 0:
				fg1 = 1
			elif fg2 == 0:
				fg2 = 1
			if fg1 == 1 and fg2 == 1:
				cnt += m
				fg1 = 1
				fg2 = 0
				m = 0
		if li[i] == '0':
			if fg1 == 1 and fg2 == 0:
				m += 1
	print(cnt)


T = int(input())
for i in range(T):
	a = list(map(int, input().split()))
	if len(a) == 1 and a[0] == 1 or a[0] == 0:
		print(0)
	else:
		cc = 0
		l1 = []
		aa = [int(i) for i in str(*a)]
		if len(set(aa)) == 1:
			print(0)
			continue
		else:
			for i in range(len(aa)):
				if aa[i] == 1:
					l1.append(i)
				else:
					pass
			for j in range(len(l1) - 1):
				s = l1[j + 1] - l1[j]
				if s != 1:
					cc += s - 1
				else:
					pass
			print(cc)


for o in range(int(input())):
	s = input()
	dic = {1: []}
	if len(s) == 1 and (s[0] == 0 or s[0] == 1):
		print(0)
	else:
		for i in range(len(s)):
			if s[i] == '1':
				dic[1].append(i)
		c = 0
		for i in range(len(dic[1]) - 1):
			if dic[1][i + 1] - dic[1][i] > 1:
				c = c + dic[1][i + 1] - dic[1][i] - 1
		print(c)


for _ in range(int(input())):
	s = input()
	l = s.find('1')
	r = s.rfind('1')
	print(0 if r <= l else s.count('0', l, r))


t = int(input())
for i in range(t):
	s = input()
	a = list(s)
	b = []
	c = 0
	k = 0
	c1 = a.count('1')
	for j in range(len(a)):
		if a[j] == '1':
			k = 1
			while c < c1 and j != len(a) - 1:
				if a[j] == '1':
					c = c + 1
				b.append(a[j])
				j = j + 1
		if k == 1:
			break
	print(b.count('0'))


for u in range(int(input())):
	ka = input().strip('0')
	print(ka.count('0'))


t = int(input())
if t in range(101):
	for case in range(t):
		s = input()
		if len(s) in range(1, 101):
			count = 0
			zeros = 0
			counting = False
			for c in s:
				if c == '0' or c == '1':
					if counting:
						if c == '0':
							count += 1
						else:
							zeros += count
							count = 0
					elif c == '1':
						counting = True
				else:
					break
			print(zeros)


t = int(input())
for _ in range(t):
	s = input()
	if '1' not in s:
		print(0)
		continue
	first_index = s.find('1')
	last_index = s.rfind('1')
	ret = 0
	i = first_index
	while i < last_index:
		if s[i] == '0':
			ret += 1
		i += 1
	print(ret)


n = int(input())
for i in range(n):
	a = input()
	b = a
	if '1' in a:
		z = a.index('1')
		a = a[::-1]
		x = a.index('1')
		q = b[z:len(a) - x]
		print(q.count('0'))
	else:
		print(0)


def Main():
	case = int(input())
	while case > 0:
		lin = input()
		if len(lin) > 1:
			n = countCero(lin)
			print(n)
		else:
			print(0)
		case -= 1

def countCero(l):
	n = len(l)
	b = -1
	count = 0
	for i in range(n):
		if i == 0 and l[i] == '1':
			b = i
		elif l[i] == '1':
			if b != -1 and i - b > 0:
				count = count + (i - b - 1)
				b = i
			else:
				b = i
	return count
Main()


t = int(input())
q = []
for i in range(t):
	step = 0
	s = input()
	s = [int(j) for j in s]
	r = 0
	if sum(s) == 0:
		q.append(0)
	else:
		while 1:
			if s[0] == 0:
				s.remove(s[0])
			else:
				break
		for j in s:
			if j == 1:
				r += 1
			else:
				step += 1
			if r == sum(s):
				q.append(step)
				break
for i in q:
	print(i)


def main():
	t = int(input())
	while t:
		s = input()
		(l, r, c) = (s.find('1'), s.rfind('1'), 0)
		for i in range(l, r):
			if s[i] == '0':
				c += 1
		print(c)
		t -= 1
main()


n = int(input())
for i in range(n):
	l = []
	d = 0
	s = str(input())
	for j in range(0, len(s)):
		if s[j] == '1':
			l.append(j)
	if len(l) == 0 or len(l) == 1:
		print(0)
	else:
		for j in range(0, len(l) - 1):
			d = d + (l[j + 1] - l[j] - 1)
		print(d)


for i in range(int(input())):
	word = input()
	(zc, pl, sl) = (0, 0, 0)
	zc = word.count('0')
	if zc != len(word):
		pl = word.index('1')
		sl = len(word) - word.rindex('1') - 1
		print(zc - pl - sl)
	else:
		print(0)


from collections import deque

def count_minimum(strs):
	if strs.count('1') == 0:
		return 0
	idx = strs.find('1')
	ns = strs[idx:]
	q = deque(ns)
	cnt = 0
	while q:
		ch = q.popleft()
		if ch == '0' and q.count('1') > 0:
			cnt += 1
	return cnt
t = int(input())
while t:
	string = input()
	result = count_minimum(string)
	print(result)
	t -= 1


t = int(input())
while t > 0:
	s = input()
	if len(s) > 2:
		i = s.find('1')
		j = s.rfind('1')
		l = s[i:j]
		print(l.count('0'))
	else:
		print('0')
	t -= 1


def erasePreZeros(s):
	if s[0] == '1':
		return s
	return erasePreZeros(s[1:])

def erasePostZeros(s):
	return erasePreZeros(s[::-1])

def countIntermediateZeros(s):
	IntermediateString = erasePostZeros(erasePreZeros(s))
	continousString = '1' * len(IntermediateString)
	return len([i for i in range(len(IntermediateString)) if IntermediateString[i] != continousString[i]])
test_cases = int(input())
for i in range(test_cases):
	s = input()
	if len(s) == s.count('0'):
		print(0)
	else:
		print(countIntermediateZeros(s))


t = int(input())
for i in range(t):
	str = list(input())
	for j in range(len(str)):
		if str[j] == '1':
			break
	for k in range(len(str) - 1, -1, -1):
		if str[k] == '1':
			break
	str = str[j:k]
	count = 0
	for j in str:
		if j == '0':
			count = count + 1
	if count == len(str):
		count = 0
	print(count)


for _ in range(int(input())):
	s = input()
	if s.find('1') == -1:
		print(0)
	else:
		print(s[s.find('1'):s.rindex('1')].count('0'))


import sys
import math
import heapq
import bisect
import re
from collections import deque
from decimal import *
from fractions import gcd

def no():
	print('NO')

def dist(z, c):
	return (z[0] - c[0]) * (z[0] - c[0]) + (z[1] - c[1]) * (z[1] - c[1])

def vec(z, c):
	return z[0] * c[1] - z[1] * c[0]

def pro(z, c):
	return [z[0] - c[0], z[1] - c[1]]

def main():
	s = sys.stdin.readline()
	n = len(s)
	(r, l, o) = (-1, -1, 0)
	for i in range(n):
		if s[i] == '1':
			r = i
			o += 1
			if l == -1:
				l = i
	if l == -1:
		print(0)
		return 0
	print(r - l - o + 1)
for i in range(int(sys.stdin.readline())):
	main()


t = int(input())
for ii in range(0, t):
	s = input()
	ans = 0
	last = 0
	for j in reversed(range(len(s))):
		if s[j] == '1':
			last = j
			break
	for i in range(len(s)):
		if s[i] == '1':
			for k in range(i, last):
				if s[k] == '0':
					ans += 1
			break
	print(ans)


from sys import stdin, stdout
T = int(input())
for t in range(T):
	a = input()
	(l, r) = (-1, -1)
	for i in range(len(a)):
		if a[i] == '1':
			if l == -1:
				l = i
			r = i
	if l == -1:
		print(0)
		continue
	ans = 0
	for i in range(l, r + 1):
		if a[i] == '0':
			ans += 1
	print(ans)


t = int(input())
while t:
	t -= 1
	s = input()
	slen = len(s)
	le = 0
	ri = slen - 1
	for i in range(slen):
		le = i
		if s[i] == '1':
			break
	for i in range(slen - 1, -1, -1):
		ri = i
		if s[i] == '1':
			break
	if le >= ri:
		print(0)
	else:
		ans = 0
		for i in range(le, ri + 1):
			if s[i] == '0':
				ans += 1
		print(ans)


t = int(input())
for i in range(t):
	s = input()
	l = 0
	r = 0
	ans = 0
	ss = 0
	for j in range(len(s)):
		if s[j] == '1':
			l = j
			break
	for j in range(len(s) - 1, -1, -1):
		if s[j] == '1':
			r = j
			break
	for j in range(len(s)):
		if s[j] == '1':
			ss += 1
	if ss != 0:
		ans = r - l - ss + 1
	else:
		ans = 0
	print(ans)


n = int(input())
for i in range(n):
	s = input()
	l = 0
	e = -1
	temp = 0
	for j in range(len(s)):
		if s[j] == '1':
			l = j
			temp = 1
			break
	if temp == 0 or l == len(s) - 1:
		print('0')
	else:
		cnt = 1
		for j in range(l + 1, len(s)):
			if s[j] == '1':
				e = j
				cnt += 1
		if e == -1:
			print(0)
		else:
			print(e - l + 1 - cnt)


for i in range(int(input())):
	n = input()
	i = 0
	while i < len(n) and n[i] == '0':
		i += 1
	j = len(n) - 1
	while j >= 0 and n[j] == '0':
		j -= 1
	print(n[i:j].count('0'))


for _ in range(int(input())):
	s = input()
	cnt = 0
	li = -1
	le = ''
	for i in range(len(s)):
		if li != -1 and le == '0' and (s[i] == '1'):
			cnt += i - li - 1
		if s[i] == '1':
			li = i
		le = s[i]
	print(cnt)


def dezero(s):
	on = False
	zero = 0
	zeroTo1 = 0
	for ch in s:
		if ch == '0':
			if on:
				zero += 1
		else:
			on = True
			zeroTo1 = zero
	return zeroTo1
n = int(input())
answers = [0] * n
for i in range(n):
	answers[i] = dezero(input())
for answer in answers:
	print(answer)


for i in range(int(input())):
	arr = input()
	a = []
	sum = 0
	for j in range(0, len(arr)):
		if arr[j] == '1':
			a.append(j)
	for j in range(len(a) - 1):
		sum = sum + (a[j + 1] - a[j] - 1)
	print(sum)


def solve(s):
	n = len(s)
	i = 0
	j = n - 1
	while i < n and s[i] == '0':
		i += 1
	while j >= 0 and s[j] == '0':
		j -= 1
	ans = 0
	for k in range(i + 1, j):
		if s[k] == '0':
			ans += 1
	return ans
t = int(input().strip())
while t:
	s = input().strip()
	print(solve(s))
	t -= 1


for _ in range(int(input())):
	string = input()
	ans = 0
	index = None
	for i in range(len(string)):
		if string[i] == '1':
			index = i
			break
	if index is not None:
		temp = 0
		for i in range(index + 1, len(string)):
			if string[i] == '0':
				temp += 1
			else:
				ans += temp
				temp = 0
	print(ans)


t = int(input())
for i in range(1, t + 1):
	print(input().strip('0').count('0'))


T = int(input())
L = []
for i in range(T):
	L = list(map(str, input()))
	res = 0
	n = 0
	num = L.count('1')
	if num != 0:
		j = L.index('1')
		while j < len(L) and n < num:
			if L[j] == '1':
				n += 1
			elif L[j] == '0':
				res += 1
			j += 1
	print(res)


t = int(input())
for i in range(t):
	a = input()
	c = 0
	b = []
	for j in range(len(a)):
		if a[j] == '0':
			c = c + 1
		else:
			b.append(c)
			c = 0
	b.append(c)
	d = sum(b)
	if a[0] == '0':
		d = d - b[0]
	if a[-1] == '0':
		d = d - b[-1]
	print(max(d, 0))


a = int(input())
for i in range(a):
	s = input()
	ans = []
	total = 0
	for i in range(len(s)):
		if s[i] == '1':
			ans.append(i)
	for i in range(1, len(ans)):
		total = total + (ans[i] - ans[i - 1] - 1)
	print(total)


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


n = int(input())
outputs = []
for i in range(n):
	str = input()
	while str[0] == '0' and len(str) > 1:
		str = str[1:]
	while str[-1] == '0' and len(str) > 1:
		str = str[0:len(str) - 1]
	sum = 0
	if len(str) > 1:
		for j in range(len(str)):
			if str[j] == '0':
				sum += 1
	outputs.append(sum)
for i in range(n):
	print(outputs[i])


for _ in range(int(input())):
	s = input()
	idx = []
	for i in range(len(s)):
		if s[i] == '1':
			idx.append(i)
	if len(idx) <= 1:
		print(0)
		continue
	else:
		mx = 0
		for i in range(len(idx) - 1):
			mx += idx[i + 1] - idx[i] - 1
		print(mx)


for _ in range(int(input())):
	a = 0
	n = input()
	i = 0
	l = len(n)
	el = -1
	while i < l:
		if n[i] == '1':
			el = i
			break
		i += 1
	r = -1
	i = l - 1
	while i >= 0:
		if n[i] == '1':
			r = i
			break
		i -= 1
	if el != -1:
		print(n[el:r].count('0'))
	else:
		print(0)


def main():
	for _ in range(int(input())):
		s = input()
		ans = 0
		d1 = 0
		d2 = 0
		t = 0
		for i in range(len(s)):
			if s[i] == '0':
				ans += 1
			if s[i] == '1':
				t += 1
			if not t:
				d1 += 1
		if t < 2:
			print(0)
			continue
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '1':
				break
			d2 += 1
		print(ans - d1 - d2)
main()


t = int(input())
for i in range(t):
	s = input()
	n = len(s)
	(j, k) = (0, n - 1)
	while j < n and s[j] == '0':
		j += 1
	while k >= j and s[k] == '0':
		k -= 1
	x = 0
	for p in range(j, k + 1):
		if s[p] == '0':
			x += 1
	print(x)


for i in range(int(input())):
	s = input()
	if s.find('1') >= 0:
		print(s[s.find('1'):s.rfind('1')].count('0'))
	else:
		print(0)


n = int(input())
for t in range(n):
	inpStr = input()
	a = inpStr.find(str(1))
	if a != -1:
		b = inpStr.count('1')
		answer = 0
		for i in range(a, len(inpStr)):
			if inpStr[i] != '1' and b > 0:
				answer += 1
			else:
				b -= 1
		print(answer)
	else:
		print(0)


t = int(input())
for i in range(t):
	s = input()
	i = 0
	l = len(s)
	while i < l and s[i] == '0':
		i += 1
	j = l - 1
	while i <= j and s[j] == '0':
		j -= 1
	c = 0
	while i <= j:
		if s[i] == '0':
			c += 1
		i += 1
	print(c)


def remove_side_zeros(case):
	left_index = 0
	for character in case:
		if character == '1':
			break
		left_index += 1
	case = case[left_index:]
	right_index = len(case)
	for index in range(len(case)):
		if case[right_index - 1] == '0':
			right_index -= 1
		else:
			break
	case = case[:right_index]
	return case

def count_number_of_zeros(case):
	number_of_zeros = 0
	for character in case:
		if character == '0':
			number_of_zeros += 1
	return number_of_zeros
test_number = int(input())
for i in range(test_number):
	case = input()
	case_without_side_zeros = remove_side_zeros(case)
	number_of_zeros = count_number_of_zeros(case_without_side_zeros)
	print(number_of_zeros)


t = int(input())
for i in range(t):
	s = input()
	minToErase = s.count('0')
	for x in s:
		if x == '1':
			break
		minToErase -= 1
	if minToErase > 0:
		for x in reversed(s):
			if x == '1':
				break
			minToErase -= 1
	print(minToErase)


for _ in range(int(input())):
	s = input()
	flag = 0
	count = 0
	total = 0
	N = len(s)
	for i in range(N - 1):
		if s[i] == '1':
			count = 0
			for j in range(i + 1, N):
				if s[j] == '0':
					count += 1
				else:
					total += count
					break
	print(total)


for _ in range(int(input())):
	s = str(input())
	fir = -1
	las = -1
	c = 1
	for i in range(len(s)):
		if s[i] == '1':
			fir = i
			las = i
			break
	for i in range(fir + 1, len(s)):
		if s[i] == '1':
			c += 1
			las = i
	print(las - fir + 1 - c)


n = int(input())
for i in range(n):
	st = input()
	l1 = []
	count = 0
	for i in range(len(st)):
		if st[i] == '1':
			l1.append(i)
	if len(l1) > 1:
		for i in range(len(l1) - 1):
			count += abs(l1[i] - l1[i + 1]) - 1
	print(count)


from itertools import groupby
for _ in range(int(input())):
	st = input()
	if st.count('1') < 2:
		print(0)
	else:
		st = st[st.find('1'):st.rindex('1') + 1]
		ans = 0
		for (key, group) in groupby(st):
			if key == '0':
				ans += len(list(group))
		print(ans)


t = int(input())
for q in range(t):
	s = input()
	l = -1
	for i in range(len(s)):
		if s[i] == '1':
			l = i
			break
	if l != -1:
		r = -1
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '1':
				r = i
				break
	if l != -1 and r != -1:
		ans = 0
		for i in range(l, r + 1):
			if s[i] == '0':
				ans += 1
		print(ans)
	else:
		print(0)


T = int(input())
for i in range(T):
	string = input()
	j = 0
	k = len(string) - 1
	while string[j] == '0' and j < len(string) - 1:
		j += 1
	while string[k] == '0' and k >= 0:
		k -= 1
	sol = 0
	for l in range(j, k + 1):
		if string[l] == '0':
			sol += 1
	print(sol)


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


for _ in range(int(input())):
	s = input()
	x = s.find('1')
	y = s.rfind('1')
	print(s[x:y + 1].count('0'))


for i in range(int(input())):
	s = list(input())
	if s.count('0') == 0 or s.count('1') == 0:
		print(0)
	else:
		while 1:
			if s[0] == '0':
				s.pop(0)
			else:
				break
		while 1:
			if s[-1] == '0':
				s.pop()
			else:
				break
		print(s.count('0'))


t = int(input())
for i in range(0, t):
	data = input()
	temp = tmp = data.split('0')
	for i in range(len(tmp)):
		if tmp[i] != '':
			temp = tmp[i:]
			break
		if i == len(tmp) - 1:
			temp = ['']
	tmp = temp
	for i in range(len(tmp) - 1, -1, -1):
		if tmp[i] != '':
			temp = tmp[:i + 1]
			break
	print(len(temp) - 1)


for _ in '0' * int(input()):
	s = input()
	j = -1
	z = -1
	c = s.count('1')
	for i in range(len(s)):
		if s[i] == '1':
			j = i
			break
	for i in range(len(s)):
		if s[-i - 1] == '1':
			z = len(s) - i
			break
	print(z - j - c)


for _ in range(int(input())):
	s = input()
	count1 = s.count('1')
	(y, x) = (0, 0)
	for i in range(0, len(s)):
		if s[i] == '1':
			x = i
			break
	for i in range(0, len(s)):
		if s[len(s) - 1 - i] == '1':
			y = len(s) - i - 1
			break
	if count1 != 0:
		print(y - x - count1 + 1)
	else:
		print('0')


def min_erase(s):
	l = -1
	r = -1
	n = len(s)
	for i in range(n):
		if s[i] == '1':
			l = i
			break
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			r = j
			break
	cnt = 0
	if l == -1 or r == -1:
		return 0
	for k in range(l, r + 1):
		if s[k] == '0':
			cnt += 1
	return cnt
t = int(input())
for _ in range(t):
	s = input()
	ans = min_erase(s)
	print(ans)


def answer():
	a = int(input())
	while a:
		b = list(input())
		b = [int(x) for x in b]
		i = 0
		ans = 0
		while i < len(b) - 1:
			if b[i] and (not b[i + 1]):
				j = i + 1
				temp = 0
				while j < len(b) and b[j] != 1:
					temp += 1
					j += 1
				if j == len(b):
					temp = 0
				elif b[j] == 1:
					ans += temp
				j = i
				j -= 1
			i += 1
		print(ans)
		a -= 1
answer()


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

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

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

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007

def solve():
	t = nu()
	for tt in range(t):
		s = input()
		ff = -1
		ll = -1
		for i in range(len(s)):
			if s[i] == '1':
				ff = i
				break
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '1':
				ll = i
				break
		if ff == -1:
			print(0)
		else:
			xp = s[ff:ll + 1]
			print(xp.count('0'))
solve()


def fun(s):
	if '1' in s:
		st = s.index('1')
		en = len(s) - s[::-1].index('1') - 1
		print(s[st:en + 1].count('0'))
	else:
		print('0')
for _ in range(int(input())):
	s = input()
	fun(s)


t = int(input())
for i in range(0, t):
	s = input()
	r = 0
	l = 0
	res = 0
	for i in range(0, len(s)):
		if s[i] == '1':
			l = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			r = i
			break
	for i in range(l + 1, r + 1):
		if s[i] == '0':
			res += 1
	print(res)


for _ in range(int(input())):
	s = input()
	mc = 0
	ind = -1
	l = len(s)
	for i in range(l - 1):
		if s[i] == '1':
			ind = i
			break
	if ind == -1:
		print('0')
	else:
		c = 0
		for i in range(ind + 1, l - 1):
			if s[i] != '1':
				c += 1
			else:
				mc += c
				c = 0
		if s[-1] == '1':
			mc += c
		print(mc)


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


t = int(input())
for i in range(0, t):
	s = str(input())
	s = list(s)
	a = []
	for j in range(0, len(s)):
		if s[j] == '1':
			a.append(j)
	b = []
	if len(a) == 1:
		print(0)
	else:
		for j in range(0, len(a) - 1):
			b.append(a[j + 1] - a[j] - 1)
		print(sum(b))


t = int(input())
for i in range(t):
	s = str(input())
	if s.count('1') < 2:
		print(0)
	else:
		x1 = s.index('1')
		s = s[::-1]
		x2 = len(s) - s.index('1')
		print(x2 - x1 - s.count('1'))


for _ in range(int(input())):
	count = 0
	b = 0
	e = 0
	s = input()
	for i in range(len(s)):
		if s[i] == '1':
			b = i
			break
	for j in range(len(s) - 1, 0, -1):
		if s[j] == '1':
			e = j
			break
	for k in range(b, e):
		if s[k] == '0':
			count += 1
	print(count)


def remove_zero(listed):
	result = 0
	found = False
	temp = 0
	for i in listed:
		if i == 0 and found:
			temp += 1
		elif i == 1 and (not found):
			found = True
		if i == 1:
			result += temp
			temp = 0
	return result
useless = int(input())
for i in range(useless):
	string = [int(i) for i in input()]
	print(remove_zero(string))


for __ in range(int(input())):
	n = input()
	flag = 0
	cnt = 0
	left = 0
	right = len(n) - 1
	while n[left] == '0' and left < right:
		left += 1
	while n[right] == '0' and left < right:
		right -= 1
	while left < right:
		if n[left] != '1':
			cnt += 1
		left += 1
	print(cnt)


t = int(input())
for _ in range(t):
	s = input()
	f = -1
	count = 0
	for i in range(len(s)):
		if s[i] == '1':
			f = i
		elif f != -1:
			count += 1
	print(max(0, count - len(s) + f + 1))


n = int(input())
for i in range(n):
	s = input()
	k = len(s)
	a = 0
	b = k - 1
	if '1' in s:
		while a < k and s[a] == '0':
			a += 1
		while b >= 0 and s[b] == '0':
			b -= 1
		print(b - a + 1 - s[a:b + 1].count('1'))
	else:
		print(0)


t = int(input())
pr = []
for i in range(t):
	s = input()
	s = s.strip('0').count('0')
	pr.append(s)
for j in pr:
	print(j)


tests = int(input())
for i in range(tests):
	binary = [int(i) for i in input()]
	try:
		first = binary.index(1)
		binary.reverse()
		last = len(binary) - binary.index(1)
		binary.reverse()
		print(binary[first:last].count(0))
	except:
		print(0)


def last1(s):
	for i in range(len(s) - 1, 0 - 1, -1):
		if s[i] == '1':
			return i

def first1(s):
	for i in range(0, len(s)):
		if s[i] == '1':
			return i
test = int(input())
for index in range(test):
	s = input()
	if len(s) < 3 or s.count('1') == 0 or s.count('1') == len(s):
		print('0')
	else:
		print(last1(s) - first1(s) - s.count('1') + 1)


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


for _ in range(int(input())):
	s = input()
	ones = s.count('1')
	if ones:
		left = 0
		while s[left] == '0':
			left += 1
		right = len(s) - 1
		while s[right] == '0':
			right -= 1
		print(right - left + 1 - ones)
	else:
		print(0)


test = int(input())
j = 0
while j < test:
	str = input()
	i = 0
	begin = 0
	end = len(str) - 1
	while i < len(str):
		if str[i] == '1':
			begin = i
			break
		i += 1
	i = len(str) - 1
	while i >= 0:
		if str[i] == '1':
			end = i
			break
		i -= 1
	str = str[begin:end + 1]
	count = 0
	if str[0] == '1':
		for i in str:
			if i == '0':
				count += 1
	print(count)
	j += 1


for _ in range(int(input())):
	s = input()
	l = 0
	i = 0
	c = 0
	for p in s:
		if p == '1':
			c += 1
	if c == 0:
		print('0')
	else:
		while s[i] != '\x00':
			if s[i] == '1':
				l = i
				break
			i += 1
		j = len(s) - 1
		if s[j] == '1':
			r = j
		else:
			while s[j] != '1':
				j -= 1
		count = 0
		for x in range(i, j):
			if s[x] == '0':
				count += 1
		print(count)


t = int(input())
for i in range(t):
	s = input()
	leng = len(s)
	for j in range(leng):
		a = s.find('1')
		b = s.rfind('1')
		count = 0
		for k in range(a, b):
			if s[k] == '0':
				count += 1
	print(count)


t = int(input())
while t > 0:
	t -= 1
	s = input()
	sp = s.split('1')[1:-1]
	ans = 0
	for p in sp:
		ans += len(p)
	print(ans)


def solve():
	s = input()
	first_one = False
	remove_count = 0
	current_count = 0
	for (i, s_i) in enumerate(s):
		if s_i == '1':
			first_one = True
			remove_count += current_count
			current_count = 0
		elif first_one:
			current_count += 1
	print(remove_count)

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


def Input():
	tem = input().split()
	ans = []
	for it in tem:
		ans.append(int(it))
	return ans
from collections import Counter
n = Input()[0]
for i in range(n):
	s = input()
	m = len(s)
	(i, j) = (0, m - 1)
	while i < m and s[i] == '0':
		i += 1
	while j >= 0 and s[j] == '0':
		j -= 1
	ma = Counter(s[i:j + 1])
	if '0' not in ma:
		print(0)
	else:
		print(ma['0'])


tt = int(input())
while tt > 0:
	st = input()
	i = 0
	start = 0
	end = 0
	c = 0
	while i < len(st):
		if st[i] == '1':
			start = i
			break
		i += 1
	while i < len(st):
		if st[i] == '1':
			end = i
		i += 1
	for i in range(start + 1, end + 1):
		if st[i] == '0':
			c += 1
	print(c)
	tt -= 1


T = int(input())
for i in range(T):
	s = input()
	ans = 0
	flag = False
	f1 = 0
	l1 = 0
	for i in range(len(s)):
		if s[i] == '1':
			f1 = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			l1 = i
			break
	print(s[f1:l1].count('0'))


n = int(input())
for i in range(n):
	line = list(input().strip('0'))
	is_zero = 0
	for e in line:
		if e == '0':
			is_zero += 1
	print(is_zero)


def solve(s):
	oc = []
	for x in range(len(s)):
		if s[x] == '1':
			oc.append(x)
	temp = []
	for i in range(len(oc) - 1):
		temp.append(oc[i + 1] - oc[i])
	moves = 0
	for k in range(len(temp)):
		if temp[k] != 1:
			moves += temp[k] - 1
	return moves

def main():
	n = int(input())
	while n != 0:
		s = input()
		print(solve(s))
		n = n - 1
main()


n = int(input())
c = '1'
d = '0'
for i in range(n):
	s = list(input())
	if c in s:
		l = s.index(c)
		s.reverse()
		r = s.index(c)
		total = s.count(d) - l - r
		print(total)
	else:
		print(0)


t = int(input())
for h in range(t):
	s = input()
	if '1' not in s:
		print(0)
	else:
		st1 = s.index('1')
		for i in range(len(s)):
			if s[i] == '1':
				end1 = i
		s = s[st1:end1]
		l = s.replace('0', '')
		print(len(s) - len(l))


t = int(input())
while t > 0:
	t -= 1
	s = input()
	k = 0
	c = 0
	sum = 0
	l = 0
	for i in s:
		if i == '0':
			l = 0
			if k == 0:
				continue
			else:
				c += 1
		else:
			k = 1
			if l == 0:
				sum = sum + c
				c = 0
				l = 1
	print(sum)


n = int(input())
for _ in range(n):
	s = input()
	(f, e) = [0, 0]
	if '1' not in s:
		print(0)
		continue
	for (i, x) in enumerate(s):
		if x == '1':
			f = i
			break
	s = s[f:]
	s = s[::-1]
	for (i, x) in enumerate(s):
		if x == '1':
			e = i
			break
	s = s[e:]
	ans = s.count('0')
	print(ans)


t = int(input())
while t > 0:
	s = list(input())
	k = s.count('1')
	ans = 0
	for i in range(len(s)):
		if s[i] == '1':
			k -= 1
			for j in range(i + 1, len(s)):
				if k == 0:
					break
				elif s[j] == '1':
					k -= 1
				else:
					s[j] == '0'
					ans += 1
			break
	print(ans)
	t -= 1


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(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

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

def ntl(n):
	return [int(i) for i in str(n)]

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 gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

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 read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	for _ in range(ii()):
		s = si()
		n = len(s)
		a = -1
		f = 0
		b = -1
		for i in range(n):
			if s[i] == '1' and f == 0:
				a = i
				f = 1
			if s[i] == '1':
				b = i
		c = s.count('1')
		if a == -1 and b == -1:
			print(0)
			continue
		if a == b:
			print(0)
			continue
		print(b - a - c + 1)
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 sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
n = int(input())
for _ in range(n):
	s = input()
	start = last = -1
	ctr = 0
	for (i, c) in enumerate(s):
		if start < 0 and c == '1':
			start = i
		if c == '1':
			last = i
			ctr += 1
	if start < 0:
		print(0)
	else:
		print(last - start + 1 - ctr)


for _ in range(int(input())):
	s = input()
	t = 0
	c = 0
	l = 'start'
	for char in s:
		if char == l:
			c += 1
			l = char
		elif char == '0' and l == 'start':
			l = 'start'
		else:
			if l == '0':
				t += c
			c = 1
			l = char
	print(t)


for _ in range(int(input())):
	s = input()
	i = 0
	l = len(s)
	while i < l:
		if s[i] == '1':
			break
		i += 1
	j = l - 1
	while j > -1:
		if s[j] == '1':
			break
		j -= 1
	s = s[i:j + 1]
	print(s.count('0'))


t = int(input())
for q in range(t):
	s = str(input())
	pos = []
	n = len(s)
	for i in range(n):
		if s[i] == '1':
			pos.append(i + 1)
	ans = 0
	for i in range(len(pos) - 1):
		ans += pos[i + 1] - pos[i] - 1
	print(ans)


s = input()
while True:
	try:
		s = input()
		z = 0
		r = 0
		for i in s:
			if i == '0':
				z += 1
		for i in s:
			if i == '1':
				break
			r += 1
		for i in s[::-1]:
			if i == '1':
				break
			r += 1
		print(max(0, z - r))
	except:
		break


q = int(input())
for _ in range(q):
	s = list(input())
	n = len(s)
	k = -1
	for i in range(n):
		if s[i] == '1':
			k = i
			break
	l = -1
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			l = i
			break
	ans = 0
	for i in range(k, l):
		if s[i] == '0':
			ans += 1
	print(ans)


for _ in range(int(input())):
	s = input()
	a = 0
	b = 0
	for i in range(len(s)):
		if s[i] == '1':
			a = i
			break
	for j in range(len(s) - 1, -1, -1):
		b += 1
		if s[j] == '1':
			break
	c = s.count('1')
	if c > 0:
		ans = len(s) - a - (b - 1) - c
	else:
		ans = 0
	print(ans)


def erasing_zeros():
	for i in range(int(input())):
		inp = input().strip('0')
		print(inp.count('0'))
erasing_zeros()


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()):
	a = si()
	c = 0
	if a.find('1') == -1:
		print('0')
	else:
		l = ''.join(reversed(a))
		n = a.index('1')
		p = len(a) - l.index('1')
		for i in range(n, p):
			if a[i] == '0':
				c = c + 1
		print(c)


t = int(input())
for g in range(0, t):
	s = input()
	a = []
	for i in range(0, len(s)):
		if s[i] == '1':
			a.append(i)
	result = 0
	if len(a) == 1:
		print(0)
	else:
		for i in range(0, len(a) - 1):
			result = result + a[i + 1] - a[i] - 1
		print(result)


for _ in range(int(input())):
	n = input().strip('0')
	c = 0
	for i in range(len(n) - 1):
		if n[i] == '1' and n[i + 1] == '0' or (n[i] == '0' and n[i + 1] == '0'):
			c += 1
	print(c)


queries = int(input())
for _ in range(queries):
	wasOne = False
	word = input()
	counter = 0
	result = 0
	for char in word:
		if wasOne:
			if char == '0':
				counter += 1
		if char == '1':
			wasOne = True
			result += counter
			counter = 0
	print(result)


n = int(input())
for i in range(n):
	l = []
	a = 0
	p = list(input())
	count_1 = p.count('1')
	if count_1 >= 2:
		for j in range(0, len(p)):
			if p[j] == '1':
				a = j + 1
				l.append(a)
				break
		b = 0
		for j in range(len(p) - 1, -1, -1):
			if p[j] == '1':
				b = j + 1
				l.append(b)
				break
		count = 0
		l_a = l[0]
		l_b = l[1]
		for j in range(l_a - 1, l_b):
			if p[j] == '0':
				count += 1
	elif count_1 < 2:
		count = 0
	print(count)


n = int(input())
for i in range(n):
	a = input()
	if a.count('1') <= 1:
		print(0)
	else:
		first = a.index('1')
		last = 0
		for i in range(len(a)):
			if a[i] == '1':
				last = i
		count = 0
		for i in a[first:last]:
			if i == '0':
				count += 1
		print(count)


from collections import *
from bisect import *
for _ in range(int(input())):
	l = list(input())
	n = len(l)
	ans = 0
	cnt = 0
	i = 0
	while i < n:
		if l[i] == '1':
			j = i
			val = 0
			while j < n and l[j] == '1':
				j += 1
			while j < n and l[j] == '0':
				val += 1
				j += 1
			if j < n and l[j] == '1':
				ans += val
			cnt += 1
			i = j
		else:
			i += 1
	if cnt > 1:
		print(ans)
	else:
		print(0)


n = int(input())
for i in range(n):
	s = input()
	j = 0
	while j < len(s) and s[j] == '0':
		j += 1
	c1 = j
	j = len(s) - 1
	while j >= 0 and s[j] == '0':
		j -= 1
	c2 = j + 1
	s = s[c1:c2]
	c = 0
	for j in range(len(s)):
		if s[j] == '0':
			c += 1
	print(c)


for i in range(int(input())):
	q = list(map(int, list(input())))
	if 1 in q:
		w = sum(q)
		e = q.index(1)
		r = len(q) - q[::-1].index(1)
		print(r - e - w)
	else:
		print(0)


t = int(input())
for test in range(t):
	s = input()
	if '1' not in s:
		print(0)
	else:
		(start, end, x) = (0, 0, 0)
		for i in range(len(s)):
			if s[i] == '1':
				start = i
				break
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '1':
				end = i + 1
				break
		for i in range(start, end):
			if s[i] == '0':
				x += 1
		print(x)


t = int(input())
for _ in range(t):
	s = input()
	if '1' in s:
		locstart = -1
		for i in range(len(s)):
			if s[i] == '1':
				locstart = i
				break
		locend = -1
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '1':
				locend = i
				break
		p = s[locstart:locend]
		print(p.count('0'))
	else:
		print(0)


def main():
	string = str(input())
	i = 0
	while i < len(string) and string[i] == '0':
		i += 1
	cnt = 0
	while i < len(string):
		index = i
		while index < len(string) and string[index] == '0':
			index += 1
		if index == len(string):
			break
		else:
			cnt += index - i
		i = index + 1
	print(cnt)

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


for _ in range(int(input())):
	ar = list(map(int, input()))
	ans = 0
	flag = 0
	for i in range(len(ar)):
		if flag == 0 and ar[i] == 1:
			flag = 1
		if flag == 1 and ar[i] == 0:
			ans += 1
	i = len(ar) - 1
	while i >= 0 and ar[i] == 0:
		i -= 1
		ans -= 1
	print(max(ans, 0))


t = int(input())
while t > 0:
	s = input()
	if '1' in s:
		count = 0
		for i in range(len(s)):
			if s[i] == '1':
				break
		for j in range(len(s) - 1, -1, -1):
			if s[j] == '1':
				break
		while i <= j:
			if s[i] == '0':
				count += 1
			i += 1
		print(count)
	else:
		print(0)
	t -= 1


n = int(input())
for i in range(n):
	a = input()
	nz = 0
	t = 0
	h = 0
	for i in range(len(a)):
		if a[i] == '1':
			h = 1
			nz += t
			t = 0
		if h == 1 and a[i] == '0':
			t = t + 1
	print(nz)


t = int(input())
for i in range(t):
	l = list(str(input()))
	flag = 0
	c1 = 0
	c2 = 0
	for i in range(len(l)):
		if l[i] == '0' and flag != 0:
			c2 += 1
		elif l[i] == '1':
			flag = 1
			c1 += c2
			c2 = 0
	print(c1)


m = int(input())
for i in range(0, m):
	a = input()
	a = list(a)
	c = a[-1::-1]
	if a.count('1') == 0:
		print(0)
	else:
		d = a.index('1')
		e = c.index('1')
		f = a.count('0')
		print(f - d - e)


for _ in range(int(input())):
	a = list(map(int, list(input())))
	(f, l) = (-1, -1)
	for i in range(len(a)):
		if a[i] == 1:
			if f == -1:
				f = i
				l = i
			else:
				l = i
	ans = 0
	if f >= 0:
		for i in range(f, l + 1):
			if a[i] == 0:
				ans += 1
	print(ans)


from sys import stdin
for _ in range(int(stdin.readline())):
	s = stdin.readline().strip()
	count = 0
	n = len(s)
	if s.count('0') == n:
		print(0)
		continue
	start = 0
	last = n
	for i in range(n):
		if s[i] == '1':
			start = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			last = i
			break
	for j in range(start + 1, last):
		if s[j] == '1':
			pass
		else:
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	first = None
	last = None
	cnt = 0
	s = input()
	for i in range(len(s)):
		if s[i] == '1':
			if first == None:
				first = i
			last = i
	if first != None:
		for i in range(first, last + 1):
			if s[i] == '0':
				cnt += 1
	print(cnt)


def solve(test):
	ans = 0
	s = input()
	ok = False
	tmp = 0
	for c in s:
		if c == '1':
			if ok:
				ans += tmp
			ok = True
			tmp = 0
		else:
			tmp += 1
	print(ans)
t = int(input())
for _ in range(t):
	solve(_ + 1)


for tc in range(int(input())):
	k = input()
	p = 0
	q = 0
	for i in range(len(k)):
		if k[i] == '1':
			p = i
			break
	for i in range(len(k) - 1, -1, -1):
		if k[i] == '1':
			q = i
			break
	ans = 0
	for i in range(p, q):
		if k[i] == '0':
			ans += 1
	print(ans)


def calc(charList: list):
	ans: int = 0
	foundOne: bool = False
	try:
		while charList[-1] == '0':
			del charList[-1]
	except IndexError:
		return 0
	try:
		while charList[0] == '0':
			del charList[0]
	except IndexError:
		return 0
	for i in charList:
		if i == '0' and foundOne is False:
			ans += 1
		elif i == '0' and foundOne is True:
			ans += 1
		elif i == '1' and foundOne is True:
			foundOne = False
		elif i == '1' and foundOne is False:
			foundOne = True
	return ans

def main():
	for _ in range(int(input())):
		charList: list = list(input())
		print(calc(charList))
main()


t = int(input())
for _ in range(t):
	s = input().replace('\r', '')
	c = 0
	a = -1
	for l in s:
		if l == '1':
			if a > 0:
				c += a
			a = 0
		elif a >= 0:
			a += 1
	print(c)


def count_zero(string):
	lista = []
	for x in range(len(string)):
		lista.append(string[x])
	lista.append('1')
	contadores = []
	for i in range(len(lista)):
		if int(lista[i]) == 1:
			if i + 1 == len(lista):
				break
			if int(lista[i + 1]) == 0:
				j = i + 1
				count = 0
				while int(lista[j]) == 0:
					count += 1
					j += 1
					if j + 1 == len(lista):
						count = 0
						break
				contadores.append(count)
	return contadores

def somador(contador):
	valor = 0
	for i in range(len(contador)):
		valor += contador[i]
	return valor
x = int(input())
for i in range(x):
	string = input()
	if int(string) == 1 or int(string) == 0:
		print('0')
	else:
		string.split(' ')
		contador = count_zero(string)
		if contador == []:
			print('0')
		else:
			print(somador(contador))


def main_function():
	t = int(input())
	for i in range(t):
		string = input()
		counter = 0
		for j in range(string.find('1') + 1, string.rfind('1')):
			if string[j] == '0':
				counter += 1
		print(counter)
main_function()


t = int(input())
for i in range(t):
	a = str(input())
	if a.count('1'):
		print(a[a.index('1'):len(a) - a[::-1].index('1')].count('0'))
	else:
		print(0)


t = int(input())
for _ in range(t):
	start = -1
	end = -1
	sl = list(input())
	for (idx, s) in enumerate(sl):
		if s == '1':
			if start == -1:
				start = idx
			end = idx
	if start == -1:
		print(0)
		continue
	print(sl[start:end].count('0'))


for ti in range(int(input())):
	s = input()
	ans = 0
	t = 0
	prev1 = 0 if s[0] == '1' else 1000
	for i in range(1, len(s)):
		if prev1 < i:
			if s[i] == '0':
				t += 1
			else:
				ans += t
				t = 0
				prev1 = i
		elif s[i] == '1':
			prev1 = i
	print(ans)


n = int(input())
for i in range(n):
	m = list(input())
	l = []
	for i in range(len(m)):
		if m[i] == '1':
			l.append(i)
	s = 0
	for i in range(len(l) - 1):
		t = l[i + 1] - l[i]
		if t > 1:
			s += t - 1
	print(s)


for T in range(int(input())):
	s = input()
	(i, m, c, r) = (0, 0, 0, 0)
	while i < len(s):
		if int(s[i]):
			r += m * c
			(m, c) = (1, 0)
		else:
			c += 1
		i += 1
	print(r)


for _ in range(int(input())):
	s = input()
	accs = []
	ids = []
	last = s[0]
	acc = 1
	for i in range(1, len(s)):
		if s[i] == last:
			acc += 1
		else:
			ids.append(last)
			accs.append(acc)
			acc = 1
			last = s[i]
	ids.append(last)
	accs.append(acc)
	i = 1
	if ids[0] == '0':
		i = 2
	ans = 0
	while i < len(accs) - 1:
		ans += accs[i]
		i += 2
	print(ans)


n = int(input())
for _ in range(n):
	(s, res, ok, ans) = (input(), 0, 0, 0)
	for x in s:
		if ok == 0 and x == '0':
			continue
		if x == '1':
			ok = 1
			res += ans
			ans = 0
		else:
			ans += 1
	print(res)


for _ in range(int(input())):
	a = list(input())
	k = 0
	p = 0
	t = 0
	if '1' in a:
		l = a.index('1')
		b = a.copy()
		b.reverse()
		n = b.index('1')
		if l + n + 1 != len(a):
			for i in range(l + 1, len(a) - n):
				if a[i] == '0':
					k += 1
		print(k)
	else:
		print(0)


for _ in range(int(input())):
	given = input()
	if '1' not in given:
		print('0')
	else:
		erase = given[given.index('1'):given.rindex('1') + 1].count('0')
		print(erase)


def solve(s):
	if not s:
		return 0
	d = 0
	l = r = 0
	for i in range(len(s)):
		if s[i] == '1':
			l = r = i
			break
	for i in range(l + 1, len(s)):
		r = i
		if s[r] == '1':
			d += r - l - 1
			l = r
	return d
T = int(input())
for _ in range(T):
	s = solve(input())
	print(s)


t = int(input())
for _ in range(t):
	s = input()
	f = 0
	count = 0
	sub = 0
	for i in s:
		if i == '1':
			f = 1
			count += sub
			sub = 0
		elif f == 1:
			sub += 1
	print(count)


t = int(input())
while t > 0:
	t = t - 1
	a = [int(i) for i in input()]
	b = []
	b.append(a[0])
	for i in range(1, len(a)):
		b.append(a[i] + b[i - 1])
	last = b[len(b) - 1]
	zero = 0
	i = 0
	while i < len(b):
		if b[i] == 0:
			i += 1
			continue
		else:
			curr = b[i]
			if curr == last:
				break
			for j in range(i + 1, len(b)):
				if b[j] == curr:
					zero += 1
				else:
					i = j
					break
	print(zero)


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

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

def iinput():
	return int(input())
t = iinput()

def solve(s):
	i = 0
	n = len(s)
	res = 0
	last_sum = 0
	while i < n and s[i] == '0':
		i += 1
	while i < n:
		while i < n and s[i] == '1':
			i += 1
		acc = 0
		while i < n and s[i] == '0':
			acc += 1
			i += 1
		res += acc
		last_sum = acc
	if s[-1] == '0':
		res -= last_sum
	return res
while t:
	s = input()
	print(solve(s))
	t -= 1


def ab():
	a = list(map(int, input()))
	p = 0
	c = 0
	j = 0
	ff = set(a)
	if len(ff) == 1:
		print(0)
		return
	while True:
		if a[j] == 1:
			break
		else:
			a.pop(0)
	p = len(a) - 1
	while True:
		if a[p] == 1:
			break
		else:
			a.pop(p)
			p = p - 1
	for i in a:
		if i == 1:
			p = 1
			continue
		if i == 0:
			if p == 1:
				c += 1
	if p == 0:
		print(0)
	else:
		print(c)
for i in range(0, int(input())):
	ab()


t = int(input())
for i in range(t):
	s = input()
	enter = False
	endind = -1
	counter = 0
	for l in range(1, len(s) + 1):
		if s[len(s) - l] == '1':
			endind = len(s) - l
			break
	if endind != -1:
		s1 = s[s.index('1'):endind]
		for k in s1:
			if k == '0':
				counter += 1
	print(counter)


for nt in range(int(input())):
	s = input()
	(start, end) = (-1, -1)
	for i in range(len(s)):
		if s[i] == '1':
			start = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			end = i
			break
	if start == -1 or end == -1:
		print(0)
		continue
	print(s[start:end + 1].count('0'))


num1 = eval(input())
item = []
cool = []
great = []
z = 0
x = 0
y = 0
for i in range(num1):
	column = str(input())
	item = list(column)
	cool = list(map(str, item))
	cool.reverse()
	if item.count('1') > 0:
		x = item.index('1')
		y = cool.index('1')
		for j in range(x, len(item) - y):
			if item[j] == '0':
				z += 1
	great.append(z)
	z = 0
for i in range(len(great)):
	print(great[i])


for _ in range(int(input())):
	s = input()
	n = len(s)
	r = 0
	l = n - 1
	while r < n:
		if s[r] == '1':
			break
		r += 1
	while l >= 0:
		if s[l] == '1':
			break
		l -= 1
	s = s[r:l + 1]
	print(s.count('0'))


for i in range(int(input())):
	num = int(input())
	l1 = []
	n = num
	if n < 100:
		print(0)
		continue
	while n % 2 == 0:
		n //= 10
	while n >= 1:
		l1.append(n % 10)
		n //= 10
	a = l1.count(0)
	print(a)


t = int(input())
for j in range(t):
	s = input()
	l = s.find('1')
	r = s.rfind('1')
	ans = 0
	if l == -1:
		print(0)
	else:
		print(s.count('0', l, r))


for _ in range(int(input())):
	s = input()
	if len(s) == 1:
		print(0)
	else:
		pos = []
		for i in range(len(s)):
			if s[i] == '1':
				pos.append(i)
		cnt = 0
		for p in range(1, len(pos)):
			cnt += pos[p] - pos[p - 1] - 1
		print(cnt)


a = int(input())
for i in range(a):
	b = input()
	c = b.strip('0')
	print(c.count('0'))


for _ in range(int(input())):
	s = input()
	a = 0
	b = 0
	c = 0
	for i in range(len(s)):
		if s[i] == '1':
			c = 1
			b = b + a
			a = 0
		if s[i] == '0' and c:
			a = a + 1
	print(b)


inp1 = int(input())
for i in range(inp1):
	inp2 = input()
	l = len(inp2)
	k = 0
	c = 0
	t = 0
	z = 0
	for j in range(l):
		if inp2[j] == '1' and c == 0:
			c = 1
		elif c == 1 and inp2[j] == '0':
			t = t + 1
			z = z + 1
		elif c == 1 and inp2[j] == '1' and (z > 0):
			k = k + t
			t = 0
			z = 0
	print(k)


N = int(input())
for _ in range(N):
	s = input()
	i = s.find('1')
	j = s.rfind('1')
	if i == -1:
		print(0)
		continue
	ans = 0
	for k in range(i, j + 1):
		if s[k] == '0':
			ans += 1
	print(ans)


def go():
	s = input()
	i = 0
	while i < len(s) and s[i] == '0':
		i += 1
	if i == len(s):
		return 0
	j = len(s) - 1
	while s[j] == '0':
		j -= 1
	ones = 0
	for ss in s:
		if ss == '1':
			ones += 1
	return j - i + 1 - ones
t = int(input())
for _ in range(t):
	print(go())


t = int(input())
for i in range(t):
	a = list(input())
	if len(a) > 2:
		x = 0
		y = 0
		for j in range(len(a)):
			if a[j] == '1':
				x = j
				break
		for k in range(len(a) - 1, -1, -1):
			if a[k] == '1':
				y = k
				break
		z = 0
		for l in range(x, y):
			if a[l] == '0':
				z += 1
		print(z)
	else:
		print('0')


N = int(input())
for _ in range(0, N):
	list1 = []
	count = 0
	str1 = input()
	for i in range(0, len(str1)):
		list1.append(int(str1[i]))
	for i in range(0, len(list1)):
		if i != len(list1) - 1:
			if list1[i] == 1 and 1 in list1[i + 1:]:
				j = i + 1
				while True:
					if j < len(list1):
						if list1[j] == 1:
							break
						else:
							count += 1
					else:
						break
					j += 1
	print(count)


import sys, math
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
t = 1
t = inp()
for tt in range(t):
	a = insr()
	a = list(a)
	c = 0
	if '1' not in a:
		print(0)
		continue
	q = a.index('1')
	a.reverse()
	w = len(a) - 1 - a.index('1')
	print(w - q - a.count('1') + 1)


for _ in range(int(input())):
	s = input()
	k = s.count('1')
	print(0 if k == 0 else len(s) - s[::-1].find('1') - s.find('1') - k)


n = int(input())
for _ in range(n):
	s = input()
	count = 0
	z = -1
	for i in range(1, len(s)):
		if s[i - 1] == '0' and s[i] == '1':
			if z != -1:
				count += i - z
		if s[i - 1] == '1' and s[i] == '0':
			z = i
	print(count)


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

def main():
	s = input()
	(l, r, count) = (0, 0, 0)
	for j in range(len(s)):
		if s[j] == '1' and count == 0:
			(l, r) = (j, j + 1)
			count += 1
		elif s[j] == '1':
			r = j + 1
			count += 1
	return r - l - count
for i in range(int(input())):
	print(main())


t = int(input())
for i in range(t):
	s = input()
	p = s.rfind('1')
	ans = 0
	f = False
	for j in range(p):
		if s[j] == '1':
			f = True
		if f and s[j] == '0':
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	arr = list(input())
	if '1' not in arr:
		print(0)
	else:
		first_att = arr.index('1')
		temp = arr[:]
		temp.reverse()
		last_att = len(temp) - temp.index('1') - 1
		count = 0
		for j in range(first_att, last_att):
			if arr[j] == '0':
				count += 1
			else:
				continue
		print(count)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
t = I()
for _ in range(t):
	s = input().strip()
	f = 0
	for i in range(len(s)):
		if s[i] == '1':
			f = 1
			break
	k = i
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			f = 1
			break
	j = i
	if f:
		l = j - k + 1
		print(l - s.count('1'))
	else:
		print(0)


def min_zeros(astring):
	seqs = astring.split(',')
	for s in seqs:
		if s == '' or '1' not in s:
			return 0
		n = len(s)
		res = 0
		one = False
		for i in range(n):
			if s[i] == '1':
				one = True
				continue
			if one:
				for j in range(i + 1, n):
					if s[j] == '1':
						res += 1
						break
		return res
n = int(input())
strings = []
for i in range(n):
	strings.append(input())
for s in strings:
	print(min_zeros(s))


c = int(input())
for i in range(c):
	num = 0
	n = input()
	if int(n) == 0:
		print(0)
	f = n.find('1')
	rev = n[::-1]
	l = len(n) - 1 - rev.find('1')
	for k in n[f:l]:
		if k == '0':
			num += 1
	if int(n) != 0:
		print(num)


for _ in range(int(input())):
	str = input()
	l = list(str)
	if l.count('1') > 1:
		n = l.index('1')
		t = l[::-1].index('1')
		print(l[n:len(l) - t].count('0'))
	else:
		print('0')


number_of_testcases = int(input())
for i in range(number_of_testcases):
	string = input()
	length = len(string)
	counter = 0
	zeroes_to_erase = 0
	while counter < length:
		if string[counter] == '1':
			break
		counter = counter + 1
	zeroes_to_add = 0
	while counter < length - 1:
		counter = counter + 1
		if string[counter] == '0':
			zeroes_to_add = zeroes_to_add + 1
		else:
			zeroes_to_erase = zeroes_to_erase + zeroes_to_add
			zeroes_to_add = 0
	print(zeroes_to_erase)


t = int(input())
nums = []

def delzero(a):
	newstr = a
	for i in range(len(a)):
		if a[i] == '0':
			newstr = a[i + 1:]
		if a[i] == '1':
			break
	return newstr
for i in range(t):
	nums.append(input())
	s = nums[i]
	s = delzero(s)
	s = s[::-1]
	s = delzero(s)
	count = 0
	for i in range(len(s)):
		if s[i] == '0':
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	s = input()
	if s.count('1') <= 1:
		print(0)
		continue
	first = s.index('1')
	last = len(s) - 1 - s[::-1].index('1')
	print(s[first:last].count('0'))


t = eval(input())
while t:
	s = input()
	l = -1
	r = -1
	n = len(s)
	for i in range(n):
		if s[i] == '1':
			l = i
			break
	for i in range(n):
		if s[i] == '1':
			r = i
	if l == -1 and r == -1:
		print(0)
	else:
		res = 0
		for i in range(l, r + 1):
			if s[i] == '0':
				res += 1
		print(res)
	t -= 1


t = int(input().strip())
out = []
for _ in range(t):
	(cnt, total, b) = (0, 0, False)
	for c in input().strip():
		if b:
			if c == '0':
				cnt += 1
			elif c == '1':
				total += cnt
				cnt = 0
		elif c == '1':
			b = True
	out.append(str(total))
print('\n'.join(out))


t = int(input())
for _ in range(t):
	s = input()
	s = s.strip('0')
	n = len(s)
	cnt = 0
	for i in range(n):
		if s[i] == '0':
			cnt += 1
	print(cnt)


t = int(input())
for q in range(t):
	n = input()
	l = len(n)
	s = 0
	i = 0
	p = 0
	if l == 0 or l == 1 or l == 2:
		s = 0
		print(s)
	else:
		for k in range(l):
			if n[k] == '1':
				i = k
				break
		for a in range(l - 1, i, -1):
			if n[a] == '1':
				p = a
				break
		for j in range(i, p):
			if n[j] == '0':
				s = s + 1
		print(s)


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
from io import BytesIO, IOBase
from bisect import bisect_left as bl
from bisect import bisect_right as br

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=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

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 flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def modpow(b, p, m):
	res = 1
	b = b % m
	while p:
		if p & 1:
			res = res * b % m
		b = b * b % m
		p >>= 1
	return res

def mod_inv(a, m):
	return modpow(a, m - 2, m)

def ncr(n, r, m):
	res = 1
	if r == 0:
		return 1
	if n - r < r:
		r = n - r
	(p, k) = (1, 1)
	while r:
		res = res % m * (n % m * mod_inv(r, m) % m) % m
		n -= 1
		r -= 1
	return res

def ncrlis(n, r, m, fact):
	return fact[n] * (mod_inv(fact[r], m) * mod_inv(fact[n - r], m)) % m % m

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

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

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

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

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

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

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

def ddl():
	return collections.defaultdict(list)
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(ii()):
	s = input()
	n = len(s)
	(idx1, idx2) = (-1, -1)
	for i in range(n):
		if s[i] == '1':
			idx1 = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			idx2 = i
			break
	if idx1 == -1:
		print(0)
	else:
		print(s[idx1:idx2 + 1].count('0'))


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


for _ in range(int(input())):
	s = input()
	(ans, now, cnt) = (0, False, 0)
	for i in s:
		if i == '1':
			now = True
			ans += cnt
			cnt = 0
		elif now:
			cnt += 1
	print(ans)


t = int(input())
for i in range(0, t):
	s = input()
	i = 0
	c = 0
	tc = 0
	while True:
		if i == len(s) - 1:
			break
		if s[i] == '1':
			i = i + 1
			c = 0
			while s[i] != '1' and i != len(s) - 1:
				c = c + 1
				i = i + 1
			if s[i] == '1':
				tc = tc + c
		else:
			i = i + 1
	print(tc)


t = int(input())
(k, g) = (0, 0)
for i in range(t):
	s = input()
	if s == '0' or s == '1' or '0' not in s or ('1' not in s):
		s0 = 0
	else:
		for j in range(len(s) - 1, -1, -1):
			if s[j] == '1':
				k = j
				break
		for l in range(len(s)):
			if s[l] == '1':
				g = l
				break
	s0 = 0
	while g != k:
		if s[g] == '0':
			s0 += 1
		g += 1
	print(s0)


for _ in range(int(input())):
	s = input()
	l = len(s)
	if s == '0' or s == '1':
		print(0)
		continue
	if l == 2:
		print(0)
		continue
	for i in range(l):
		if s[i] == '1':
			break
	for j in range(l - 1, -1, -1):
		if s[j] == '1':
			break
	c = 0
	for k in range(i + 1, j):
		if s[k] == '0':
			c += 1
	print(c)


def removingZeroes(givenInput):
	input = givenInput.split('\n')
	input = input[1:]
	result = ''
	for i in range(len(input)):
		singleLine = input[i]
		singleLine = singleLine.split()
		for each in singleLine:
			summ = removingZeroesHelper(each)
			if i < len(input) - 1:
				result = result + str(summ) + '\n'
			else:
				result = result + str(summ)
	return result

def removingZeroesHelper(givenString):
	startIndex = None
	summ = 0
	count = 0
	for i in range(len(givenString)):
		if givenString[i] == '1':
			startIndex = i
			break
	if startIndex == None:
		return 0
	for i in range(startIndex, len(givenString)):
		if givenString[i] == '1' and count == 0:
			pass
		elif givenString[i] == '1' and count > 0:
			summ += count
			count = 0
		elif givenString[i] == '0':
			count += 1
	return summ
n = eval(input())
givenInput = str(n) + '\n'
for i in range(n):
	singleLine = input()
	if i == n - 1:
		givenInput += singleLine
		continue
	givenInput += singleLine + '\n'
final = removingZeroes(givenInput)
print(final)


t = int(input())
for i in range(t):
	s = input()
	start = -1
	end = -1
	count = 0
	for i in range(len(s)):
		if s[i] == '0' and start == -1 and (i - 1 >= 0) and (s[i - 1] == '1'):
			start = i
			end = -1
		if s[i] == '1' and end == -1 and (start != -1):
			end = i - 1
			count += end - start + 1
			start = -1
	print(count)


t = int(input())
for _ in range(t):
	s = input()
	if not '1' in s:
		print(0)
		continue
	i = s.index('1')
	j = len(s) - 1 - s[::-1].index('1')
	print(s[i:j + 1].count('0'))


for _ in range(int(input())):
	(l, r, s, got, z) = (0, 0, input(), False, 0)
	for (i, el) in enumerate(s):
		if el == '1' and (not got):
			got = True
			l = i
			r = i
		elif el == '1':
			r = i
		elif el == '0':
			z += 1
	z -= l
	z -= len(s) - 1 - r
	if not got or l == r:
		z = 0
	print(z)


hm = int(input())
for i in range(hm):
	inp = input()
	zeros = 0
	zerocounter = 0
	flag = 0
	for e in inp:
		if e == '1':
			flag = 1
			zeros += zerocounter
			zerocounter = 0
		elif flag == 1:
			zerocounter += 1
	print(zeros)


test_case = int(input())
for _ in range(test_case):
	s = input()
	one = s[0] == '1'
	result = 0
	r = []
	for i in range(1, len(s)):
		if s[i] == '0' and one:
			result += 1
		if s[i] == '1':
			r.append(result)
			result = 0
			one = True
	print(sum(r))


t = int(input())
for _ in range(t):
	a = input()
	w = a.split('1')
	ans = 0
	for i in range(1, len(w) - 1):
		ans += len(w[i])
	print(ans)


def min_zeros(case):
	length = len(case)
	begin = -1
	number_of_zeros = 0
	min_number_of_zeros = 0
	for j in range(0, length):
		if case[j] == '1':
			if begin == -1:
				begin = j
			else:
				min_number_of_zeros += number_of_zeros
			number_of_zeros = 0
		else:
			number_of_zeros += 1
	return min_number_of_zeros
number_of_test_cases = int(input(''))
test_cases = []
for i in range(0, number_of_test_cases):
	test_cases.append(input(''))
for test_case in test_cases:
	print(min_zeros(test_case))


a = int(input())
for i in range(0, a):
	b = list(map(int, input()))
	bilLiOn = 0
	itogSum = 0
	suma = sum(b)
	for g in range(0, len(b)):
		if b[g] == 0:
			if bilLiOn != 0:
				if bilLiOn != suma:
					itogSum += 1
					continue
				else:
					break
		else:
			bilLiOn += 1
	print(itogSum)


testCases = int(input())
for _ in range(testCases):
	test = input()
	if len(test) < 3:
		print(0)
	elif '1' not in test:
		print(0)
	else:
		startIndex = -1
		endIndex = -1
		for index in range(len(test)):
			if startIndex == -1 and test[index] == '1':
				startIndex = index
			backIndex = len(test) - 1 - index
			if endIndex == -1 and test[backIndex] == '1':
				endIndex = backIndex
			if startIndex != -1 and endIndex != -1:
				break
		newTest = test[startIndex:endIndex + 1]
		remain = newTest.replace('0', '')
		answer = len(newTest) - len(remain)
		print(answer)


for _ in range(int(input())):
	m = input()
	if set(m) == {'0'}:
		print(0)
		continue
	ans1 = 0
	for i in range(len(m)):
		if m[i] == '1':
			ans1 = i
			break
	ans2 = ans1
	for i in range(ans1 + 1, len(m)):
		if m[i] == '1':
			ans2 = i
	print(m[ans1:ans2 + 1].count('0'))


n = int(input())
while n > 0:
	s = input()
	c = 0
	pos1 = 0
	pos2 = 0
	count = 0
	for i in range(len(s)):
		if c == 0 and s[i] == '1':
			c += 1
			pos1 = i
		elif s[i] == '1':
			pos2 = i
	for i in range(pos1, pos2 + 1):
		if s[i] == '0' and i != 0:
			count += 1
	print(count)
	n -= 1


for T in range(int(input().strip())):
	a = list(input().strip())
	while len(a) > 0 and a[-1] == '0':
		a.pop()
	a = a[::-1]
	while len(a) > 0 and a[-1] == '0':
		a.pop()
	count = 0
	for i in range(len(a)):
		if a[i] == '0':
			count = count + 1
	print(count)


n = int(input())
for i in range(n):
	a = input()
	a = list(a)
	r = 0
	y = []
	for i in range(len(a)):
		if a[i] == '1':
			x = 0
			for j in range(i + 1, len(a)):
				if a[j] == '0':
					x += 1
				if a[j] == '1':
					break
			y.append(x)
	if a[len(a) - 1] != '1' and len(y) >= 1:
		print(sum(y) - y[len(y) - 1])
	else:
		print(sum(y))


import sys

def f(line):
	cnt = 0
	i = 0
	j = -1
	if len(line) == 0:
		print(0)
		return
	while line[i] != '1':
		i += 1
		if i >= len(line):
			print(0)
			return
	while line[j] != '1':
		j -= 1
		if j == -1:
			print(0)
			return
	while i < j + len(line):
		if line[i] == '0':
			cnt += 1
		i += 1
	print(cnt)
flag = False
for line in sys.stdin:
	if flag == False:
		flag = True
		continue
	else:
		f(line)


t = int(input())
while t:
	s = input()
	vs = []
	cnt = 0
	has = 0
	for x in s:
		if x == '1':
			if cnt > 0 and has:
				vs.append(cnt)
				cnt = 0
			else:
				cnt = 0
			has = 1
		else:
			cnt += 1
	vs.sort()
	ans = 0
	for x in vs:
		ans += x
	print(ans)
	t -= 1


T = int(input())
for i in range(T):
	s = input()
	c = 0
	m = 0
	w = 0
	for j in s:
		if j == '1':
			if c == 0:
				c = 1
			else:
				w = w + m
				m = 0
		elif j == '0':
			if c == 1:
				m = m + 1
	print(w)


a = int(input())
for k in range(a):
	b = input()
	c = 0
	sum = 0
	e = b.count('10')
	if e == 0:
		print(0)
	elif e == 1 and b.count('01') == 0:
		print(0)
	else:
		for j in range(e):
			g = b.find('10', c)
			h = b.find('01', g)
			if h >= 0 and g >= 0:
				sum += h - g
			c = g + 1
		print(sum)


t = int(input())
for case in range(t):
	s = input()
	light_flag = 0
	ans = 0
	tmp = 0
	for i in s:
		if light_flag == 0:
			if i == '1':
				light_flag = 1
		elif i == '0':
			ans += 1
			tmp += 1
		else:
			tmp = 0
	print(ans - tmp)


t = int(input())
for i in range(t):
	s = input()
	sum1 = 0
	flag = 0
	c = 0
	for i in range(len(s)):
		if s[len(s) - i - 1] == '1':
			c = len(s) - i - 1
			break
	for i in range(len(s)):
		if s[i] == '1':
			flag = 1
		elif flag == 1 and i < c:
			sum1 += 1
	print(sum1)


t = int(input())
for __ in range(t):
	s = input()
	ans = 0
	cont = 0
	aux = False
	for e in s:
		if e == '1':
			if aux == False:
				aux = True
				continue
			else:
				ans += cont
				cont = 0
		elif e == '0':
			if aux == False:
				continue
			else:
				cont += 1
	print(ans)


import sys
input = sys.stdin.readline
N = int(input())
for _ in range(N):
	s = list(map(int, list(input())[:-1]))
	t = []
	res = 0
	for i in range(len(s)):
		if s[i] == 1:
			t.append(i)
	for i in range(len(t) - 1):
		res += t[i + 1] - t[i] - 1
	print(res)


n = int(input())
for z in range(n):
	s = input()
	c = 0
	for i in range(0, len(s)):
		if s[i] == '1':
			break
	for j in range(len(s) - 1, -1, -1):
		if s[j] == '1':
			break
	for k in range(i + 1, j):
		if s[k] == '0':
			c += 1
	print(c)


repetition = int(input())

def first_1(l):
	for i in range(len(l)):
		if l[i] == '1':
			return i
			break

def last_1(l):
	last_occur = 0
	for i in range(len(l)):
		if l[i] == '1':
			last_occur = i
	return last_occur
for num in range(repetition):
	counter = 0
	test_case = input()
	first_num = first_1(test_case)
	last_num = last_1(test_case)
	if first_1(test_case) == None:
		counter = 0
		print(counter)
		continue
	for e in range(first_num, last_num + 1):
		if test_case[e] == '0':
			counter = counter + 1
	print(counter)


t = int(input())
while t != 0:
	a = input()
	count = 0
	c = 0
	x = 0
	for i in range(len(a)):
		if a[i] == '1':
			count = count + c
			c = 0
			x = 1
			continue
		elif x == 1:
			c = c + 1
	print(count)
	t = t - 1


def erase_zeroes(string):
	started = False
	removal_count = 0
	for i in string:
		if i == '1':
			started = True
		elif started:
			removal_count += 1
	if not started:
		return 0
	end_count = 0
	for i in range(len(string) - 1, -1, -1):
		if string[i] == '1':
			break
		end_count += 1
	return removal_count - end_count

def solution(inp1):
	return erase_zeroes(inp1)

def main():
	inp1 = input()
	length = int(inp1)
	for i in range(length):
		inp1 = input()
		result = solution(inp1)
		print(result)
main()


t = int(input())
for i in range(t):
	s = input()
	left = -1
	l = len(s)
	right = l - 1
	for j in range(l):
		if s[j] == '1':
			left = j
			break
	if left == -1 or left == right:
		print(0)
		continue
	for j in range(l - 1, -1, -1):
		if s[j] == '1':
			right = j
			break
	count = 0
	for j in range(left + 1, right):
		if s[j] == '0':
			count += 1
	print(count)


a = int(input())
for i in range(a):
	l = list(map(str, input()))
	countone = l.count('1')
	pas = 0
	one = False
	for j in l:
		if j == '1' and countone >= 0:
			countone -= 1
			one = True
		elif j == '0' and countone > 0 and (one == True):
			pas += 1
	print(pas)


t = int(input())
while t > 0:
	s = input()
	l = 102
	r = 101
	for i in range(len(s)):
		if s[i] == '1':
			l = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			r = i
			break
	c = 0
	for i in range(l, r + 1):
		if s[i] == '0':
			c += 1
	print(c)
	t -= 1


x = int(input())
t = []
for c in range(x):
	v = input()
	vv = []
	for cc in range(len(v)):
		vv.append(v[cc])
	t.append(vv)
for c in t:
	zero = 0
	for cc in range(len(c)):
		zero = zero + int(c[cc])
	if zero == 0:
		print('0')
	else:
		win = 0
		countL = 0
		countR = len(c)
		reverse = -1
		while c[countL] != '1':
			countL = countL + 1
		while c[reverse] != '1':
			reverse = reverse - 1
			countR = countR - 1
		win = 0
		for x in range(countL, countR):
			if c[x] == '0':
				win = win + 1
		print(win)


for _ in range(int(input())):
	s = input()
	l = []
	c = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
			l.append(i)
	if len(l) > 1:
		d = l[-1] - l[0] + 1
		print(d - c)
	else:
		print('0')


def zero(k):
	l = list(map(int, list(k)))
	j = list(map(int, list(k[::-1])))
	z = 0
	if any(l) == True:
		first = l.index(1)
		last = j.index(1)
		z = l[first:len(l) - last].count(0)
	return z
n = int(input())
for x in range(n):
	k = int(input())
	s = zero(str(k))
	print(s)


for _ in range(int(input())):
	n = input()
	m = n[::-1]
	count = 0
	for i in range(len(n)):
		if n[i] == '0':
			count += 1
		else:
			break
	for i in range(len(n)):
		if m[i] == '0':
			count += 1
		else:
			break
	if n.count('1') == 0:
		print(0)
	else:
		print(n.count('0') - count)


for _ in range(int(input())):
	s = input()
	n = len(s)
	if s == '0' * n or s == '1' * n:
		print(0)
	else:
		d1 = n - s[::-1].index('1')
		print(s[s.index('1'):d1].count('0'))


def solve(line):
	m = 0
	start = 0
	end = len(line) - 1
	while start <= end and line[start] == '0':
		start += 1
	while end >= start and line[end] == '0':
		end -= 1
	found = False
	for s in line[start:end + 1]:
		if not found:
			if s == '1':
				found = True
		elif s == '0':
			m += 1
	return m

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


for _ in range(int(input())):
	s = input()
	m = [i for (i, e) in enumerate(s) if e == '1']
	c = 0
	for idx in range(len(m) - 1):
		c += m[idx + 1] - m[idx] - 1
	print(c)


t = int(input())
for _ in range(t):
	s = input()
	count = 0
	pos = 0
	pos2 = 0
	for i in range(len(s)):
		if s[i] == '1':
			pos = i
			break
	for i in range(len(s) - 1, pos + 1, -1):
		if s[i] == '1':
			pos2 = i
			break
	for i in range(pos, pos2):
		if s[i] == '0':
			count += 1
	print(count)


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


t = int(input())
for _ in range(t):
	s = [int(i) for i in input()]
	ind1 = 0
	ind2 = len(s) - 1
	freq0 = 0
	freq1 = 0
	for i in s:
		if i:
			freq1 += 1
		else:
			freq0 += 1
	if 1 not in s:
		print(0)
	else:
		for i in range(len(s)):
			if s[i] == 1:
				ind1 = i
				break
		for i in range(len(s) - 1, -1, -1):
			if s[i] == 1:
				ind2 = i
				break
		ct = 0
		for i in range(ind1, ind2):
			if s[i] == 0:
				ct += 1
		print(ct)


for _ in range(int(input())):
	s = input()
	flag = False
	count = 0
	for i in range(len(s)):
		if not flag and s[i] == '1':
			flag = True
		if flag and s[i] == '0':
			count += 1
	s = s[::-1]
	for i in range(len(s)):
		if flag and s[i] == '0':
			count -= 1
		if s[i] == '1':
			flag = False
			break
	print(count)


for x in range(int(input())):
	inp = list(map(int, input()))
	count = dict()
	for y in range(len(inp)):
		if inp[0] == 1:
			break
		else:
			inp.remove(inp[0])
	for z in range(len(inp)):
		if inp[-1] == 1:
			break
		else:
			inp.pop(-1)
	for t in inp:
		if count.get(t) == None:
			count[t] = 1
		else:
			count[t] = count[t] + 1
	count = count.get(0)
	if count == None:
		print(0)
	else:
		print(count)


import math
from collections import *
import sys
from functools import reduce

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

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
UGLYMOD = int(1000000000.0) + 7
SEXYMOD = 998244353
MAXN = int(100000.0)
for _testcases_ in range(int(input())):
	s = input()
	try:
		st = s.index('1')
	except:
		st = len(s)
	try:
		en = s.rindex('1')
	except:
		en = 0
	ans = 0
	for i in range(st, en):
		if s[i] == '0':
			ans += 1
	print(ans)


def solve():
	t = int(input())
	for _ in range(t):
		count = 0
		s = input()
		s = s.lstrip('0')
		s = s.rstrip('0')
		for i in s:
			if i == '0':
				count += 1
		print(count)
solve()


def checker(n, s):
	(last, count) = (n, 0)
	for i in range(n):
		if s[i] == '1':
			last = i
		if last != n and s[i] == '0':
			count += 1
	return count - (n - 1 - last + (last == n))
for _ in range(int(input())):
	t = input()
	print(checker(len(t), t))


def main():
	t = int(input())
	for __ in range(t):
		s = input()
		found_one = False
		count = 0
		a = []
		for i in s:
			if i == '1':
				if found_one:
					while a[-1] != '1':
						a.pop()
						count += 1
				else:
					found_one = True
			a.append(i)
		print(count)
main()


t = int(input())
m = 0
while m < t:
	str = input().strip('0')
	tt = str.count('0')
	print(int(tt))
	m = m + 1


t = int(input().strip())
for i in range(t):
	s = input().strip()
	i = 0
	j = len(s) - 1
	endi = True
	while endi and i < j:
		endi = False
		if s[i] == '0':
			i += 1
			endi = True
		if s[j] == '0':
			j -= 1
			endi = True
	if i >= j:
		print('0')
	else:
		print(s.count('0', i, j + 1))


for _ in range(int(input())):
	n = input()
	right = 0
	left = 0
	for i in range(len(n)):
		if n[i] == '1':
			left = i
			break
	for j in range(len(n) - 1, -1, -1):
		if n[j] == '1':
			right = j
			break
	if right <= left:
		print(0)
	else:
		n = n[left:right + 1]
		print(n.count('0'))


for i in range(int(input())):
	a = input()
	start = 0
	end = 0
	for i in range(len(a)):
		if a[i] == '1':
			start = i
			break
	for i in range(len(a) - 1, -1, -1):
		if a[i] == '1':
			end = i
			break
	a = a[start:end]
	print(a.count('0'))


for t in range(int(input())):
	(bn, c) = (input(), 0)
	for i in range(len(bn)):
		if bn[i] != '0':
			break
	for j in range(len(bn) - 1, -1, -1):
		if bn[j] != '0':
			break
	for k in range(i + 1, j):
		if bn[k] == '0':
			c += 1
	print(c)


t = int(input())
for s in range(t):
	string = input()
	(add, count, store, n, flag) = (0, 0, 0, 0, 1)
	for i in string:
		count += 1
		if i == '1':
			add += 1
			n = count
		if add == 1 and flag == 1:
			store = count
			flag = 0
	if add == 0:
		print(0)
	else:
		print(n - store - add + 1)


for i in range(int(input())):
	s = list(str(input()))
	if s.count('1') < 2:
		print(0)
	else:
		i = 0
		j = len(s) - 1
		while s[i] == '0':
			i += 1
		while s[j] == '0':
			j -= 1
		print(s[i:j + 1].count('0'))


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):
	s = list(ips())
	n = len(s)
	if s.count('0') == n:
		ans = 0
	else:
		for i in range(n):
			if s[i] == '1':
				st = i
				break
		for i in range(n - 1, -1, -1):
			if s[i] == '1':
				end = i
				break
		gap = []
		ct = 0
		for i in range(st, end + 1):
			if s[i] == '0':
				ct += 1
			else:
				if ct != 0:
					gap.append(ct)
				ct = 0
		if ct != 0:
			gap.append(ct)
		ans = sum(gap)
	out(ans)


for i in range(int(input())):
	s = input()
	k = -1
	ans = 0
	for i in range(len(s)):
		if s[i] == '1':
			if k == -1:
				k = i
			else:
				ans += i - k - 1
				k = i
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	s = input()
	first = -1
	last = -1
	for i in range(0, len(s)):
		if s[i] == '1':
			first = i
			break
	for i in range(0, len(s)):
		if s[i] == '1':
			last = i
	count = 0
	for i in range(first, last):
		if s[i] == '0':
			count += 1
	print(count)


def func(stri):
	if len(stri) < 3:
		return 0
	while 1:
		if len(stri) == 0:
			return 0
		if stri[0] == '1':
			break
		else:
			stri = stri[1:]
	while 1:
		if len(stri) == 0:
			return 0
		if stri[len(stri) - 1] == '1':
			break
		else:
			stri = stri[:len(stri) - 1]
	count = 0
	for i in range(len(stri)):
		if stri[i] == '0':
			count += 1
	return count
testcase = input()
num_arr = []
for i in range(int(testcase)):
	num_arr.append(input())
for j in num_arr:
	print(func(j))


import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

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

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

def instr():
	s = input()
	return list(s[:len(s)])

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

def main():
	t = inp()
	for _ in range(t):
		s = input()
		n = len(s)
		c1 = 0
		c2 = 0
		for i in range(n):
			if s[i] == '1':
				c1 = i
				break
		for i in range(n - 1, -1, -1):
			if s[i] == '1':
				c2 = i
				break
		res = 0
		for i in range(c1, c2 + 1):
			if s[i] == '0':
				res += 1
		if c2 <= c1:
			res = 0
		print(res)
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')
main()


t = int(input())
for w in range(t):
	s = input()
	m = 0
	c = s.count('1')
	l = len(s)
	if c > 1:
		x = s.index('1')
		for i in range(l - 1, x, -1):
			if s[i] == '1':
				m = i - x + 1 - c
				break
	print(m)


for _ in range(int(input())):
	sp = []
	sp1 = []
	Str = input()
	sp.extend(Str[Str.find('1'):])
	for i in range(len(sp) - 1, -1, -1):
		if sp[i] == '1':
			sp1.extend(sp[:i])
			break
	print(sp1.count('0'))


t = int(input())
for _ in range(t):
	s = input()
	c = 0
	i = 0
	back = 0
	tmp = 0
	while i < len(s):
		if s[i] == '0':
			if back:
				tmp += 1
		else:
			back = 1
			c += tmp
			tmp = 0
		i += 1
	print(c)


import math
n = int(input())
ans = []
for i in range(n):
	s = str(input())
	k = 0
	left = 0
	right = len(s) - 1
	while s[left] != '1' and left < len(s) - 1:
		left += 1
	while s[right] != '1' and right >= left:
		right -= 1
	for j in range(left, right):
		if s[j] != '1':
			k += 1
	ans.append(k)
for i in range(len(ans)):
	print(ans[i])


for i in range(int(input())):
	s = list(input())
	ln = len(s)
	num1 = s.count('1')
	num2 = s.count('0')
	index1 = 0
	index2 = ln - 1
	if ln == 1 or num1 == 0:
		print('0')
	else:
		for i in range(ln):
			if s[i] == '1':
				index1 = i
				break
		for i in range(ln):
			if s[i] == '1':
				index2 = i
		print(index2 - index1 + 1 - num1)


for _ in range(int(input())):
	s = input()
	n = len(s)
	if n >= 3:
		if '1' in s and s.count('1') > 1:
			k = s[::-1]
			i = s.index('1')
			j = n - (k.index('1') + 1)
			z = s[i:j + 1]
			if '0' in z:
				print(z.count('0'))
			else:
				print(0)
		else:
			print(0)
	else:
		print(0)


for _ in range(int(input())):
	s = input()
	left = 0
	right = len(s) - 1
	hasLeft = False
	hasRight = False
	if s.count('1') == 0:
		print(0)
		continue
	while left < right:
		if not hasLeft and s[left] == '0':
			left += 1
		elif not hasLeft and s[left] == '1':
			hasLeft = True
		if not hasRight and s[right] == '0':
			right -= 1
		elif not hasRight and s[right] == '1':
			hasRight = True
		if hasLeft and hasRight:
			break
	s = s[left:right + 1]
	print(s.count('0'))


for i in range(int(input())):
	s = input()
	if s.count('0') == 0 or s.count('1') == 0:
		print(0)
	else:
		iss = len(s) - s.find('1')
		s = s[::-1]
		is2 = s.find('1')
		print(s[is2:iss].count('0'))


NTC = int(input())
for _ in range(NTC):
	s = input()
	s = s.replace('0', ' ')
	s = s.strip()
	print(s.count(' '))


def f(s):
	try:
		l = s.index('1')
	except:
		return 0
	if l == -1:
		return 0
	t = list(reversed(s))
	r = len(s) - t.index('1') - 1
	count = 0
	for i in range(l, r + 1):
		if s[i] == '0':
			count += 1
	return count
try:
	t = int(input())
	for i in range(t):
		s = input()
		print(f(s))
except:
	pass


import sys
input = sys.stdin.readline

def in_int():
	return int(input())

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

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

def in_ints():
	return map(int, input().split())
t = in_int()
while t > 0:
	t -= 1
	x = in_str()
	l = 0
	while l < len(x) and x[l] == '0':
		l += 1
	r = len(x) - 1
	while r >= 0 and x[r] == '0':
		r -= 1
	count = 0
	for ii in list(x[l:r + 1]):
		if ii == '0':
			count += 1
	print(count)


n = int(input())
for _ in range(n):
	x = input()
	f = 0
	i = 0
	c = 0
	while i < len(x):
		if x[i] == '1' and f == 0:
			f = 1
		if f == 1 and x[i] == '0':
			c += 1
		i += 1
	m = 0
	i -= 1
	while i > 0:
		if x[i] != '1':
			m += 1
		else:
			break
		i -= 1
	if c - m < 0:
		print(0)
	else:
		print(c - m)


for _ in range(int(input())):
	s = input()
	L = list(s)
	if L.count('1') > 1:
		x = L.index('1')
		y = L[::-1].index('1')
		print(L[x:len(L) - y].count('0'))
	else:
		print('0')


a = int(input())
count = 0
for z in range(a):
	s = input()
	q = -1
	f = -1
	for v in range(len(s)):
		if q == -1 and s[v] == '1':
			q = v
		if s[v] == '1':
			f = v
	for v in range(q, f):
		if s[v] == '0':
			count += 1
	print(count)
	count = 0


t = int(input())
for _ in range(t):
	l = list(input())
	li = l.copy()
	li.reverse()
	if '1' in l and '0' in l:
		print(l.count('0') - l.index('1') - li.index('1'))
	else:
		print(0)


for _ in [0] * int(input()):
	First1 = False
	One = False
	(ans, scet0) = (0, 0)
	for i in input():
		if i == '1':
			First1 = True
			One == True
			ans += scet0
			scet0 = 0
		elif First1:
			scet0 += 1
	print(ans)


for i in range(int(input())):
	a = []
	for j in input():
		a.append(j)
	if a.count('1') == 0:
		print(0)
		continue
	f = 0
	s = 0
	for j in range(len(a)):
		if a[j] == '1':
			f = j
			break
	for j in range(len(a) - 1, 0, -1):
		if a[j] == '1':
			s = j
			break
	ans = 0
	for j in range(f, s + 1):
		if a[j] == '0':
			ans += 1
	print(ans)


import re
for _ in range(int(input())):
	s = input()
	n = len(s)
	na = 0
	cnt1 = 0
	for i in s:
		if i == '0':
			cnt1 += 1
		else:
			break
	lst = re.findall('[0]+[1]', s)
	count = 0
	for j in lst:
		count = count + j.count('0')
	if count != 0:
		print(count - cnt1)
	else:
		print(0)


t = int(input())
for _ in range(t):
	s = input()
	s = s.strip('0')
	cnt = 0
	for c in s:
		if c == '1':
			cnt += 1
	print(len(s) - cnt)


t = int(input())
for test in range(t):
	string = input()
	strlen = len(string)
	count = 0
	res = 0
	if '1' in string:
		idx = string.index('1')
		for i in range(idx, strlen):
			if string[i] == '1':
				res += count
				count = 0
			else:
				count += 1
	print(res)


def one():
	return int(input())

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

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

def st():
	return input()
for i in range(one()):
	s = st()
	l = []
	count = 0
	for (ind, j) in enumerate(s):
		if j == '1':
			l.append(ind)
	for (ind, j) in enumerate(s):
		if j == '0':
			if len(l) > 1:
				if l[0] < ind < l[-1]:
					count += 1
	print(count)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_int = lambda : int(sys.stdin.readline().strip())
pt = lambda x: sys.stdout.write(str(x))
for _ in range(get_int()):
	s = get_string()
	s = s.strip('0')
	print(s.count('0'))


t = int(input())
result = []
for _ in range(t):
	result.append(input().strip('0').count('0'))
for x in result:
	print(x)


n = int(input())
for i in range(0, n):
	s = list(input())
	for i in range(0, len(s)):
		if s[i] == '1':
			break
		s[i] = '1'
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			break
		s[i] = '1'
	result = 0
	for c in s:
		if c == '0':
			result += 1
	print(result)


t = int(input())
for _ in range(t):
	s = list(input())
	while s and s[-1] == '0':
		s.pop()
	while s and s[0] == '0':
		s.pop(0)
	print(s.count('0'))


def compress(string):
	string = string + '#'
	n = len(string)
	(begin, end, cnt) = (0, 1, 1)
	ans = []
	while end < n:
		if string[begin] == string[end]:
			(end, cnt) = (end + 1, cnt + 1)
		else:
			ans.append((string[begin], cnt))
			(begin, end, cnt) = (end, end + 1, 1)
	return ans
t = int(input())
for _ in range(t):
	s = input()
	comp_s = compress(s)
	ans = 0
	for (char, cnt) in comp_s[1:-1]:
		if char == '0':
			ans += cnt
	print(ans)


def remove_char(string, idx):
	new_str = ''
	for i in range(len(string)):
		if i != idx:
			new_str += string[i]
	return new_str
t = int(input())
s = []
d = []
for i in range(t):
	s.append(input())
	d.append(0)
for j in range(t):
	start = s[j].find('1', 0)
	end = s[j].rfind('1', 0)
	if start == end or start == -1:
		continue
	i = s[j].find('0', start, end)
	while i != -1:
		s[j] = remove_char(s[j], i)
		d[j] += 1
		start = s[j].find('1', 0)
		end = s[j].rfind('1', 0)
		i = s[j].find('0', start, end)
for i in d:
	print(i)


t = int(input())
for i in range(t):
	s = input()
	c = 0
	f = -1
	for i in range(len(s)):
		if s[i] == '1' and f == -1:
			f = i
		elif s[i] == '1':
			c += i - f - 1
			f = i
	print(c)


t = int(input())
for _ in range(t):
	s = input()
	zeros = s.count('0')
	if zeros == len(s):
		print(0)
	else:
		a = s.index('1')
		b = s[::-1].index('1')
		print(zeros - a - b)


t = int(input())
for i in range(0, t):
	t = input()
	l = len(t)
	c1 = 0
	p = t.find('1')
	q = t.rfind('1')
	for i in range(p, q):
		if t[i] == '0':
			c1 += 1
	print(c1)


def solve(s):
	cnt_one = 0
	for i in range(len(s)):
		if s[i] == '1':
			cnt_one += 1
	if len(s) == 0 or cnt_one == 0:
		print(0)
		return
	cnt = 0
	ans = 0
	ind = s.index('1')
	for i in range(ind, len(s)):
		if s[i] == '1':
			cnt += 1
		elif s[i] == '0' and cnt != cnt_one:
			ans += 1
	print(ans)
t = int(input())
for _ in range(t):
	s = list(input())
	solve(s)


num_t = int(input())
for _ in range(num_t):
	s = input()
	f = s.find('1')
	if f == -1:
		print('0')
		continue
	l = len(s) - s[::-1].find('1') - 1
	print(l - f + 1 - s.count('1'))


for _ in range(int(input())):
	s = input()
	prev = 0
	ans = 0
	flag = False
	for i in range(len(s)):
		if s[i] == '1':
			if flag:
				ans += i - prev - 1
			flag = True
			prev = i
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	f = len(s)
	for i in range(len(s)):
		if s[i] == '1':
			f = i
			break
	l = -1
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			l = i
			break
	c = 0
	for i in range(f, l + 1):
		if s[i] == '0':
			c += 1
	print(c)


def processing(string):
	count = 0
	first_one_index = string.find('1')
	if first_one_index == -1:
		return 0
	last_one_index = len(string) - 1 - string[len(string)::-1].find('1')
	for i in range(first_one_index, last_one_index):
		if string[i] == '0':
			count += 1
	return count
t = int(input())
for _ in range(t):
	string = input()
	print(processing(string))


k = int(input())
num_list = []
num_list2 = []
for i in range(k):
	num = input()
	num_list.append(num)
i = 0
for num in num_list:
	if '1' not in num:
		print(0)
	else:
		while num[-1] == '0':
			num = num[:-1]
		while num[0] == '0':
			num = num[1:]
		print(num.count('0'))


for _ in [0] * int(input()):
	a = input()
	left = a.find('1')
	right = len(a) - a[::-1].find('1') - 1
	cc = a.count('1')
	if left == -1:
		print(0)
		continue
	print(right - left - cc + 1)


for i in range(int(input())):
	s = input()
	i = s.find('1')
	j = s.rfind('1')
	print(s[i:j].count('0'))


def eraseZero(args: str):
	count = 0
	isbegin = False
	start = 0
	for i in range(len(args)):
		if args[i] == '1' and isbegin:
			count += i - start - 1
			isbegin = False
		if args[i] == '1':
			start = i
			isbegin = True
	return count
num = eval(input())
for i in range(num):
	args = input()
	print(eraseZero(args))


import math
t = int(input())
for _ in range(t):
	s = input()
	l = []
	flag = 0
	for i in range(len(s)):
		if s[i] == '1':
			flag = 1
			l.append(i)
	if s == '0' or flag == 0:
		print(0)
	else:
		var = min(l)
		nia = max(l)
		c = 0
		for i in range(var, nia):
			if s[i] == '0':
				c += 1
		print(c)


t = int(input())
for i in range(t):
	lis = list(map(int, input()))
	check = -1
	res = 0
	for k in range(len(lis)):
		if lis[k] == 1:
			if check == -1:
				check = k
			else:
				res = res + (k - check - 1)
				check = k
	print(res)


for _ in range(int(input())):
	s = input()
	start = s.find('1')
	end = s.rfind('1')
	count = 0
	while start <= end:
		if s[start] == '0':
			count += 1
		start += 1
	if s.count('0') == len(s):
		print(0)
	else:
		print(count)


for i in range(int(input())):
	s = input()
	l = s.find('1')
	r = s.rfind('1')
	zeros = s.count('0', l, r)
	print(zeros)


from collections import Counter
t = int(input())
for x in range(t):
	s = list(input())
	count = Counter(s)
	if count['1'] > 0:
		fi = s.index('1')
		ki = len(s) - s[::-1].index('1') - 1
		ans = ki - fi + 1 - count['1']
		print(ans)
	else:
		print('0')


t = int(input())
for _ in range(t):
	stri = input()
	arr = []
	for i in stri:
		arr.append(int(i))
	n = len(arr)
	ans = []
	for i in range(n):
		if arr[i] == 1:
			ans.append(i)
	diff = 0
	for i in range(1, len(ans)):
		diff += ans[i] - ans[i - 1] - 1
	print(diff)


for i in range(int(input())):
	n = input()
	u = 0
	i = 0
	for i in range(len(n)):
		u = u + 1
		if n[i] == '1':
			break
	for j in range(len(n)):
		l = len(n) - j - 1
		if n[len(n) - j - 1] == '1':
			break
	print(n.count('0', u, l))


for _ in range(int(input())):
	s = input()
	if '1' not in s:
		print(0)
	else:
		a = s.index('1')
		b = s.rindex('1')
		res = 0
		for i in range(a + 1, b):
			if s[i] == '0':
				res += 1
		print(res)


for entry in range(int(input())):
	s = input()
	x = 0
	y = 0
	z = 0
	n = len(s)
	for i in range(n):
		if s[i] == '1' and y == 0:
			y = 1
		if y == 1:
			if s[i] == '0':
				z = z + 1
			if s[i] == '1':
				x = x + z
				z = 0
	print(x)


def solve(s):
	ans = 0
	i = 0
	done = False
	while i < len(s):
		if s[i] == '1' or done:
			while i < len(s) and s[i] == '1':
				i += 1
			temp = 0
			while i < len(s) and s[i] == '0':
				temp += 1
				i += 1
			if i < len(s):
				ans += temp
				done = True
		i += 1
	return ans

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


t = int(input())
for i in range(t):
	s = input()
	pre = []
	add = 0
	for i in s:
		add += int(i)
		pre.append(add)
	num = []
	for i in s:
		num.append(int(i))
	num.reverse()
	res = [sum(num[:i + 1]) for i in range(len(num))]
	cnt = 0
	for i in pre:
		if i == 0:
			cnt += 1
	for i in res:
		if i == 0:
			cnt += 1
	value = s.count('0')
	value1 = s.count('1')
	if value1 == 0:
		print(0)
	else:
		print(value - cnt)


cases = int(input())
for t in range(cases):
	s = input()
	l = len(s)
	c = 0
	z = 0
	i1 = s.find('1')
	i2 = l - 1 - s[::-1].find('1')
	if i1 == -1:
		print(0)
	else:
		s = s[i1:i2 + 1]
		c = 0
		for i in s:
			if i == '0':
				c += 1
		print(c)


t = int(input())
for j in range(t):
	res = [int(x) for x in str(input())]
	c = len(res) - 1
	s = 0
	m = 0
	for i in range(c, -1, -1):
		if res[i] == 0:
			c -= 1
		else:
			break
	for i in range(0, len(res)):
		if res[i] == 1:
			break
		else:
			s += 1
	for i in range(s, c + 1):
		if res[i] == 0:
			m += 1
	print(m)


import sys
from math import log2, floor
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j 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 ** 18
MOD = 10 ** 9 + 7
for _ in range(int(ri())):
	st = ri()
	seen1 = False
	cnt = 0
	for i in range(len(st)):
		if st[i] == '1':
			seen1 = True
		elif seen1:
			cnt += 1
	if seen1:
		for i in range(len(st) - 1, -1, -1):
			if st[i] == '0':
				cnt -= 1
			else:
				break
	print(cnt)


num_lines = int(input())
if num_lines >= 1 and num_lines <= 100:
	lines = []
	for i in range(num_lines):
		lines.append(input())
	for line in lines:
		if len(line) > 1:
			count = 0
			start = -1
			for i in range(len(line)):
				if line[i] == '1':
					if start == -1:
						start = i
					else:
						count += i - start - 1
						start = i
			print(count)
		else:
			print(0)


def erase(s):
	n = len(s)
	c = s.count('1')
	if c < 2:
		return 0
	f = s.index('1')
	p = s[::-1]
	l = n - p.index('1')
	m = s[f:l]
	return m.count('0')
t = int(input())
for _ in range(t):
	k = str(input())
	print(erase(k))


def solve():
	s = input()
	x = s[::-1]
	if s.count('1') == 0:
		print('0')
	else:
		a = s.index('1')
		b = len(s) - 1 - x.index('1')
		print(s[a:b + 1].count('0'))
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	arr = input()
	first = 10 ** 9
	last = -1
	ans = 0
	for i in range(len(arr)):
		if arr[i] == '1':
			first = min(first, i)
			last = max(last, i)
	for i in range(first, last):
		if arr[i] == '0':
			ans += 1
	print(ans)


n = int(input())
a = 1
while a <= n:
	str = input()
	cnt = 0
	ans = 0
	jue = False
	for c in str:
		c = int(c)
		if c == 1:
			jue = 1
		if c == 0 and jue == 1:
			cnt += 1
			jue = True
		if c == 1 and jue == 1:
			ans += cnt
			cnt = 0
	print(ans)
	a += 1


n = int(input())
for i in range(n):
	x = input()
	if '1' in x:
		i = x.index('1')
		i1 = x.rindex('1')
		print(x[i:i1 + 1].count('0'))
	else:
		print(0)


n = int(input())
l = [input() for i in range(n)]
k = [0 for i in range(n)]
for i in range(n):
	if '0' not in l[i] or '1' not in l[i]:
		print(0)
	else:
		a = l[i].find('1')
		b = l[i].rfind('1')
		s = l[i][a:b + 1]
		print(s.count('0'))


def main():
	n = int(input())
	for _ in range(n):
		s = input()
		s = s.strip('0')
		numErase = 0
		for x in s:
			if x == '0':
				numErase += 1
		print(numErase)
main()


for tests in range(int(input())):
	prev = -1
	N = 0
	S = input()
	for cur in range(len(S)):
		if S[cur] == '1':
			if prev != -1:
				N += cur - prev - 1
			prev = cur
	print(N)


t = int(input())
for i in range(t):
	s = input()
	s = int(s)
	s = str(s)[::-1]
	s = int(s)
	if len(str(s)) == 1 and s == 0:
		print(0)
	else:
		print(str(s).count('0'))


from collections import Counter
t = int(input())
for _ in range(t):
	s = input()
	firstOne = -1
	lastOne = -1
	for i in range(len(s)):
		if s[i] == '1':
			if firstOne == -1:
				firstOne = i
			else:
				lastOne = i
	if firstOne > -1 and lastOne > -1:
		print(Counter(s[firstOne:lastOne])['0'])
	else:
		print(0)


t = int(input())
for _ in range(t):
	s = input()
	if s.count('1') > 1:
		x = s.index('1')
		y = len(s) - s[::-1].index('1')
		z = s[x:y].count('0')
		print(z)
	else:
		print('0')


def contarZeros(sequencia):
	iniciou = False
	remocoes = 0
	acumulado = 0
	for i in sequencia:
		if i == '1':
			iniciou = True
			remocoes += acumulado
			acumulado = 0
		elif iniciou:
			acumulado += 1
	return remocoes
nEntradas = int(input())
quantidadeRemocoes = []
for i in range(nEntradas):
	quantidadeRemocoes.append(contarZeros(input()))
for i in quantidadeRemocoes:
	print(i)


for _ in range(int(input())):
	s = input()
	try:
		i = s.index('1')
	except:
		print(0)
		continue
	p = s[::-1]
	j = p.index('1')
	j = len(s) - j - 1
	c = 0
	for k in range(i, j + 1):
		if s[k] == '0':
			c += 1
	print(c)


t = int(input())
for _ in range(t):
	s = input()
	l = 0
	r = len(s) - 1
	tot = 0
	for x in s:
		if x == '0':
			tot += 1
	cnt = 0
	while l < len(s) and s[l] == '0':
		l += 1
		cnt += 1
	while r >= 0 and s[r] == '0':
		r -= 1
		cnt += 1
	print(max(0, tot - cnt))


import math
T = int(input())
for i in range(T):
	a = list(input())
	d = False
	if a.count('1') == 0 or a.count('0') == 0:
		print(0)
		continue
	s = a.index('1')
	a.reverse()
	e = len(a) - a.index('1')
	a.reverse()
	print(a[s:e].count('0'))


for _ in range(int(input())):
	s = input()
	for (k, c) in enumerate(s):
		if c == '1':
			break
	ans = t = 0
	for i in range(k + 1, len(s)):
		if s[i] == '0':
			t += 1
		else:
			ans += t
			t = 0
	print(ans)


x = int(input())
Arr = []
for i in range(0, x):
	Arr.append(int(input()))
for j in Arr:
	ind = []
	z = 0
	j1 = str(j)
	for s in j1:
		if s == '1':
			ind.append(z)
		z = z + 1
	if len(ind) >= 1:
		print(ind[-1] - (len(ind) - 1))
	else:
		print('0')


t = int(input())
for i in range(t):
	s = input()
	was = 0
	last = 0
	ans = 0
	for el in s:
		if was and el == '0':
			last += 1
		if el == '1':
			ans += last
			last = 0
			was = 1
	print(ans)


for j in range(int(input())):
	stri = list(input())
	one = 0
	ct = 0
	for i in range(len(stri) - 1):
		if stri[i] == '1':
			one += 1
		elif one and stri[i] == '0' and ('1' in stri[i + 1:]):
			ct += 1
	print(ct)


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


t = int(input())
for tt in range(t):
	s = input()
	st = ''
	count = 0
	l = 0
	f = False
	r = len(s) - 1
	for i in range(len(s)):
		if s[i] == '1':
			l = i
			f = True
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			r = i
			f = True
			break
	for i in range(l, r):
		if s[i] == '0':
			count += 1
	print('0' if not f else count)


N = int(input())
for _ in range(N):
	s = input().strip()
	beg = None
	end = None
	for i in range(len(s)):
		if s[i] == '1':
			beg = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			end = i
			break
	count = 0
	if beg == None or end == None:
		print(0)
	else:
		while beg <= end:
			if s[beg] == '0':
				count += 1
			beg += 1
		print(count)


for _ in range(int(input())):
	s = input()
	if len(s) < 2:
		print(0)
		continue
	first = s.find('1')
	s1 = s[::-1]
	last = s1.find('1')
	if first == -1:
		print(0)
		continue
	i = first
	while i < len(s) and s[i] == '1':
		i += 1
	if i == len(s) - last - 1 or i == len(s):
		print(0)
	else:
		j = last
		while j < len(s) and s1[j] == '1':
			j += 1
		ans = 0
		for x in range(i, len(s) - j):
			if s[x] == '0':
				ans += 1
		print(ans)


def check(s):
	i = int(s)
	lenn = len(str(i))
	if 2 ** lenn - 1 == i:
		return 1
	else:
		return 0
for t in range(int(input())):
	n = input()
	(f, c) = (0, 0)
	i = int(n)
	if i == 0:
		print(0)
	else:
		while i % 10 == 0:
			i //= 10
		n = str(i)
		if check(n) == 1:
			print(0)
		else:
			for i in n:
				if f:
					if i == '0':
						c += 1
				if i == '1':
					f = 1
			i = -1
			(l, ll, f, cc) = (0, 0, 0, 0)
			print(c)


def result(arr):
	zero = 0
	one = 0
	temp = 0
	for i in arr:
		if i == '1' and one == 0:
			one = 1
		elif one == 1 and i == '0':
			temp += 1
		elif one == 1 and i == '1':
			zero += temp
			temp = 0
	return zero

def main():
	for _ in range(int(input())):
		arr = input()
		print(result(arr))
main()


for _ in range(int(input())):
	s = input()
	s = s.strip('0')
	res = 0
	for i in range(len(s)):
		if s[i] == '0':
			res += 1
	print(res)


x = int(input(''))
for ii in range(x):
	aa = input('')
	b = 0
	c = 0
	a = aa.strip('0')
	for i in a:
		if i == '1':
			c += b
			b = 0
		if i == '0':
			b += 1
	print(c)


for x in range(int(input())):
	s1 = input()
	zeros = 0
	try:
		l = s1.find('1')
		r = s1.rfind('1')
		for x in s1[l:r + 1]:
			if x == '0':
				zeros += 1
		print(zeros)
	except:
		print(zeros)


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


for _ in range(int(input())):
	String = str(input()).strip('0')
	count = 0
	for i in String:
		if i != '1':
			count += 1
	print(count)


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from functools import *
from itertools import permutations, combinations, groupby
import sys
import bisect
import string
import math
import time
import random

def Golf():
	(*a,) = map(int, open(0))

def S_():
	return input()

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

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

def I():
	return int(input())

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 StoI():
	return [ord(i) - 97 for i in input()]

def ItoS(nn):
	return chr(nn + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def GI(V, E, Directed=False, index=0):
	org_inp = []
	g = [[] for i in range(n)]
	for i in range(E):
		inp = LI()
		org_inp.append(inp)
		if index == 0:
			inp[0] -= 1
			inp[1] -= 1
		if len(inp) == 2:
			(a, b) = inp
			g[a].append(b)
			if not Directed:
				g[b].append(a)
		elif len(inp) == 3:
			(a, b, c) = inp
			aa = (inp[0], inp[2])
			bb = (inp[1], inp[2])
			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}):
	mp = [1] * (w + 2)
	found = {}
	for i in range(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 += [1] + [mp_def[j] for j in s] + [1]
	mp += [1] * (w + 2)
	return (h + 2, w + 2, mp, found)

def bit_combination(k, n=2):
	rt = []
	for tb in range(n ** k):
		s = [tb // n ** bt % n for bt in range(k)]
		rt += [s]
	return rt

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['YES', 'NO']
mo = 10 ** 9 + 7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
input = lambda : sys.stdin.readline().rstrip()

def ran_input():
	import random
	n = random.randint(4, 16)
	(rmin, rmax) = (1, 10)
	a = [random.randint(rmin, rmax) for _ in range(n)]
	return (n, a)
show_flg = False
show_flg = True
ans = 0
t = I()
for _ in range(t):
	s = [int(i) for i in input()]
	n = len(s)
	t = [0] * n
	u = [0] * n
	v = [0] * n
	c = 0
	d = 0
	ans = 0
	for i in range(n):
		if s[i] == 1:
			c = 1
		t[i] = c
		if s[-1 - i] == 1:
			d = 1
		u[-1 - i] = d
	for i in range(n):
		v[i] = t[i] & u[i]
		ans += v[i] - s[i]
	print(ans)


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


t = int(input())
for i in range(t):
	co = 0
	li = []
	cpu = 0
	s = input()
	p = s[::-1]
	k = p.count('1')
	if k > 0:
		for j in range(len(p)):
			if s[j] == '1':
				li.append(j)
	if k > 0:
		x = max(li)
		y = 0
		if k >= 1:
			for v in range(len(s)):
				if v != len(s) - 1:
					if s[v] == '1' and s[v + 1] == '1':
						y += 1
			if y == k - 1:
				print(0)
			else:
				for v in range(len(s)):
					if v == x:
						break
					elif s[v] == '0':
						co += 1
				for v in range(len(s)):
					if s[v] == '1':
						break
					else:
						cpu += 1
				print(co - cpu)
	else:
		print(0)


for _ in range(int(input())):
	s = input()
	if len(set(s)) == 1:
		print(0)
	else:
		t = []
		for i in range(len(s)):
			if s[i] == '1':
				t.append(i)
		a = 0
		for i in range(1, len(t)):
			a += t[i] - t[i - 1] - 1
		print(a)


t = int(input())
lis = []
for i in range(t):
	a = input()
	lis.append(a)
for j in lis:
	print(j.strip('0').count('0'))


t = int(input())
for i in range(t):
	n = input()
	k = 0
	for j in n:
		if j == '1':
			k += 1
	if k == 0 or k == len(n):
		print(0)
		continue
	else:
		n = int(n)
		n = str(n)
		if k == len(n):
			print(0)
			continue
		else:
			k1 = 0
			k0 = 0
			fl = False
			kn = 0
			for j in n:
				if j == '1' and k1 + 1 == k and (kn + 1 != len(n)) and (k0 == 0):
					fl = True
					print(0)
					break
				elif j == '1' and k1 != k:
					k1 += 1
				elif j == '0':
					k0 += 1
				kn += 1
				if k1 == k:
					break
			if fl:
				continue
			print(k0)
			continue


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


cases = int(input())
while cases:
	cases -= 1
	case = input().strip('0')
	print(case.count('0'))


x = int(input())
for i in range(x):
	y = list(input())
	r = len(y)
	h = y.count('1')
	if r > 2 and h >= 2:
		for j in range(r):
			y[j] = int(y[j])
		v = 0
		u = 0
		for i in range(r):
			if y[i] == 1:
				v = int(i)
				break
		for i in range(r - 1, -1, -1):
			if y[i] == 1:
				u = int(i)
				break
		s = sum(y[v + 1:u])
		p = u - (v + 1)
		print(p - s)
	else:
		print('0')


for _ in range(int(input())):
	string = list(input())
	one = [idx for (idx, char) in enumerate(string) if char == '1']
	res = 0
	for y in range(len(one) - 1):
		if one[y + 1] - one[y] > 1:
			res += one[y + 1] - one[y] - 1
	print(res)


t = int(input())
for inh in range(0, t):
	n = int(input())
	while n % 10 == 0 and n > 0:
		n = n // 10
	if n == 0:
		print(0)
	else:
		n = str(n)
		k = n.count('0')
		print(k)


def cut(chunk):
	i = 0
	first_one = 0
	second_one = 0
	while i < len(chunk):
		if chunk[i] == '1':
			first_one = i
			break
		i = i + 1
	i = len(chunk) - 1
	while i >= 0:
		if chunk[i] == '1':
			second_one = i
			break
		i = i - 1
	zeros = chunk.count('0', first_one, second_one)
	return zeros
t = int(input())
s = []
for i in range(t):
	c = input()
	s.append(cut(c))
for i in s:
	print(i)


for _ in range(int(input())):
	h = []
	s = input()
	cnt0 = 0
	f = 0
	for x in s:
		if x == '1':
			f = 1
		elif f:
			cnt0 += 1
	for x in s[::-1]:
		if x == '0':
			cnt0 -= 1
		else:
			break
	print(max(0, cnt0))


for t in range(int(input())):
	s = input()
	if '1' in s:
		n = len(s)
		c = 0
		s = list(s)
		s1 = s.copy()
		p = s.index('1')
		s.reverse()
		p1 = s.index('1')
		if p == n - p1:
			print(0)
		else:
			print(s1[p:n - p1].count('0'))
	else:
		print(0)


sol = []
n = int(input())

def solve(m):
	c = 0
	(index1, index2) = (0, 0)
	x = str(m)
	(l, y) = ([], list(x))
	for i in range(len(y)):
		if int(y[i]) == 0:
			y.pop(i)
		else:
			break
	for i in range(len(y) - 1, -1, -1):
		if int(y[i]) == 0:
			y.pop(i)
		else:
			break
	for i in y:
		if int(i) == 0:
			c += 1
	return c
for i in range(n):
	m = int(input())
	sol.append(solve(m))
for i in sol:
	print(i)


for t in range(int(input())):
	s = input().split('1')
	res = 0
	for e in s[1:-1]:
		res += e.count('0')
	print(res)


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


t = int(input())
for i in range(t):
	s = input()
	n = 0
	prev = 0
	c = 0
	for j in range(len(s)):
		if s[j] == '1':
			prev = j
			break
	n = prev
	cur = prev
	for j in range(n + 1, len(s)):
		if s[j] == '1':
			if j - prev == 1:
				prev = j
			else:
				n = j - cur - 1
				c = c + n
			cur = j
	print(c)


t = int(input())
for _ in range(t):
	s = str(int(input()))
	for i in range(len(s) - 1, -1, -1):
		if s[i] != '0':
			break
	s = s[:i]
	print(s.count('0'))


T = int(input())
for t in range(T):
	l = list(input())
	cnt = 0
	if l.count('1') > 0:
		beg = l.index('1')
		end = len(l) - l[::-1].index('1')
		cnt = l[beg:end].count('0')
	print(cnt)


t = int(input())
for i in range(t):
	l = [i for i in input()]
	(first, sec) = (0, 0)
	for i in range(len(l)):
		if l[i] == '1':
			first = i
			break
	for i in range(1, len(l) + 1):
		if l[-i] == '1':
			sec = len(l) + 1 - i
			break
	print(sec - first - l.count('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')
testcases = int(input())
for j in range(testcases):
	string = input()
	inds = []
	gaps = 0
	for s in range(len(string)):
		if string[s] == '1':
			inds.append(s)
	for s in range(len(inds) - 1):
		gaps += inds[s + 1] - 1 - inds[s]
	print(gaps)


t = int(input())
for _ in range(t):
	s = input()
	l = []
	for u in s:
		l.append(u)
	i = 0
	j = len(l) - 1
	c = 0
	if len(l) == 1:
		print(0)
	else:
		while l[i] != '1':
			i += 1
			if i == len(l) - 1:
				break
		while l[j] != '1':
			j = j - 1
			if j == 0:
				break
		for k in range(i, j + 1):
			if l[k] == '0':
				c = c + 1
		print(c)


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


n = int(input())
for i in range(0, n):
	str = input()
	count = 0
	flag = 0
	temp = 0
	for i in range(0, len(str)):
		if flag == 1 and str[i] == '0':
			temp = temp + 1
		elif str[i] == '1':
			if flag == 1:
				count = count + temp
				temp = 0
			else:
				flag = 1
	print(count)


t = int(input())
for _ in range(t):
	x = input()
	aux = 0
	if len(x) < 4:
		if len(x) == 3:
			if x[0] == '1' and x[1] == '0' and (x[2] == '1'):
				print(1)
				continue
			else:
				print(0)
				continue
		else:
			print(0)
			continue
	else:
		for i in range(len(x) - 1):
			if x[i] == '1' and x[i + 1] == '0':
				j = x.find('1', i + 1, len(x)) - 1
				if j >= 0:
					aux += j - i
	print(aux)


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


n = int(input())
for _ in range(n):
	s = str(input())
	ans = 0
	start = -1
	end = -1
	for i in range(len(s)):
		if s[i] == '1' and start == -1:
			start = i
			end = i
		elif s[i] == '1' and start > -1:
			end = i
	for elem in s[start:end]:
		if elem == '0':
			ans += 1
	print(ans)


import math
for _ in range(int(input())):
	s = input()
	c = 0
	for i in range(len(s)):
		if s[i] == '0':
			c += 1
	v = [0] * len(s)
	for i in range(len(s)):
		if s[i] != '1':
			v[i] += 1
			c -= 1
		else:
			break
	for i in range(len(s) - 1, 0, -1):
		if s[i] != '1' and v[i] == 0:
			c -= 1
		else:
			break
	print(c)


t = int(input())
for _ in range(0, t):
	s = list(map(int, input()))
	one_indices = []
	i = 0
	while i < len(s):
		if s[i] == 1:
			one_indices.append(i)
		i += 1
	m = 0
	for i in range(0, len(one_indices) - 1):
		m += one_indices[i + 1] - one_indices[i] - 1
	print(m)


n = int(input())
ans = []
for i in range(n):
	s = input()
	r = s.strip('0')
	t = r.count('0')
	ans.append(t)
sz = len(ans)
z = 0
for i in range(sz):
	print(ans[i])
	i = i + 1


for _ in range(int(input())):
	y = input()
	count = 0
	fi = y.find('1')
	li = y[::-1].find('1')
	li = len(y) - 1 - li
	if fi == -1 or li == fi:
		print('0')
	else:
		for i in y[fi:li + 1]:
			if i == '0':
				count = count + 1
		print(count)


n = int(input())
while n:
	s = input()
	l = []
	c = 0
	x = 0
	for i in range(len(s)):
		if s[i] == '1':
			l.append(i)
			c += 1
	for i in range(len(l) - 1):
		x = x + l[i + 1] - l[i] - 1
	print(x)
	n -= 1


def per(A):
	B = []
	for i in range(len(A)):
		B.append(int(A[i]))
	return B

def kl(A):
	c = 0
	for i in range(len(A)):
		if A[i] == 1:
			c = i
			break
	g = 0
	for i in range(len(A) - 1, 0, -1):
		if A[i] == 1:
			g = i
			break
	A = A[c:g]
	return A.count(0)
a = int(input())
B = []
for i in range(a):
	A = input()
	B.append(kl(per(A)))
for i in range(len(B)):
	print(B[i])


for _ in range(int(input())):
	s = input()
	l = [i for i in s]
	count = 0
	try:
		a = l.index('1')
		b = l.copy()
		l.reverse()
		c = abs(l.index('1') - len(b))
		for i in range(a, c):
			if b[i] == '0':
				count += 1
		print(count)
	except:
		print(0)


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time

def I():
	return int(input())

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

def S():
	return input()

def MS():
	return map(str, input().split())

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

def LI_():
	return [int(i) - 1 for i in input().split()]

def StoI():
	return [ord(i) - 97 for i in input()]

def ItoS(nn):
	return chr(nn + 97)

def input():
	return sys.stdin.readline().rstrip()

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = {False: 'No', True: 'Yes'}
MOD = 10 ** 9 + 7
inf = float('inf')
IINF = 10 ** 10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False

def solve(T):
	s = S()
	ans = 0
	trail_zero = 0
	first = None
	if len(s) == 1:
		print(0)
		return
	for i in range(len(s)):
		if first is None and s[i] == '1':
			first = i
		elif first is not None and s[i] == '0':
			ans += 1
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '0':
			trail_zero += 1
		elif s[i] == '1':
			break
	if ans != 0:
		print(ans - trail_zero)
	else:
		print(0)

def main():
	T = I()
	for i in range(T):
		solve(T)
main()


t = int(input())
q = []
for _ in range(t):
	q.append(list(input()))
for query in q:
	flag = False
	for c in reversed(query):
		if flag == False and c == '0':
			query.pop()
		if c == '1':
			flag = True
res = []
for query in q:
	total = 0
	flag = False
	for c in query:
		if c == '0' and flag:
			total += 1
		if c == '1':
			flag = True
	res.append(total)
for _ in res:
	print(_)


a = int(input())
for i in range(a):
	b = list(input())
	if '1' in b:
		first1 = b.index('1')
		for i in range(len(b)):
			if b[len(b) - i - 1] == '1':
				last1 = i
				break
			else:
				continue
		print(b.count('0') - first1 - last1)
	else:
		print(0)


t = int(input())
for i in range(t):
	s = input()
	l = []
	cc = 0
	for y in s:
		l.append(y)
	while len(l) > 0 and l[0] == '0':
		l.pop(0)
	while len(l) > 0 and l[-1] == '0':
		l.pop()
	cc = l.count('0')
	print(cc)


t = int(input())
for i in range(t):
	s = input()
	f1 = False
	(c1, c2) = (0, 0)
	for i in s:
		if i == '1':
			f1 = True
			c1 += c2
			c2 = 0
		elif i == '0' and f1:
			c2 += 1
	print(c1)


n = int(input())
for i in range(n):
	a = input()
	l = len(a)
	i = 0
	j = l - 1
	pos1 = -1
	pos2 = -1
	count = 0
	if len(a) == 1:
		print(0)
		continue
	if '1' not in a:
		print(0)
		continue
	while i <= l - 1:
		if a[i] == '1':
			pos1 = i
			break
		i += 1
	while j >= 0:
		if a[j] == '1':
			pos2 = j
			break
		j -= 1
	while pos1 <= pos2:
		if a[pos1] == '0':
			count += 1
		pos1 += 1
	print(count)


a = int(input())
for i in range(a):
	x = input()
	e = str(x)
	d = list(e)
	(y, z, count) = (0, 0, 0)
	if len(d) > 1:
		if d.count('1') >= 1:
			y = d.index('1')
			d.reverse()
			z = d.index('1')
			d.reverse()
			for i in range(y, len(d) - z):
				if d[i] == '0':
					count = count + 1
			print(count)
		else:
			print(0)
	else:
		print(0)


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


N = int(input())
for _ in range(N):
	s = input()
	first = -1
	last = -1
	for i in range(len(s)):
		if s[i] == '1':
			if first == -1:
				first = i
			last = i
	cnt = 0
	if first == -1:
		print(0)
		continue
	for i in range(first, last + 1):
		if s[i] == '0':
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	n = input()
	r = 0
	f1 = False
	c = 0
	for i in range(0, len(n)):
		if n[i] == '1':
			i += 1
			while i < len(n) and n[i] != '1':
				c += 1
				i += 1
				f1 = True
			if f1 and i < len(n):
				r += c
				i -= 1
				f1 = False
				c = 0
	print(r)


def count_number_of_zeros(case):
	number_of_zeros = 0
	for character in case:
		if character == '0':
			number_of_zeros += 1
	return number_of_zeros

def remove_size_zeros(case):
	left_index = 0
	for character in case:
		if character == '1':
			break
		left_index += 1
	case = case[left_index:]
	right_index = len(case)
	for index in range(len(case)):
		if case[right_index - 1] == '0':
			right_index -= 1
		else:
			break
	case = case[:right_index]
	return case
test_number = int(input())
for index in range(test_number):
	case = input()
	case_without_zeros = remove_size_zeros(case)
	number_of_zeros = count_number_of_zeros(case_without_zeros)
	print(number_of_zeros)


t = int(input())
for loop in range(t):
	s = input()
	ans = 0
	flag = False
	while len(s) > 0 and s[-1] == '0':
		s = s[:-1]
	while len(s) > 1 and s[0] == '0':
		s = s[1:]
	if s == '0':
		s = ''
	for i in s:
		if i == '0':
			ans += 1
	print(ans)


t = int(input())
while t > 0:
	s = str(input())
	left = -1
	right = -1
	for i in range(0, len(s)):
		if s[i] == '1':
			left = i
			break
	for j in range(len(s) - 1, -1, -1):
		if s[j] == '1':
			right = j
			break
	if left == right:
		print(0)
	else:
		c = 0
		for j in range(left + 1, right):
			if s[j] == '0':
				c += 1
		print(c)
	t -= 1


def delete_zero(a, count):
	x = a.find('1')
	y = a.rfind('1')
	for i in a[x:y]:
		if i == '0':
			count += 1
	return count
_list = []
t = int(input())
for i in range(0, t):
	a = str(input())
	count = 0
	_list.append(delete_zero(a, count))
for i in _list:
	print(i)


def main_function():
	from sys import stdin
	from sys import stdout
	input = stdin.readline
	print = stdout.write
	t = int(input())
	for _ in range(t):
		s = input()[:-1]
		counter = 0
		last = s.find('1')
		for i in range(s.count('1') - 1):
			new = s.find('1', last + 1)
			counter += new - last - 1
			last = new
		print(f'{counter}\n')
main_function()


t = int(input())
for _ in range(t):
	s = input()
	spos = -1
	epos = -1
	for i in range(len(s)):
		if s[i] == '1':
			epos = i
			if spos == -1:
				spos = i
	if spos == -1:
		print(0)
	elif spos == epos:
		print(0)
	else:
		count = 0
		for i in range(spos, epos + 1):
			if s[i] == '0':
				count += 1
		print(count)


for _ in range(int(input())):
	s = input()
	a = s.find('1')
	b = s[::-1].find('1')
	if a == -1 or a + b == len(s) - 1:
		print(0)
	else:
		T = s[a + 1:-b - 1].count('0')
		print(T)


t = int(input())
for i in range(t):
	ch = input()
	if ch == '0':
		print(0)
	else:
		ch1 = ch.replace('0', ' ')
		ch1 = ch1.strip()
		print(ch1.count(' '))


for i in range(int(input())):
	s = input()
	p = list()
	k = 0
	for j in range(len(s)):
		if s[j] == '1':
			k = j
			break
	c = 0
	for j in range(k + 1, len(s), 1):
		if s[j] == '0':
			c = c + 1
		else:
			p.append(c)
			c = 0
	print(sum(p))


t = int(input())
for i in range(t):
	a = input()
	if a.count('1') == 0:
		print(0)
	else:
		x = a.find('1')
		y = a[::-1].find('1')
		print(a[x:len(a) - y - 1].count('0'))


def answer(s):
	zeroCount = 0
	startIndex = -1
	for i in range(len(s)):
		if int(s[i]) == 1:
			if startIndex == -1:
				startIndex = i
			else:
				zeroCount += i - startIndex - 1
				startIndex = i
	return zeroCount
testCount = int(input())
for _ in range(testCount):
	s = input()
	print(answer(s))


t = int(input())
for i in range(t):
	arr = input()
	n = len(arr)
	zero = 0
	c = 0
	flag = 0
	for i in range(0, n - 1):
		if arr[i] == '1':
			try:
				j = arr[i + 1:].index('1')
			except:
				break
			j = j + i + 1
			zero += j - i - 1
	print(zero)


t = int(input())
for _ in range(t):
	res = 0
	stack = []
	s = input()
	flag = False
	for i in range(len(s)):
		if s[i] == '1':
			flag = True
			res += len(stack)
			stack = []
		if flag and s[i] == '0':
			stack.append(1)
	print(res)


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(t,) = I()
while t:
	t -= 1
	s = input()
	n = len(s)
	first = -1
	last = 0
	ones = 0
	for i in range(n):
		if s[i] == '1':
			ones += 1
			last = i
			if first == -1:
				first = i
	if first == -1:
		print(0)
	else:
		print(last - first - ones + 1)


for _ in range(int(input())):
	mi = 10 ** 9
	ma = -1
	s = input()
	n = len(s)
	one = 0
	for i in range(n):
		if s[i] == '1':
			mi = min(mi, i)
			ma = max(ma, i)
			one += 1
	if one:
		print(ma - mi + 1 - one)
	else:
		print(0)


from sys import stdin
input = stdin.readline

def getAns(s):
	if '1' in s:
		firstIndex = s.index('1')
		lastIndex = firstIndex
		for i in range(firstIndex + 1, len(s)):
			if s[i] == '1':
				lastIndex = i
		count = 0
		for i in range(firstIndex, lastIndex):
			if s[i] == '0':
				count += 1
		return count
	else:
		return 0
for _ in range(int(input())):
	print(getAns(input()))


def erase_zero(s):
	l = []
	count = 0
	if set(s) == {'0'}:
		return 0
	for i in range(len(s)):
		if i:
			if s[i] == '0' and s[i - 1] == '1':
				count += 1
			elif s[i] == '0':
				if count:
					count += 1
			elif s[i] == '1' and s[i - 1] == '0' and count:
				l.append(count)
				count = 0
	if l:
		m = sum(l)
	else:
		return 0
	return m
t = int(input())
for _ in range(t):
	s = input()
	print(erase_zero(s))


a = int(input())
for i in range(a):
	num = input()
	num = num.strip('0')
	count = 0
	for i in num:
		if i == '0':
			count += 1
	print(count)


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random

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=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

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 flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)
input = sys.stdin.readline

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

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

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

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

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

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

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

def ddl():
	return collections.defaultdict(list)
for _ in range(ii()):
	s = input()
	(l, r) = (-1, -1)
	for i in range(len(s)):
		if s[i] == '1':
			l = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			r = i
			break
	if l == -1:
		print(0)
	else:
		print(s[l:r + 1].count('0'))


t = int(input())
for i in range(t):
	s = input()
	co = s.count('1')
	if co < 2:
		print(0)
	else:
		s1 = s[::-1]
		l = len(s)
		i1 = s.find('1')
		i2 = l - s1.find('1')
		s = s[i1:i2]
		n = s.count('0')
		print(n)


t = int(input())
for _ in range(t):
	s = input()
	ans = 0
	tmp = 0
	first = True
	for c in s:
		if c == '1':
			if first:
				first = False
			else:
				ans += tmp
			tmp = 0
		else:
			tmp += 1
	print(ans)


def zero_elimination(string):
	count = string.strip('0').count('0')
	return count
for i in range(int(input())):
	print(zero_elimination(input()))


for _ in range(int(input())):
	s = input()
	count = 0
	ans = 0
	flag = 0
	for i in s:
		if i == '1':
			flag = 1
			ans += count
			count = 0
		elif flag == 1 and i == '0':
			count += 1
	print(ans)


n = int(input())
for i in range(n):
	x = input()
	if '1' in x:
		a = x.index('1')
		c = 0
		for j in range(a + 1, len(x)):
			if x[j] == '1':
				c += x.count('0', a, j)
				a = j
		print(c)
	else:
		print(0)


for ___ in range(int(input())):
	line = input()
	lnt = len(line)
	i = 0
	res = 0
	while line[i] != '1':
		i += 1
		if i >= lnt:
			break
	while i < lnt:
		while line[i] == '1':
			i += 1
			if i >= lnt:
				break
		counter = 0
		if i >= lnt:
			break
		while line[i] != '1':
			counter += 1
			i += 1
			if i >= lnt:
				res -= counter
				break
		res += counter
	print(res)


n = int(input())
a = []
for i in range(n):
	s = input().strip('0')
	k = 0
	for i in range(len(s)):
		if s[i] == '0':
			k = k + 1
	a.append(k)
for i in a:
	print(i)


n = int(input())
for i in range(n):
	s = input()
	l = len(s)
	first = s.find('1')
	last = l - s[::-1].find('1') - 1
	if first == -1:
		print(0)
	else:
		count = 0
		for i in range(first, last):
			if s[i] == '0':
				count += 1
		print(count)


t = int(input())
for i in range(t):
	n = input()
	s = e = flag = -1
	for i in range(len(n)):
		if n[i] == '1' and flag == -1:
			s = i
			flag = 10
		if n[i] == '1':
			e = i
	if s == e:
		print('0')
	else:
		n = n[s:e + 1]
		print(n.count('0'))


t = int(input())
q = list()
while t > 0:
	m = 0
	k = 0
	s = input()
	if s.count('1'):
		loc = s.find('1')
	else:
		t = t - 1
		q.append(0)
		continue
	for item in s[loc:]:
		if item == '1':
			m += k
			k = 0
		else:
			k += 1
		loc += 1
	q.append(m)
	t -= 1
for i in q:
	print(i)


t = int(input())
for i in range(t):
	s = input()
	n = s.count('1')
	if n == 0:
		print('0')
		continue
	q = 1
	d = 0
	for j in range(s.index('1') + 1, len(s)):
		if s[j] == '1':
			q += 1
		if s[j] == '0' and q < n:
			d += 1
	print(d)


n = int(input())
z = []
for i in range(n):
	s = str(input())
	s = list(s)
	i = len(s) - 1
	while int(s[i]) == 0:
		s[i] = '-1'
		i -= 1
	i = 0
	while int(s[i]) == 0:
		s[i] = '-1'
		i += 1
	x = 0
	for i in range(len(s) - 1):
		if int(s[i]) == 0:
			x += 1
	z.append(x)
for i in range(len(z)):
	print(z[i])


count = int(input())
while count:
	print(input().strip('0').count('0'))
	count -= 1


from sys import stdin
s = []
for i in range(int(stdin.readline())):
	s.append(stdin.readline())

def improve_pattern(pattern):
	zeros_removed = 0
	pattern = pattern[pattern.find('1'):pattern.rfind('1') + 1]
	while True:
		zero_find = pattern.find('0')
		if zero_find != -1:
			pattern = pattern[:zero_find] + pattern[zero_find + 1:]
			zeros_removed += 1
		else:
			break
	return zeros_removed
for pattern in s:
	print(improve_pattern(pattern))


def process(x, j):
	count = 0
	cfin = 0
	l = len(x)
	for k in range(j, l):
		if x[k] == '0':
			count = count + 1
		elif x[k] == '1':
			cfin = count
	return cfin
t = int(input())
for i in range(t):
	x = input()
	l = len(x)
	j = 0
	while x[j] != '1' and j != l - 1:
		j = j + 1
	if j == l:
		print('0')
	else:
		print(process(x, j))


for _ in range(int(input())):
	s = input()
	(l, r) = (0, 0)
	for i in range(len(s)):
		if s[i] == '1':
			l = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			r = i
			break
	c = 0
	if l == 0 and r == 0:
		print(0)
		continue
	for i in range(l, r + 1):
		if s[i] == '0':
			c += 1
	print(c)


exec(int(input()) * "print(input().strip('0').count('0'));")


t = int(input())

def findfirstOne(s):
	distance = 0
	for item in s:
		if item == '1':
			return distance
		distance += 1
	return 0
answer = []
for item in range(t):
	s = list(input())
	distance = 0
	for i in range(len(s)):
		if s[i] == '1':
			distance += findfirstOne(s[i + 1:])
	answer.append(distance)
for item in answer:
	print(item)


n = int(input())
for i in range(n):
	x = input()
	s = 0
	total = 0
	if x.count('1') != 0:
		for j in range(x.index('1'), len(x)):
			if x[j] == '0':
				s += 1
			else:
				total += s
				s = 0
	print(total)


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


for _ in range(int(input())):
	s = input()
	first_1 = -1
	for i in range(len(s)):
		if s[i] == '1':
			first_1 = i
			break
	if first_1 != -1:
		last_1 = -1
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '1':
				last_1 = i
				break
		res = 0
		for i in range(first_1, last_1):
			if s[i] == '0':
				res += 1
		print(res)
	else:
		print(0)


for _ in range(int(input())):
	s = input()
	(si, li) = (0, 0)
	if len(s) == 1:
		print(0)
	elif s.count('0') == len(s) or s.count('1') == len(s):
		print(0)
	else:
		for i in range(len(s)):
			if s[i] == '1':
				si = i
				break
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '1':
				li = i
				break
		res = 0
		for i in range(si, li + 1):
			if s[i] == '0':
				res += 1
		print(res)


n = int(input())
for i in range(n):
	s = input()
	k = c = x = 0
	for i in s:
		if i == '1' and x == 0:
			x = x + 1
		elif i == '1' and x == 1:
			k = k + c
			c = 0
		elif i == '0' and x == 1:
			c = c + 1
	print(k)


t = int(input())
for x in range(t):
	s = input()
	v = []
	for i in range(len(s)):
		if s[i] == '1':
			v.append(i)
	n = 0
	m = len(v) - 1
	for i in range(m, 0, -1):
		n += v[i] - v[i - 1] - 1
	print(n)


import sys
T = int(sys.stdin.readline())
for i in range(T):
	num = str(sys.stdin.readline().strip())
	if '1' not in num:
		print(0)
	else:
		first_one = num.index('1')
		last_one = len(num) - 1 - num[::-1].index('1')
		print(num[first_one:last_one + 1].count('0'))


t = int(input())
for i in range(0, t):
	st = 0
	txt = input()
	txt = txt.strip('0')
	for c in txt:
		if c == '0':
			st += 1
	print(st)


from sys import stdin
inp = stdin.readline
t = int(inp())
for i in range(t):
	print(inp()[:-1].strip('0').count('0'))


for _ in range(int(input())):
	s = str(input())

	def check(index):
		if index >= 0 and index < len(s):
			return s[index] == '1'
		return False
	(result, pointer) = (0, 0)
	while pointer < len(s):
		if s[pointer] == '0':
			(count, sub_pointer) = (1, pointer + 1)
			while sub_pointer < len(s):
				if s[sub_pointer] == '0':
					count += 1
					sub_pointer += 1
				else:
					break
			if check(pointer - 1) == True and check(sub_pointer) == True:
				result += count
			pointer = sub_pointer
		else:
			pointer += 1
	print(result)


t = int(input())
for i in range(0, t):
	s = input()
	a = s.find('1')
	b = s.rfind('1')
	print(s.count('0', a, b))


t = int(input())
for _ in range(t):
	s = input()
	flag = False
	ans = 0
	right0 = 0
	for i in reversed(range(len(s))):
		if s[i] == '1':
			break
		right0 += 1
	for i in range(len(s)):
		if flag:
			if s[i] == '0':
				ans += 1
		if s[i] == '1':
			flag = True
	if flag:
		print(ans - right0)
	else:
		print(0)


def count(seq):
	while len(seq) > 0 and seq[len(seq) - 1] == '0':
		seq.pop()
	initiate = False
	val = 0
	for j in seq:
		if int(j) == 1:
			initiate = True
			continue
		if initiate == True and int(j) == 0:
			val += 1
	return val
t = int(input())
for i in range(t):
	case = input()
	print(count(list(case)))


t = int(input())
l1 = []
for i in range(t):
	s = input()
	p = 0
	a = list(s.strip('0'))
	for j in range(1, len(a)):
		if a[j] == '0':
			p += 1
	l1.append(p)
for item in l1:
	print(item)


import re
n = int(input())
while n != 0:
	txt = input()
	x = re.sub('10+1', '11', txt)
	y = re.sub('10+1', '11', x)
	print(len(txt) - len(y))
	n = n - 1


ans = []
for t in range(int(input())):
	s = input()
	(start, end) = (float('inf'), -1)
	count = 0
	for i in range(len(s)):
		if s[i] == '0':
			continue
		count += 1
		if i < start:
			start = i
		if i > end:
			end = i
	if count == 0:
		ans.append('0')
	else:
		ans.append(str(end - start + 1 - count))
print('\n'.join(ans))


n = int(input())
for i in range(n):
	s = input()
	borra = 0
	x = 0
	count = 0
	for i in s:
		if i == '1' and x == 0:
			x += 1
		elif i == '0' and x == 1:
			count += 1
		elif i == '1' and x == 1:
			borra += count
			count = 0
	print(borra)


def func(arr):
	print(arr.strip('0').count('0'))
for j in range(int(input())):
	func(input())


q = int(input())
for i in range(q):
	s = input()
	d = {'1': [], '0': []}
	for j in range(len(s)):
		d[s[j]].append(j)
	a = d['1']
	connt = 0
	for i in range(len(a) - 1):
		if a[i + 1] - a[i] > 1:
			connt += a[i + 1] - a[i] - 1
	print(connt)


n = int(input())
b = []
for k in range(n):
	a = input()
	a = list(a)
	no = 0
	flag = 0
	firs = 0
	for i in range(1, len(a) + 1, 1):
		if a[i - 1] == '1' and firs == 0:
			flag = i
			firs = 1
		elif a[i - 1] == '1' and firs != 0:
			no += i - flag - 1
			flag = i
	b.append(str(no))
print('\n'.join(b))


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()):
	s = si()
	s = s.strip('0')
	siz = len(s)
	s = s.replace('0', '')
	print(siz - len(s))


N = int(input())
for i in range(N):
	ans = 0
	S = str(input())
	O = [i for (i, x) in enumerate(S) if x == '1']
	if len(O) == 0 or len(O) == 1:
		print(0)
	else:
		print(O[-1] - O[0] - 1 - (len(O) - 2))


import sys
from collections import defaultdict
t = int(sys.stdin.readline())
for _ in range(t):
	s = sys.stdin.readline()[:-1]
	(z, count, ans) = (False, 0, 0)
	for i in range(len(s)):
		if s[i] == '0':
			if z:
				count += 1
		if s[i] == '1':
			z = True
			ans += count
			count = 0
	print(ans)


t = int(input())
for t in range(t):
	s = input()
	j1 = -1
	j2 = -1
	for i in range(len(s)):
		if j1 == -1:
			if s[i] == '1':
				j1 = i
		elif s[i] == '1':
			j2 = i
	lst = []
	lst = s[j1:j2 + 1]
	s1 = ''.join(lst)
	print(s1.count('0'))


for tc in range(int(input())):
	s = input()
	ans = 0
	i = 0
	j = len(s) - 1
	for i in range(len(s)):
		if s[i] == '1':
			break
	for j in range(len(s) - 1, -1, -1):
		if s[j] == '1':
			break
	if i > j:
		print(0)
		continue
	for i in range(i, j):
		if s[i] == '0':
			ans += 1
	print(ans)


for _ in range(int(input())):
	string = input().strip()
	if string.count('0') == 0 or string.count('1') == 1 or string.count('1') == 0:
		print(0)
		continue
	idx1 = string.find('1')
	idx2 = len(string) - string[::-1].find('1') - 1
	print(string[idx1:idx2 + 1].count('0'))


t = int(input())
for you in range(t):
	s = input()
	count = 0
	start = 0
	arr = []
	for i in range(len(s)):
		if s[i] == '1':
			arr.append(i)
	count = 0
	for i in range(1, len(arr)):
		count += arr[i] - arr[i - 1] - 1
	print(count)


t = int(input())
for i in range(t):
	s = list(map(int, list(input())))
	if set(s) == {0, 1} or set(s) == {1, 0}:
		x = [a for (a, ltr) in enumerate(s) if ltr == 1]
		count = 0
		for m in range(1, len(x)):
			if x[m] - x[m - 1] != 1:
				count += x[m] - x[m - 1] - 1
		print(count)
	else:
		print(0)


for i in range(int(input())):
	s = str(input())
	f = 0
	for x in range(len(s) - 1):
		if s[x] == '1' and s[x + 1] == '0':
			for w in range(x + 2, len(s)):
				if s[w] == '1':
					f += w - x - 1
					break
	print(f)


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


import os
import sys
from math import *
from collections 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')

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

def array():
	return [int(i) for i in input().split()]
for _ in range(int(input())):
	s = input().strip('0')
	print(s.count('0'))


def inp(dtype=str, strip=True):
	s = input()
	res = [dtype(p) for p in s.split()]
	res = res[0] if len(res) == 1 and strip else res
	return res

def problemA():
	t = int(input())
	for _ in range(t):
		s = input()
		res = 0
		for i in range(s.find('1'), s.rfind('1')):
			res += int(s[i] == '0')
		print(res)
problemA()


for i in range(int(input())):
	s = input()
	num = 0
	turn = False
	for c in range(len(s)):
		if s[c] == '0':
			if turn and s[c:].find('1') > 0:
				num += 1
			else:
				continue
		if s[c] == '1':
			if turn:
				continue
			else:
				turn = True
	print(num)


t = int(input())
for i in range(t):
	s = list(input())
	cnt = 0
	one = False
	r = list(reversed(s))
	if '1' in s:
		print(s[s.index('1'):len(s) - r.index('1')].count('0'))
	else:
		print(0)


n = int(input())
while n:
	string = input()
	zeroFound = 0
	totalZero = string.count('0')
	ans = 0
	for i in string:
		if i != '1':
			zeroFound += 1
		else:
			break
	for j in range(len(string) - 1, -1, -1):
		if string[j] != '1':
			zeroFound += 1
		else:
			break
	if zeroFound < totalZero:
		ans = totalZero - zeroFound
	print(ans)
	n -= 1


t = int(input())
for k in range(t):
	s = input()
	if len(s) == 0:
		print('0')
	else:
		l = []
		for i in range(len(s)):
			if s[i] == '1':
				l.append(i)
		c = 0
		l1 = []
		for i in range(len(l) - 1, 0, -1):
			c = l[i] - l[i - 1]
			c -= 1
			l1.append(c)
		print(sum(l1))


t = int(input())
for _ in range(t):
	s = str(int(input()))
	cnt = 0
	hasOne = False
	for i in reversed(s):
		if i == '1':
			hasOne = True
		if i == '0' and hasOne:
			cnt += 1
	print(cnt)


from sys import stdin, stdout
t = int(stdin.readline())
for case in range(t):
	s = stdin.readline()
	xx = []
	for (i, ch) in enumerate(s):
		if ch == '1':
			xx.append(i)
	ans = 0
	if len(xx) == 0 or len(xx) == len(s):
		ans = 0
	else:
		for j in range(1, len(xx)):
			ans += xx[j] - xx[j - 1] - 1
	stdout.write('{}\n'.format(ans))


t = int(input())
for i in range(t):
	case = input()
	count = 0
	startC = False
	auxCount = 0
	for j in case:
		if j == '1':
			startC = True
			count += auxCount
			auxCount = 0
		elif startC:
			auxCount += 1
	print(count)


for i in range(int(input())):
	s = input().strip()
	li_s = [int(i) for i in s]
	first = s.find('1')
	last = len(s) - s[::-1].find('1') - 1
	if first == -1 or last == -1:
		print(0)
		continue
	print(last - first + 1 - sum(li_s))


n = int(input())
for i in range(n):
	s = input()
	length = 0
	t = 0
	start = 0
	for j in range(len(s) - 1, -1, -1):
		if s[j] == '1':
			length = j
			break
	for j in range(length):
		if s[j] == '1':
			t = 1
		if t == 1:
			if s[j] == '0':
				start += 1
	print(start)


t = int(input())
while t:
	s = input()
	(a, b) = (s.find('1'), len(s) - s[::-1].find('1'))
	sm = 0
	if a != -1:
		for i in range(a, b):
			if s[i] == '0':
				sm += 1
	print(sm)
	t -= 1


t = int(input())
for i in range(t):
	s = str(input())
	try:
		c = s.count('1')
		l = len(s)
		x = 0
		z = 0
		ii = s.index('1')
		for j in range(ii, l):
			if s[j] == '1':
				x = x + 1
			else:
				z = z + 1
			if x == c:
				break
		print(z)
	except:
		print('0')


def mult(a):
	r = 1
	for i in a:
		r *= i
	return r
for i in range(int(input())):
	a = input()
	s = 0
	for i in range(a.find('1') + 1, len(a)):
		if a[i] == '0' and '1' in a[i + 1:]:
			s += 1
	print(s)


n = int(input())
i = 0
a = [input() for i in range(n)]

def test(num):
	return num[num.index('1'):len(num) - num[::-1].index('1')].count('0')
while i < n:
	if '1' in a[i]:
		print(test(a[i]))
	else:
		print(0)
	i += 1


t = int(input())
for _ in range(t):
	s = input()
	start = -1
	con = False
	cnt = 0
	for (pos, char) in enumerate(s):
		if char == '1' and (not con):
			start = pos
			con = True
		if char == '1':
			end = pos
	if start != -1:
		for i in range(start, end):
			if s[i] == '0':
				cnt += 1
	print(cnt)


n = int(input())
for i in range(n):
	s = input()
	if '1' in s:
		print(s.count('0', s.index('1'), s.rindex('1')))
	else:
		print(0)


for i in range(int(input())):
	l = input().split('1')
	flag = 0
	for j in range(1, len(l) - 1):
		flag += len(l[j])
	print(flag)


for _ in range(int(input())):
	a = input()
	k = -1
	for i in range(len(a)):
		if a[i] == '1':
			k = i
			break
	k1 = -1
	for i in range(len(a)):
		if a[i] == '1':
			k1 = i
	if k == -1:
		print(0)
	else:
		print(a[k:k1 + 1].count('0'))


t = int(input())
for _ in range(t):
	s = input()
	f = 0
	ans = 0
	c = 0
	p = -1
	for i in range(len(s)):
		if s[i] == '1':
			p = i
			break
	if p != -1:
		for i in range(p, len(s)):
			if s[i] == '0':
				c += 1
			elif s[i] == '1':
				ans += c
				c = 0
				continue
	print(ans)


for _ in range(int(input())):
	s = input()
	n = len(s)
	cnt = 0
	i = 0
	while s[i] == '0':
		i += 1
		if i == n:
			break
	ind1 = i
	i = n - 1
	while s[i] == '0':
		i -= 1
		if i == -1:
			break
	ind2 = i
	print(s[ind1:ind2 + 1].count('0'))


from collections import Counter
t = int(input())
for _ in range(t):
	print(Counter(input().replace('0', ' ').strip())[' '])


t = int(input())

def find(biStr):
	start = 0
	end = 0
	for j in range(len(biStr)):
		if int(biStr[j]) == 1:
			start = j
			break
	for k in range(len(biStr), 0, -1):
		if int(biStr[k - 1]) == 1:
			end = k - 1
			break
	if int(start) == int(end):
		return 0
	else:
		res = 0
		for l in range(len(biStr[start:end])):
			if int(biStr[start:end][l]) == 0:
				res += 1
		return res
for i in range(t):
	biStr = input()
	print(find(biStr))


t = int(input())
for _ in range(t):
	user_input = input()
	zero_list = []
	one_list = []
	flag = False
	count = 0
	for i in range(len(user_input)):
		if user_input[i] == '0':
			zero_list.append(i)
		elif user_input[i] == '1':
			one_list.append(i)
	for z in range(len(zero_list)):
		if len(zero_list) != 0 and len(one_list) != 0 and (zero_list[z] > min(one_list)) and (zero_list[z] < max(one_list)):
			count += 1
	print(count)


def ans(s):
	temp = 'dummy'
	answer = 0
	for i in range(len(s)):
		if s[i] == '1':
			if temp != 'dummy':
				answer += i - temp - 1
			temp = i
	return answer
T = int(input())
for i in range(T):
	s = input()
	print(ans(s))


t = int(input())
for _ in range(t):
	s = input().strip()
	before_one = False
	before_one_cnt = 0
	total = 0
	for c in s:
		if c == '1':
			total += before_one_cnt
			before_one_cnt = 0
			before_one = True
		elif before_one:
			before_one_cnt += 1
	print(total)


def check(str):
	bool = False
	bool1 = False
	count = 0
	final = 0
	for i in range(len(str) - 1):
		if str[i] == '1' and str[i + 1] == '0':
			bool = True
		if bool:
			count += 1
			if str[i] == '0' and str[i + 1] == '1':
				bool1 = True
				bool = False
				count -= 1
				final = final + count
				count = 0
	return (bool1, final)
n = int(input())
while n:
	n -= 1
	str = input()
	(bool, count) = check(str)
	if bool:
		print(count)
	else:
		print(0)


import sys, math
MOD = 998244353
for test_num in range(int(input())):
	s = input()
	(l, r) = (0, len(s) - 1)
	while l < len(s) and s[l] == '0':
		l += 1
	while r > 0 and s[r] == '0':
		r -= 1
	s = s[l:r + 1]
	print(s.count('0'))


t = int(input())
a = []
for i in range(t):
	a.append(input())
for i in a:
	k = 0
	s = 0
	while k < len(i):
		try:
			p = i.index('1', k)
			q = i.index('1', p + 1)
			k = q
			s += q - p - 1
		except:
			break
	print(s)


t = int(input())
for i in range(t):
	s = input()
	l = list(s)
	if l.count('1') == 0:
		print(0)
	else:
		for i in range(len(l)):
			if l[i] == '1':
				strt = i
				break
		l2 = l[strt:]
		for j in range(len(l2)):
			if l2[j] == '1':
				lst = j
		l3 = l2[:lst]
		print(l3.count('0'))


for t in range(int(input())):
	s = input()
	cnt = 0
	pos = -1
	for i in range(len(s)):
		if s[i] == '1':
			if pos == -1:
				pos = i
			else:
				cnt += i - pos - 1
				pos = i
	print(cnt)


t = int(input())
for i in range(t):
	s = input()
	c = 0
	if '1' in s:
		beg = s.index('1')
		end = len(s) - s[::-1].index('1')
		for j in range(beg, end):
			if s[j] == '0':
				c += 1
	print(c)


test = eval(input())
for i in range(test):
	word = input()
	(prev, ctr) = (0, 0)
	(on, off) = (0, 0)
	for i in word:
		if i == '1' and (not on):
			on = 1
		if on and i == '0':
			ctr += 1
		if on and ctr and (i == '1'):
			prev += ctr
			ctr = 0
	print(prev)


t = int(input())
for _ in range(t):
	arr = input()
	last = -1
	ans = 0
	for (i, ch) in enumerate(arr):
		if ch == '1':
			if last != -1:
				ans += i - last - 1
				last = i
			else:
				last = i
	print(ans)


def testcase(s):
	lc = 0
	i = 0
	while i < len(s) - 1:
		if s[i] == '1':
			i += 1
			while i < len(s):
				if s[i] == '0':
					lc += 1
					i += 1
				else:
					break
		else:
			i += 1
	if s[len(s) - 1] == '0' and lc > 0:
		for j in range(len(s) - 1, -1, -1):
			if s[j] == '0':
				lc -= 1
			else:
				break
	print(lc)
t = int(input())
for i in range(t):
	s = input()
	testcase(s)


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


import sys
for _ in range(int(sys.stdin.readline().rstrip())):
	num = sys.stdin.readline().rstrip()
	x = 0
	y = 0
	cnt = 0
	for (idx, i) in enumerate(num):
		if i == '1':
			x = idx
			break
	rev_num = num[::-1]
	for (idx, i) in enumerate(rev_num):
		if i == '1':
			y = len(rev_num) - idx
			break
	for i in range(x, y):
		if num[i] == '0':
			cnt += 1
	print(cnt)


for i in range(int(input())):
	x = str(int(str(int(input()))[::-1]))
	n = 0
	if len(x) == 1:
		print(0)
	else:
		for i in range(len(x)):
			if x[i] == '0':
				n += 1
		print(n)


t = int(input())
for j in range(t):
	c = 0
	s = input()
	count = s.find('1')
	count1 = s.rfind('1')
	c = 0
	for i in range(count, count1):
		if s[i] == '0':
			c += 1
	print(c)


for i in range(int(input())):
	t = input()
	if '1' not in t:
		print(0)
	else:
		s = t[::-1]
		a = t.index('1')
		b = len(t) - s.index('1')
		print(abs(b - (a + t.count('1'))))


from sys import stdin, gettrace
if not gettrace():

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

def solve():
	ss = input()
	zcount = 0
	lzcount = 0
	started = False
	for s in ss:
		if s == '1':
			lzcount = zcount
			started = True
		elif started:
			zcount += 1
	print(lzcount)

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


t = int(input())
for _ in range(t):
	s = input()
	(res, sub) = ([], '')
	while s[0] == '0' or s[-1] == '0':
		if s[0] == '0':
			s = s[1:]
		if not s:
			break
		if s[-1] == '0':
			s = s[:-1]
		if not s:
			break
	print(s.count('0'))


t = int(input())
for i in range(t):
	n = input()
	a = [i for i in n]
	if len(a) == a.count('0'):
		print('0')
		continue
	while a[0] != '1':
		a.pop(0)
	while a[len(a) - 1] != '1':
		a.pop()
	print(a.count('0'))


def amount(string):
	if '1' not in string:
		return 0
	i = 0
	while True:
		if string[i] == '1':
			break
		i += 1
	j = len(string) - 1
	while True:
		if string[j] == '1':
			break
		j -= 1
	if i == j:
		return 0
	count = 0
	for k in range(i + 1, j):
		if string[k] == '0':
			count += 1
	return count

def main():
	strings = []
	line_number = input()
	for i in range(int(line_number)):
		strings.append(str(input()))
	for i in range(int(line_number)):
		print(amount(strings[i]))
main()


for i in range(int(input())):
	s = input()
	a = 0
	for u in range(len(s)):
		if s[u] == '1':
			break
	a = u
	b = 0
	for k in range(len(s) - 1, -1, -1):
		if s[k] == '1':
			break
		else:
			continue
	b = k
	c = 0
	for z in range(a, b):
		if s[z] == '0':
			c += 1
	print(c)


for i in range(int(input())):
	a = input()
	st = 0
	(sm, m) = (0, 0)
	for i in a:
		if i == '0' and st == 1:
			m = m + 1
		elif i == '1' and st == 0:
			st = 1
		elif i == '1' and st == 1 and (m != 0):
			sm += m
			m = 0
	print(sm)


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [input() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [int(input()) for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

class PriorityQueue:

	def __init__(self, l=[]):
		self.q = l
		heapq.heapify(self.q)
		return

	def push(self, n):
		heapq.heappush(self.q, n)
		return

	def pop(self):
		return heapq.heappop(self.q)

def pop_count(x):
	x = x - (x >> 1 & 6148914691236517205)
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	x = x + (x >> 8)
	x = x + (x >> 16)
	x = x + (x >> 32)
	return x & 127
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def main():
	T = Scanner.int()
	for _ in range(T):
		S = Scanner.string()
		l = S.find('1')
		r = S.rfind('1')
		print(S[l:r + 1].count('0'))
main()


for _ in range(int(input())):
	l1 = input().strip()
	i = 0
	flag = 0
	count = 0
	last = 0
	first = 1
	for ele in l1:
		if ele == '1' and count == 0:
			first = i
		if ele == '1':
			count += 1
			last = i
		i += 1
	print(last - first + 1 - count)


for i in range(int(input())):
	print(sum((len(j) for j in map(str, input().lstrip('0').rstrip('0').replace('01', '0 1').replace('10', '1 0').split()) if '0' in j)))


import collections
from sys import stdin, stdout
for _ in range(0, int(input())):
	s = input()
	m = len(s)
	ans = 0
	i = 0
	l = []
	while i < m:
		if s[i] == '1':
			l.append(i)
			break
		i += 1
	i = m - 1
	while i >= 0:
		if s[i] == '1':
			l.append(i)
			break
		i -= 1
	if len(l):
		for i in range(l[0], l[1]):
			if s[i] == '0':
				ans += 1
	print(ans)


for _ in range(int(input())):
	s = input()
	cnt = s.count('0')
	for i in s:
		if i == '1':
			break
		cnt -= 1
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			break
		cnt -= 1
	print(max(cnt, 0))


def erase_zeroes(s):
	one_found = False
	one_index = 0
	no_zeroes = 0
	for i in range(len(s)):
		if s[i] == '1' and (not one_found):
			one_index = i
			one_found = True
		elif s[i] == '1' and one_found:
			if i - one_index > 1:
				no_zeroes += i - one_index - 1
				one_index = i
			else:
				one_index = i
	return no_zeroes

def main():
	test = eval(input())
	for i in range(test):
		s = input()
		print(erase_zeroes(s))
main()


for _ in range(int(input())):
	s = [int(i) for i in input()]
	a = []
	for i in range(len(s)):
		if s[i] == 1:
			a.append(i)
	print(s[min(a):max(a)].count(0)) if a else print(0)


for _ in range(int(input())):
	s = input()
	count = 0
	temp = 0
	for i in range(len(s)):
		if s[i] == '1':
			break
	for j in range(len(s) - 1, -1, -1):
		if s[j] == '1':
			break
	print(s[i:j].count('0'))


t = int(input())
for u in range(t):
	pos = []
	ans = 0
	s = input()
	for i in range(len(s)):
		if s[i] == '1':
			pos.append(i)
	ln = len(pos)
	for i in range(1, ln):
		ans += pos[i] - pos[i - 1] - 1
	print(ans)


for i in range(int(input())):
	s = input()
	past = -1
	mode = 0
	ans = 0
	for j in range(len(s)):
		if s[j] == '1' and mode == 1:
			ans += j - past - 1
			past = j
		elif s[j] == '1':
			past = j
		if past != -1 and s[j] == '0':
			mode = 1
	print(ans)


n = int(input())
for i in range(n):
	a = input()
	x = a.strip('0')
	s = 0
	for j in range(len(x)):
		if x[j] == '0':
			s += 1
	print(s)


t = int(input())
for _ in range(t):
	a = input()
	l = len(a)
	k = 0
	if a.count('1') == 0:
		print(0)
	else:
		for i in range(l):
			if a[i] == '1':
				p = i
				break
		for i in range(l - 1, -1, -1):
			if a[i] == '1':
				q = i
				break
		for i in range(p, q + 1):
			if a[i] == '0':
				k += 1
		print(k)


t = int(input())
for i in range(t):
	s = input()
	f = 0
	d = 0
	for i in range(len(s)):
		if s[i] == '1' and f == 0:
			f = 1
		if s[i] == '0' and f == 1:
			if '1' in s[i:]:
				d = d + 1
	print(d)


for j in range(int(input())):
	a = input()
	if len(a) <= 2:
		print(0)
	else:
		(p, r) = (-1, -1)
		for i in range(len(a)):
			if a[i] == '1':
				r = i
				break
		for i in range(len(a) - 1, -1, -1):
			if a[i] == '1':
				p = i
				break
		if r == -1 or p == -1 or r == p:
			print(0)
		else:
			print(a[r:p + 1].count('0'))


t = int(input())
while t:
	cnt = 0
	s = input()
	try:
		for i in range(s.index('1'), s.rindex('1')):
			if s[i] == '0':
				cnt += 1
	except:
		pass
	print(cnt)
	t -= 1


def check(sequence):
	length = len(sequence)
	sequence = list(map(int, list(sequence)))
	total = sum(sequence)
	result = 0
	revSequence = sequence[::-1]
	index = 0
	revIndex = 0
	if 1 in sequence:
		index = sequence.index(1)
		revIndex = revSequence.index(1)
		result = length - revIndex - index - total
	return result
n = int(input().rstrip())
arr = list()
for i in range(n):
	temp = input().rstrip()
	arr.append(temp)
result = list()
for i in arr:
	result.append(check(i))
for i in result:
	print(i)


import sys
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
sys.setrecursionlimit(10 ** 7)
mod = 1000000007

def IOE():
	try:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	except:
		pass
IOE()
t = int(input())
for _ in range(t):
	ss = input()
	(f, s) = (None, None)
	for i in range(len(ss)):
		if ss[i] == '1':
			f = i
			break
	for i in range(len(ss) - 1, -1, -1):
		if ss[i] == '1':
			s = i
			break
	try:
		print(ss[f:s + 1].count('0'))
	except:
		print(0)


t = int(input())
if t >= 1 and t <= 100:
	Str = [input() for t in range(t)]
	for subStr in Str:
		if len(subStr) >= 1 and len(subStr) <= 100:
			flag = 0
			finalCount = 0
			count = 0
			for i in subStr:
				if i == '1' or flag == 1:
					flag = 1
					if i == '0':
						count += 1
					if i == '1':
						finalCount = count
			print(finalCount)


x = int(input())
count = 0
m = 1
for y in range(0, x):
	z = str(input())
	c = z.strip('0')
	u = c.count('0')
	print(u)


test_cases = int(input())
for _ in range(test_cases):
	s = str(input())
	indices = [idx for idx in range(len(s)) if s[idx] == '1']
	ans = 0
	for (prev, curr) in zip(indices, indices[1:]):
		ans += curr - prev - 1
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	b = 0
	f = False
	e = 0
	c = 0
	for i in range(len(s)):
		if s[i] == '1':
			e = i
			if not f:
				f = True
				b = i
	if b == e:
		print(0)
	else:
		for i in range(b, e):
			if s[i] == '0':
				c += 1
		print(c)


t = int(input())
for _ in range(t):
	S = input()
	cnt = len(S)
	cnt_1 = S.count('1')
	if cnt_1 == 0:
		print(0)
	else:
		cnt_0l = 0
		cnt_0r = 0
		for s in S:
			if s == '0':
				cnt_0l += 1
			else:
				break
		for s in S[::-1]:
			if s == '0':
				cnt_0r += 1
			else:
				break
		print(cnt - cnt_0l - cnt_0r - cnt_1)


t = int(input())
for _ in range(t):
	num = input()
	first_one = num.find('1')
	last_one = num.rfind('1')
	print(num[first_one:last_one].count('0'))


t = int(input())
for i in range(t):
	s = input()
	x = s.rfind('1')
	y = s.find('1')
	su = 0
	for j in range(y, x):
		if s[j] == '0':
			su = su + 1
	req = su
	print(su)


t = int(input())
while t != 0:
	s = input()
	li = list(s)
	if '1' not in li:
		print(0)
	else:
		count = 0
		index1 = li.index('1')
		i = len(li) - 1
		while i >= index1:
			if li[i] == '1':
				index2 = i
				break
			i -= 1
		for i in range(index1, index2, 1):
			if li[i] == '0':
				count += 1
		print(count)
	t = t - 1


for i in range(int(input())):
	s = input()
	a = s.find('1')
	b = s.rfind('1')
	print(len(s[a:b + 1]) - s.count('1'))


t = int(input())
for i in range(t):
	sum = 0
	sum1 = 0
	b = []
	s = input()
	for j in s:
		b.append(j)
	t = 0
	for k in range(len(b)):
		if b[k] == '1':
			for n in range(k + 1, len(b)):
				if b[n] == '0':
					sum = sum + 1
				if b[n] == '1':
					break
	if len(b) > 1:
		q = len(b) - 1
		while q >= 0:
			if b[q] == '0':
				sum1 = sum1 + 1
			if b[q] == '1':
				t = 1
				break
			q = q - 1
	if t == 1:
		print(sum - sum1)
	else:
		print(sum)


def find_zero(string):
	sum1 = 0
	for i in range(len(string)):
		if string[i] == '0':
			sum1 += 1
	return sum1

def find_last(string):
	for i in range(len(string) - 1, -1, -1):
		if string[i] == '1':
			print(find_zero(string[:i]))
			return
	print(0)
	return

def solve(string):
	found = (False, -1)
	for i in range(len(string)):
		if string[i] == '1':
			find_last(string[i:])
			return
	print(0)
	return

def handle_tests():
	number_of_tests = int(input())
	tests = []
	for i in range(number_of_tests):
		test = input()
		tests.append(test)
	for test in tests:
		solve(test)
handle_tests()


t = int(input())
for _ in range(t):
	s = input()
	strtIdx = None
	endIdx = None
	for (i, c) in enumerate(s):
		if c == '1':
			strtIdx = i
			break
	for (i, c) in enumerate(reversed(s)):
		if c == '1':
			endIdx = len(s) - i - 1
			break
	cnt = 0
	if strtIdx == None or endIdx == None:
		print(cnt)
		continue
	for i in range(strtIdx, endIdx):
		if s[i] == '0':
			cnt += 1
	print(cnt)


t = int(input())
for i in range(t):
	s1 = input()
	s2 = s1[::-1]
	if '1' not in s1:
		print(0)
	else:
		x = s1[s1.index('1'):len(s2) - s2.index('1')]
		print(x.count('0'))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = input().rstrip()
	n = len(s)
	ans = 0
	tmp = 0
	x = -1
	for i in range(n):
		if s[i] == '1':
			x = i
			break
	if x == -1:
		print(0)
		continue
	for i in range(x, n):
		if s[i] == '1':
			ans += tmp
			tmp = 0
		else:
			tmp += 1
	print(ans)


def solve(s):
	first_one_index = -1
	last_index = len(s)
	last_one_index = len(s) - 1
	num_inter_zeros = 0
	for index in range(last_index):
		bit = s[index]
		if bit == '1':
			last_one_index = index
		if bit == '1' and first_one_index < 0:
			first_one_index = index
		if bit == '0' and first_one_index >= 0:
			num_inter_zeros += 1
	return num_inter_zeros - (last_index - last_one_index) + 1

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


import re
n = int(input())
result = []
for i in range(0, n):
	inputme = input()
	into = inputme.count('1')
	if into == 1:
		result.append(0)
	elif into != 0:
		intt = re.findall('(1.*1)', inputme)
		z = len(intt[0])
		aa = z - into
		result.append(aa)
	else:
		z = 0
		aa = z - into
		result.append(aa)
for i in range(0, n):
	print(result[i])


def countZeroes(l, n):
	if n > len(l) or l == []:
		return 0
	elif l == ['0'] and n == 1 or (l == ['0', '0'] and n == 2):
		return 0
	count = 1
	length = len(l)
	for i in range(n, length - 1):
		if i < length - 1:
			if l[i] == '0' and l[i + 1] == '1':
				return count
			elif l[i] == '0' and l[i + 1] == '0':
				count += 1
	return count
rnge = int(input())
input1 = []
for i7 in range(rnge):
	input1.append(input())
for i1 in range(len(input1)):
	integer = 0
	l = []
	loc = []
	loc1 = []
	integer = input1[i1]
	for i in str(integer):
		l.append(i)
	i = 0
	for i in range(len(l)):
		if i < len(l) - 1:
			if l[i] == '1' and l[i + 1] == '0':
				count0 = countZeroes(l, i + 1)
				loc.append(i + 1)
	if l[-1] == '0':
		if len(loc) >= 1:
			loc.pop()
	i = 0
	count1 = 0
	for i in range(len(loc)):
		count1 += countZeroes(l, loc[i])
	print(count1)


for _ in range(int(input())):
	s = input()
	flag = 0
	flag2 = 0
	for i in range(len(s)):
		if s[i] == '1':
			flag = 1
			c = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			flag2 = 1
			d = i
			break
	if flag and flag2:
		s2 = s[c:d]
		print(s2.count('0'))
	else:
		print(0)


import os
import sys
from io import BytesIO, IOBase

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')
main()

def test():
	s = input()
	(l, r, c) = (0, 0, 0)
	if '1' in s:
		for i in range(len(s)):
			if s[i] == '1':
				l = i
				break
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '1':
				r = i
				break
		for i in range(l, r + 1):
			if s[i] == '0':
				c += 1
	return c
t = int(input())
for _ in range(t):
	print(test())


def main():
	t = int(input())
	for h in range(t):
		s = input()
		k = 0
		a = set()
		n = len(s)
		f = 0
		for i in range(n):
			if s[i] == '0' and '1' in s[i:] and ('1' in s[:i]):
				k += 1
			else:
				f = 1
		print(k)
main()


import collections
import itertools
import sys
from collections import defaultdict, Counter
from math import sqrt
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 ds(d):
	for i in range(2, d + 1):
		if d % i == 0:
			return i

def main():
	d = inp()
	for _ in range(d):
		v = input()
		s = v.find('1')
		e = v.rfind('1')
		print(len([vv for vv in v[s:e] if vv == '0']))
main()


tests = int(input())
for t in range(tests):
	numbers = list(map(int, list(input())))
	oneWasFound = False
	total = 0
	currentTotal = 0
	r = -1
	l = -1
	for (index, number) in enumerate(numbers):
		if number == 1:
			l = index
			break
	for (index, number) in reversed(list(enumerate(numbers))):
		if number == 1:
			r = index
			break
	for i in range(l, r):
		if numbers[i] == 0:
			total += 1
	print(total)


for _ in range(int(input())):
	s = input()
	k = []
	z = 0
	for i in range(len(s)):
		if s[i] == '1':
			k.append(i)
	if k:
		z = s[k[0]:k[-1]].count('0')
	print(z)


t = int(input())
for i in range(t):
	string = input()
	number_of_ones = 0
	heading_zeros = 0
	trailing_zeros = 0
	encountered_one = False
	for char in string:
		if char == '0':
			trailing_zeros += 1
			if not encountered_one:
				heading_zeros += 1
		elif char == '1':
			encountered_one = True
			number_of_ones += 1
			trailing_zeros = 0
	if encountered_one:
		print(len(string) - number_of_ones - trailing_zeros - heading_zeros)
	else:
		print(0)


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


def RemoveZeroes():
	s = input()
	if s.count('1') < 2:
		print('0')
		return
	first = s.index('1')
	last = 0
	for j in range(len(s) - 1, 0, -1):
		if s[j] == '1':
			last = j
			break
	zeroes = s[first:last].count('0')
	print(zeroes)
t = int(input())
for i in range(t):
	RemoveZeroes()


for i in range(int(input())):
	s = input()
	f = s.find('1')
	l = len(s)
	c = 0
	while l > 0:
		if s[l - 1] == '1':
			break
		l = l - 1
	for k in range(f, l):
		if s[k] == '0':
			c = c + 1
	if f != -1:
		print(c)
	else:
		print('0')


from sys import stdin

def solve(s):
	ans = i = j = anstmp = 0
	while i < len(s):
		(j, anstmp) = (i + 1, 0)
		if s[i] == '1':
			while j < len(s) and s[j] == '0':
				(anstmp, j) = (anstmp + 1, j + 1)
			if j < len(s) and s[j] == '1':
				ans += anstmp
		i += 1
	return ans

def main():
	t = int(stdin.readline().strip())
	for _ in range(t):
		s = stdin.readline().strip()
		print(solve(s))
main()


for i in range(int(input())):
	s = input()
	a = s.split('1')
	total = 0
	for i in range(len(a)):
		total += len(a[i])
	print(total - len(a[0]) - len(a[len(a) - 1])) if len(a) != 1 else print(0)


t = int(input())
while t:
	t = t - 1
	s = input()
	if s.count('1') > 0:
		print(s.count('0') - s.find('1') - s[::-1].find('1'))
	else:
		print('0')


import math

class Read:

	@staticmethod
	def string():
		return input()

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

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

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

def solve():
	s = input()
	l = False
	r = None
	count = 0
	ls = len(s)
	for i in range(ls):
		if s[i] == '1':
			l = True
			r = i
		if l and s[i] == '0':
			count += 1
	if r is not None:
		count = count - (ls - r) + 1
	print(count)
query_count = Read.int()
while query_count:
	query_count -= 1
	solve()


a = int(input())
cont = 0
subcont = 0
for i in range(0, a):
	s = input()
	start = False
	for c in s:
		if c == '1' and start == False:
			start = True
		if c == '0' and start == True:
			subcont = subcont + 1
		if c == '1' and start == True:
			cont = cont + subcont
			subcont = 0
	print(cont)
	cont = 0
	subcont = 0


def main():
	x = list(input())
	f = 0
	for i in range(len(x)):
		if x[i] == '1':
			break
		else:
			f += 1
	x = x[::-1]
	for i in range(len(x)):
		if x[i] == '1':
			break
		else:
			f += 1
	print(x.count('0') - f if x.count('0') - f >= 0 else 0)
T = int(input())
for _ in range(T):
	main()


def countOnes(s):
	num = 0
	for ch in s:
		if ch == '1':
			num += 1
	return num

def contigString(s, totalOness):
	totalOnes = totalOness
	for ch in s:
		if ch == '1':
			totalOnes -= 1
		elif ch == '0' and totalOnes > 0:
			return False
	return True

def removedZerosNum(s, totalOnes):
	zerosRem = 0
	onesFound = False
	for ch in s:
		if ch == '1':
			totalOnes -= 1
			onesFound = True
		elif ch == '0' and totalOnes > 0 and onesFound:
			zerosRem += 1
	return zerosRem
t = int(input())
for test in range(t):
	s = input()
	totalOnes = countOnes(s)
	if contigString(s, totalOnes):
		print(0)
	else:
		print(removedZerosNum(s, totalOnes))


for i in range(int(input())):
	l = []
	s = input().strip('0')
	k = 0
	for j in range(len(s)):
		k += int(s[j])
		l.append(k)
	if k == 0:
		print(0)
	else:
		h = [0] * 101
		for j in range(len(l)):
			h[l[j]] += 1
		d = 0
		for j in h:
			if j > 1:
				d += j - 1
		print(d)


def solve(s):
	s = str(s)
	a = []
	for i in range(len(s)):
		if s[i] == '1':
			a.append(i)
	ans = 0
	for i in range(1, len(a)):
		ans += a[i] - a[i - 1] - 1
	return ans
n = int(input())
for i in range(n):
	s = input()
	print(solve(s))


t = int(input())
for i in range(t):
	c = 0
	j = 0
	p = 0
	a = input()
	for j in range(len(a)):
		if a[j] == '1':
			break
	for p in range(len(a) - 1, j, -1):
		if a[p] == '1':
			break
	for k in range(j, p):
		if a[k] == '0' and j != p - 1:
			c += 1
	print(c)


t = int(input())
for i in range(t):
	s = input()
	f = 0
	a = s.find('1')
	b = s.rfind('1')
	for j in range(a, b):
		if s[j] == '0':
			f += 1
	print(f)


test_case = int(input())
i = 0
while i < test_case:
	string = input()
	ans = string.strip('0').count('0')
	print(ans)
	i += 1


n = int(input())
for i in range(n):
	s = input()
	tam = len(s)
	a = 0
	b = 0
	f = False
	for i in range(tam):
		if s[i] == '1':
			f = True
			a = i
			break
	for i in range(tam - 1, -1, -1):
		if s[i] == '1':
			b = i
			break
	total = 0
	if f == True:
		for i in range(a, b + 1):
			if s[i] == '0':
				total += 1
	print(total)


from collections import Counter

def main():
	for _ in range(int(input())):
		k = Counter(input().strip('0'))
		print(k['0'])
main()


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


t = int(input())

def research(s):
	ans = 0
	frag = False
	for i in range(len(s))[::-1]:
		if s[i] == '0':
			s = s[:i]
		else:
			break
	for g in range(len(s)):
		if s[g] == '1':
			frag = True
		if frag and s[g] == '0':
			ans += 1
	return ans
ans_list = []
for i in range(t):
	s = list(input())
	ans_list.append(research(s))
for i in range(t):
	print(ans_list[i])


for t in range(int(input())):
	s = list(input())
	if '1' not in s:
		print(0)
		continue
	a = s.index('1')
	b = s[::-1].index('1')
	b = len(s) - 1 - b
	res = 0
	for i in range(a, b + 1):
		if s[i] == '0':
			res += 1
	print(res)


n = int(input())
count = 0
d = []
while count < n:
	s = input()
	n1 = [x for x in s if x == '1']
	rm = 0
	t1 = 0
	for x in s:
		if x == '1':
			t1 += 1
		elif t1 == len(n1) or t1 == 0:
			pass
		else:
			rm += 1
	d.append(rm)
	count += 1
for y in d:
	print(y)


n = int(input())
for i in range(n):
	s = input()
	if s.count('0') == len(s):
		print('0')
	else:
		while s[0] == '0':
			s = s[1:]
		while s[len(s) - 1] == '0':
			s = s[:len(s) - 1]
		print(s.count('0'))


n = int(input())
f = []
for x in range(n):
	s = input()
	truemode = False
	count = 0
	for i in range(len(s)):
		if s[i] == '1' and truemode == False:
			truemode = True
		if s[i] == '0' and truemode == True and (s[i + 1:].count('1') > 0):
			count += 1
	f.append(count)
for x in range(len(f)):
	print(f[x])


t = int(input())
for i in range(t):
	ans = 0
	zero = 0
	started = 0
	s = input()
	for x in s:
		if x == '1':
			if started:
				ans += zero
				zero = 0
			else:
				started = 1
		elif started:
			zero += 1
	print(ans)


n = int(input())
for i in range(n):
	q = int(input())
	k = 0
	while q % 10 == 0 and q > 0:
		q = q // 10
	while q > 0:
		if q % 10 == 0:
			k += 1
		q = q // 10
	print(k)


T = int(input())
for t in range(T):
	s = input().strip()
	r = 0
	for i in range(s.find('1'), s.rfind('1')):
		if s[i] == '0':
			r += 1
	print(r)


import sys
for i in range(int(sys.stdin.readline())):
	srt = sys.stdin.readline()
	if '1' not in srt or '0' not in srt:
		sys.stdout.write('0\n')
		continue
	res = 0
	srt = srt[srt.index('1'):srt.rindex('1') + 1]
	for ch in srt:
		if ch == '0':
			res += 1
	sys.stdout.write('{}\n'.format(res))


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


n = int(input())
ll = []
for i in range(n):
	k = input()
	l = [x for x in range(len(k)) if k.find('1', x) == x]
	if len(k) == 1 or k[0] == 0:
		ll.append('0')
	elif len(k) > 1 and len(l) > 0:
		k = k[int(min(l)):int(max(l)) + 1]
		j = len([x for x in range(len(k)) if k.find('0', x) == x])
		ll.append(str(j))
	else:
		ll.append('0')
print('\n'.join(ll))


for _ in range(int(input())):
	s = input()
	n = len(s)
	x = 0
	for i in range(n):
		if s[i] == '1':
			break
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			break
	if i == n - 1 or j == 0:
		print(x)
	else:
		print(s[i:j + 1].count('0'))


for _ in range(int(input())):
	s = input()
	i = len(s) - 1
	while i >= 0:
		if s[i] == '0':
			i -= 1
		else:
			break
	b = s[:i + 1]
	c = 0
	i = 0
	while i < len(b) - 1:
		if b[i] == '1' and b[i + 1] == '0':
			j = i + 1
			while b[j] != '1':
				c += 1
				i = j
				j += 1
		i = i + 1
	print(c)


t = int(input())
for _ in range(t):
	s = input()
	(mode, zeros, zeros_to_add) = (0, 0, 0)
	for i in s:
		if i == '0':
			zeros_to_add += 1
		else:
			if mode == 0:
				mode = 1
			elif mode == 1:
				zeros += zeros_to_add
			zeros_to_add = 0
	print(zeros)


test = int(input())
for _ in range(test):
	s = input()
	n = len(s)
	c0 = c1 = p = g = 0
	for i in range(n):
		if not p:
			if s[i] == '1':
				l = i
				c1 += 1
				p = 1
			else:
				c0 += 1
		elif s[i] == '1':
			c1 += 1
	if c1 == n or c0 == n:
		print(0)
	else:
		for j in range(n - 1, -1, -1):
			if not g:
				if s[j] == '1':
					r = j
					break
		print(len(s[l:r + 1]) - c1)


testcases = int(input())
tests = []
for i in range(testcases):
	tests.append(input())

def func(string):
	totalcount = 0
	for i in range(len(string) - 1):
		if string[i] == '1' and string[i + 1] == '0':
			strtocheck = string[i + 1:]
			if '1' in strtocheck:
				index = string.find('1', i + 1)
				totalcount += index - (i + 1)
			else:
				continue
		else:
			continue
	return totalcount
for i in tests:
	word = str(i)
	print(func(word))


t = int(input())
s = []
f = []
for i in range(t):
	s.append(input())
	if len(s[i]) == 1:
		f.append(0)
	elif s[i].find('1') == -1:
		f.append(0)
	else:
		x = s[i].find('1')
		c = s[i][::-1]
		y = c.find('1')
		li = len(s[i]) - 1 - y
		ans = s[i][x:li].count('0')
		f.append(ans)
for k in range(len(f)):
	print(f[k])


q = int(input())
for p in range(q):
	n = input()
	if '1' not in n:
		print(0)
	else:
		(w, r) = (0, 0)
		for i in range(len(n)):
			if w != 0:
				if n[i] == '0':
					r += 1
			if n[i] == '1':
				w = 1
		while n[i] == '0' and i >= 0:
			r -= 1
			i -= 1
		print(r)


t = int(input())
while t > 0:
	s = str(input())
	s = s.replace('0', ' ').strip()
	print(len(s) - s.count('1'))
	t -= 1


def giv(newstr):
	coolstr = newstr.strip('0')
	if coolstr:
		return coolstr.count('0')
	return 0
for _ in range(int(input())):
	print(giv(input()))


for _ in range(int(input())):
	string = input()
	res = 0
	temp_count = 0
	encountered_one = False
	for c in string:
		if not encountered_one and c == '1':
			encountered_one = True
		elif encountered_one and c == '0':
			temp_count += 1
		elif encountered_one and c == '1':
			res += temp_count
			temp_count = 0
	print(res)


t = int(input())
while t > 0:
	s = input()
	(l, n, p, count) = ([], [], [], 0)
	for i in s:
		l.append(i)
	for i in range(len(l)):
		if l[i] == '1':
			n.append(i)
	try:
		A = n[0]
		B = n[len(n) - 1]
		for i in range(A, B, 1):
			p.append(l[i])
		for i in range(len(p)):
			if p[i] == '0':
				p.remove(p[i])
				p.insert(i, '1')
				count += 1
		print(count)
	except:
		print('0')
	t -= 1


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


n = int(input())
for _ in range(n):
	s = input()
	try:
		s = s[s.index('1'):]
	except:
		pass
	x = 0
	for (i, c) in enumerate(s):
		if '1' not in s[i:]:
			break
		if c == '0':
			x += 1
	print(x)


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

def cont(x):
	(i, j) = (0, 1)
	count = 0
	while i < len(x):
		while j < len(x):
			if x[i] == '1':
				if x[j] == x[i]:
					j += 1
				elif x[j:].count('1') > 0:
					count += 1
					j += 1
				else:
					break
			else:
				j += 1
				break
		i += 1
	return count
for x in s:
	print(cont(x))


n = int(input())
while n != 0:
	number = input()
	first = -1
	last = -1
	lst = []
	index = 0
	for i in number:
		if i == '0':
			if len(lst) == 0:
				lst.append(1)
			else:
				lst.append(lst[index - 1] + 1)
		else:
			if first == -1:
				first = index
			last = index
			if len(lst) == 0:
				lst.append(0)
			else:
				lst.append(lst[index - 1])
		index += 1
	if first == -1:
		print(0)
	else:
		print(lst[last] - lst[first])
	n -= 1


for _ in range(int(input())):
	s = input()
	l = len(s)
	x = s.count('1')
	if x == 0 or x == 1:
		print(0)
	else:
		s1 = s[::-1]
		a = s.index('1')
		b = l - s1.index('1')
		print(s[a:b].count('0'))


for i in range(int(input())):
	a = input()
	s = 0
	b = []
	c = a.count('1')
	t = 0
	if c == 1 or c == 0:
		print(0)
	else:
		for i in a:
			if c == 0:
				break
			elif i == '1':
				t = 1
				c -= 1
			elif t == 1 and c != 0:
				s += 1
		print(s)


for _ in range(int(input())):
	s = input()
	n = len(s)
	i = 0
	while i < n and s[i] != '1':
		i += 1
	j = n - 1
	while j > -1 and s[j] != '1':
		j -= 1
	s = s[i:j + 1]
	cnt = 0
	for a in list(s):
		if a == '0':
			cnt += 1
	print(cnt)


test = int(input(''))
while test:
	test -= 1
	n = input()
	(l, r) = (-1, -1)
	lx = len(n)
	num = 0
	flag = 0
	tmp = 0
	for i in range(len(n)):
		if n[i] == '1':
			flag = 1
		if i != 0 and n[i] == '1' and (n[i - 1] == '0'):
			num += tmp
			tmp = 0
		if n[i] == '0' and flag == 1:
			tmp += 1
	print(num)


t = int(input())
for i in range(t):
	string = input()
	can_I = True
	try:
		first = string.index('1')
	except ValueError:
		print(0)
		can_I = False
	if can_I:
		last = string.rindex('1')
		if last == first:
			print(0)
		else:
			count = 0
			for elem in range(first, last):
				if string[elem] == '0':
					count += 1
			print(count)


t = int(input())
for ti in range(t):
	s = input()
	l1 = l2 = 0
	zc = 0
	ans = 0
	id1 = s.find('1')
	id2 = s.rfind('1')
	if id1 == -1:
		print(0)
	else:
		for i in range(id1, id2):
			if s[i] == '0':
				zc += 1
		print(zc)


t = int(input())
while t:
	t = t - 1
	s = input()
	zer = s.count('0')
	uni = s.count('1')
	if uni == 0:
		print('0')
	else:
		if s.find('1') != -1:
			zerprima = s.find('1')
		else:
			zerprima = 0
		s = s[::-1]
		if s.find('1') != -1:
			zerdopo = s.find('1')
		else:
			zerdopo = 0
		print(zer - zerprima - zerdopo)


for _ in range(int(input())):
	st = str(input())
	arr = []
	count = 0
	c_null = 0
	for i in range(len(st)):
		arr.append([int(st[i]), i])
	for i in range(len(arr)):
		if arr[i][0] == 0:
			arr[i][1] = 0
			c_null += 1
	arr.sort()
	for i in range(c_null, len(arr) - 1):
		count = count + (arr[i + 1][1] - arr[i][1] - 1)
	print(count)


for _ in range(int(input())):
	s = input()
	if set(s) == {'0'}:
		print(0)
		continue
	ll = s.index('1')
	ul = len(s) - s[::-1].index('1') - 1
	s = s[ll:ul + 1]
	print(s.count('0'))


t = int(input())
for q in range(t):
	s = input()
	cnt = 0
	t = 0
	tt = 0
	cur = 0
	for i in s:
		if i == '1' and t == 0:
			t = 1
			if tt:
				cnt += cur
			tt = 1
		elif i == '0' and t == 1:
			t = 0
			cur = 1
		elif i == '0':
			cur += 1
	print(cnt)


from sys import stdin, stdout
import traceback
read = stdin.readline
write = stdout.write
writeln = lambda x: write(str(x) + '\n')

def reads(typ=int):
	return list(map(typ, read().split()))

class Sol:

	@classmethod
	def input(cls):
		s = cls()
		return s

	def solve(self):
		s: str = read()
		num_1 = sum([c == '1' for c in s])
		if num_1 == 0:
			return 0
		distance = s.rindex('1') - s.index('1') + 1
		return distance - num_1
try:
	for _ in range(int(read())):
		writeln(Sol.input().solve())
except Exception as e:
	print('Got exception:', repr(e))
	print(traceback.format_exc())


t = int(input())
for i in range(t):
	s = input()
	if s.count('1') < 2:
		print(0)
	else:
		print(s.rindex('1') - s.index('1') - s.count('1') + 1)


def main():
	count_of_s = int(input())
	l = []
	for i in range(count_of_s):
		l.append(input())
		i += 1
	for s in l:
		print(s.strip('0').count('0'))
main()


for i in range(int(input())):
	s = [x for x in input()]
	l = len(s)
	i = 0
	start = 0
	flag = False
	count = 0
	while i < l:
		if i > 0:
			if s[i - 1] == '1' and s[i] == '0':
				flag = True
				start = i - 1
				i += 1
			elif s[i - 1] == '0' and s[i] == '1' and flag:
				end = i
				for j in range(end - 1, start, -1):
					s[j] = '1'
					count += 1
				i = end
			elif s[i] == '1':
				i += 1
			elif s[i] == '0':
				i += 1
		elif s[i] == '1':
			i += 1
		elif s[i] == '0':
			i += 1
	print(count)


t = int(input())
for i in range(t):
	a = input()
	firstone = a.find('1')
	endone = a.rfind('1')
	newstr = a[firstone:endone + 1]
	print(newstr.count('0'))


t = int(input())
ss = list()
for _ in range(t):
	ss.append(input())

def solve(s):
	s = s.lstrip('0').rstrip('0')
	print(s.count('0'))
for s in ss:
	solve(s)


for i in range(int(input())):
	s = input().strip('0')
	s1 = s.replace('0', '')
	print(len(s) - len(s1))


for _ in range(int(input())):
	s = input()
	s = s.lstrip('0')
	s = s.rstrip('0')
	ans = 0
	for i in s:
		if i == '0':
			ans += 1
	print(ans)


n = int(input())
for _ in range(n):
	s = input()
	fl = [0, 0]
	r = [0]
	su = 0
	b = True
	for i in range(len(s)):
		if s[i] == '1' and b == True:
			fl[0] = i
			b = False
		elif s[i] == '1':
			fl[1] = i
		else:
			continue
		su = su + int(s[i])
		r.append(su)
	if fl[0] == 0 and b == True or fl[1] == 0:
		print(0)
	else:
		print(fl[1] - fl[0] + 1 - r[-1])


import re
for _ in range(int(input())):
	count = 0
	s = input()
	l = re.findall('(?=(10+1))', s)
	for i in l:
		count += len(i) - 2
	print(count)


def binarySearch(arr, x):
	l = 0
	r = len(arr) - 1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def js(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] <= x:
			ans = m
			l = m + 1
		else:
			r = m - 1
	return ans

def jg(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= x:
			ans = m
			r = m - 1
		else:
			l = m + 1
	return ans
from math import *

def ceil(a, b):
	if a % b == 0:
		return int(a / b)
	else:
		return a // b + 1
for __ in range(int(input())):
	s = input()
	x = 0
	y = 0
	o = 0
	e = False
	for i in range(len(s)):
		if s[i] == '1':
			o = 1
		elif o == 1:
			x = i
			e = True
			break
	o = 0
	y = x
	for i in range(x, len(s)):
		if s[i] == '1' and s[i - 1] == '0' and e:
			y = i
	print(s[x:y].count('0'))


t = int(input())
for i in range(t):
	s = input()
	s = list(s)
	flag = 0
	count = 0
	sume = 0
	for j in range(len(s) - 1):
		if s[j] == '1' and s[j] != s[j + 1]:
			flag = 1
		elif s[j] == '0':
			if flag == 1 and s[j] == s[j + 1]:
				sume += 1
			elif flag == 1 and s[j] != s[j + 1]:
				count += sume + 1
				sume = 0
				flag = 0
	print(count)


def sol():
	l = list(input())
	if len(l) == 1:
		print(0)
		return
	if '1' not in l:
		print(0)
		return
	for i in range(len(l)):
		if l[i] == '1':
			lev = i
			break
	for i in range(len(l) - 1, -1, -1):
		if l[i] == '1':
			p = i
			break
	a = l[lev:p].count('0')
	print(a)
for i in range(int(input())):
	sol()


n = int(input())
ans = []
for i in range(n):
	x = input()
	if '1' in x:
		a = x.index('1')
		b = x[::-1].index('1')
		ans.append(x[a:-b - 1].count('0'))
	else:
		ans.append(0)
print(*ans, sep='\n')


t = int(input())
while t:
	m = 0
	s = input().strip('0')
	for i in s:
		if i == '0':
			m += 1
	print(m)
	t -= 1


t = int(input())
string = ''
summ = 0
x = 0
flag = False
for i in range(t):
	x = 0
	summ = 0
	flag = False
	string = input()
	for j in range(len(string)):
		if string[j] == '1':
			flag = True
			summ += x
			x = 0
		elif flag:
			x += 1
	print(summ)


def func(s):
	if not '1' in s:
		return 0
	else:
		st = s[s.find('1'):s.rfind('1') + 1]
		stk = st.replace('1', '')
		return len(stk)
t = int(input())
l = []
for i in range(t):
	l.append(func(input()))
for i in range(t):
	print(l[i])


t = int(input())
for i in range(t):
	string = input()
	start = 0
	end = len(string)
	for i in string:
		if i == '1':
			break
		start += 1
	for i in string[::-1]:
		if i == '1':
			break
		end -= 1
	newstring = string[start:end]
	print(newstring.count('0'))


k = int(input())
lista = []
for l in range(k):
	n = input()
	cont = 0
	cc = 0
	for i in range(len(n) - 1):
		if n[i] == '1' and n[i + 1] == '0':
			for j in range(i + 1, len(n)):
				lista = n[j:]
				p = lista.count('0')
				if p + j == len(n):
					cc = 1
				elif n[j] == '0':
					cont = cont + 1
				elif n[j] == '1':
					break
	print(cont)


t = int(input())
for _ in range(t):
	s = input()
	k = 0
	t = 0
	t1 = 0
	for i in range(len(s)):
		if s[i] == '1':
			t = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			t1 = i
			break
	while t < t1 and t < len(s):
		if s[t] == '0':
			k += 1
		t += 1
	print(k)


n = int(input())
while n > 0:
	flag = True
	n -= 1
	current = 0
	total = 0
	cont = input()
	for i in cont:
		if flag and i == '1':
			flag = False
			current = 0
		elif not flag and i == '1':
			total += current
			current = 0
		else:
			current += 1
	print(total)


for i in range(int(input())):
	a = input()
	cnt = 0
	flag = 0
	tmp_cnt = 0
	for x in a:
		if not flag and x is '1':
			flag = 1
		if x is '0' and flag:
			tmp_cnt += 1
		if x is '1':
			cnt += tmp_cnt
			tmp_cnt = 0
	print(cnt)


n = int(input())
for i in range(n):
	t = str(input())
	h = list(t)
	for j in range(len(h)):
		if h[j] == '0':
			h[j] = 'k'
		else:
			break
	r = len(h)
	for y in range(r - 1, -1, -1):
		if h[y] == '0':
			h[y] = 'k'
		else:
			break
	print(h.count('0'))


T = int(input())
for t in range(T):
	s = input()
	n = len(s)
	distinct_flag = False
	for i in range(1, n):
		if s[i] != s[0]:
			distinct_flag = True
			break
	else:
		print(0)
	if distinct_flag:
		i = s.find('1')
		j = s[::-1].find('1')
		j = n - j
		ans = 0
		for p in range(i, j):
			if s[p] == '0':
				ans += 1
		print(ans)


t = input()
t = int(t)
while t:
	t -= 1
	s = input()
	l = len(s)
	ans = 0
	start = 0
	end = 0
	for i in range(l - 1, -1, -1):
		if s[i] == '1':
			end = i
			break
	for i in range(0, l):
		if s[i] == '1':
			start = i
			break
	if start == end:
		print(0)
	else:
		for i in range(start, end):
			if s[i] == '0':
				ans = ans + 1
		print(ans)


t = int(input())
for x in range(t):
	a = input()
	if '1' in a:
		(l, r) = (a.index('1'), a.rindex('1'))
		print(a[l:r + 1].count('0'))
	else:
		print(0)


for i in range(int(input())):
	x = input()
	print(x.count('0', x.find('1'), x.rfind('1')))


for _ in range(int(input())):
	s = input()
	start = end = -1
	for i in range(len(s)):
		if s[i] == '1':
			start = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			end = i
			break
	print(s[start:end + 1].count('0'))


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


t = int(input())
arr = []
for i in range(t):
	arr.append(input())
for s in arr:
	s = s.split('1')
	a = 0
	b = len(s) - 1
	for i in range(1, b):
		a += len(s[i])
	print(a)


for i in range(int(input())):
	s = input()
	l = -1
	r = -1
	for i in range(len(s)):
		if s[i] == '1':
			r = i
			if l == -1:
				l = i
		ans = 0
	for i in range(l, r):
		if s[i] == '0':
			ans += 1
	print(ans)


def A():
	n = int(input())
	for i in range(n):
		t = 0
		for c in input().strip('0'):
			if c == '0':
				t += 1
		print(t)
A()


for t in range(int(input())):
	s = input()
	s = s.lstrip('0')
	s = s.rstrip('0')
	c = 0
	for i in s:
		if i == '0':
			c += 1
	print(c)


t = int(input())
while t > 0:
	s = input()
	count = 0
	count2 = 0
	for i in range(0, len(s)):
		if s[i] == '1':
			j = i
			count1 = 0
			while j >= 0 and j < len(s) - 1:
				j += 1
				if s[j] == '0':
					count2 = 0
					count1 += 1
				else:
					if s[j] == '1':
						count2 = 1
					j = -1
			if count2 == 1:
				count = count + count1
	print(count)
	t -= 1


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


print('\n'.join((str(input().lstrip('0').rstrip('0').count('0')) for i in range(int(input())))))


T = int(input())
answer = ''
for t in range(T):
	string = input()
	endl = False
	lasts = 0
	result = 0
	for i in range(len(string)):
		if not endl:
			if string[i] == '0':
				continue
			else:
				endl = True
		if string[i] == '0':
			result += 1
			lasts += 1
		if string[i] == '1':
			lasts = 0
	result -= lasts
	answer += str(result) + '\n'
print(answer)


a = int(input())
kickstart = 0
right = 0
answer = 0
final_ans = list()
for i in range(0, a):
	b = input()
	for j in b:
		if j == '1':
			kickstart = 1
			answer = answer + right
			right = 0
		if j == '0' and kickstart == 1:
			right = right + 1
	final_ans = final_ans + [answer]
	kickstart = 0
	right = 0
	answer = 0
for i in final_ans:
	print(i)


t = int(input())
for _ in range(t):
	s = input()
	li = []
	for i in range(len(s)):
		if s[i] == '1':
			li.append(i)
	c = 0
	for i in range(len(li) - 1):
		c += li[i + 1] - li[i] - 1
	print(c)


for i in range(int(input())):
	t = input()
	l = list(t)
	z_ero = l.count('0')
	if len(t) > 2 and z_ero != len(t):
		n = l.index('1')
		l.reverse()
		m = l.index('1')
		m = len(t) - m - 1
		l.reverse()
		l = l[n:m + 1]
		ans = l.count('0')
	else:
		ans = 0
	print(ans)


t = int(input())
for case in range(t):
	string = input()
	if string.count('1') == 0:
		answer = 0
	else:
		answer = string[string.index('1'):string.rindex('1')].count('0')
	print(answer)


def findOccurrences(s, ch):
	return [i for (i, letter) in enumerate(s) if letter == ch]
n = int(input())
for i in range(n):
	yourString = input()
	l = findOccurrences(yourString, '1')
	sum = 0
	for i in range(1, len(l)):
		sum += l[i] - l[i - 1] - 1
	print(sum)


import sys
strings = []
for line in sys.stdin:
	strings.append(line.strip())
testCount = int(strings[0])
strings = strings[1:testCount + 1]
startZerosindex = 0
totalZerosRemoved = 0

def stateA(i, char):
	if char == '0':
		return stateA
	else:
		return stateB

def stateB(i, char):
	global startZerosindex
	if char == '1':
		return stateB
	else:
		startZerosindex = i
		return stateC

def stateC(i, char):
	global totalZerosRemoved
	if char == '0':
		return stateC
	else:
		totalZerosRemoved += i - startZerosindex
		return stateB
currentState = stateA
for string in strings:
	for (i, char) in enumerate(string):
		currentState = currentState(i, char)
	print(totalZerosRemoved)
	totalZerosRemoved = 0
	currentState = stateA


import sys, math
t = int(input())
for test in range(t):
	s = str(input())
	count0 = 0
	countl = 0
	countr = 0
	for i in s:
		if i == '0':
			count0 += 1
	for i in s:
		if i == '0':
			countl += 1
		else:
			break
	for i in range(len(s) - 1, 0, -1):
		if s[i] == '0':
			countr += 1
		else:
			break
	if count0 - (countl + countr) > 0:
		print(count0 - (countl + countr))
	else:
		print(0)


t = int(input())
for _ in range(t):
	s = input()
	k = 0
	while s.find('10') < s.rfind('01') and s.find('10') != -1:
		i = s.find('10') + 1
		s = s[:i] + s[i + 1:]
		k += 1
	print(k)


T = int(input())
result = []
for _ in range(T):
	val = input()
	s = 0
	flag = False
	total = 0
	for i in range(len(val)):
		if val[i] == '1' and flag:
			total += s
			s = 0
			flag = False
		if val[i] == '0' and flag:
			s += 1
		if val[i] == '1' and flag == False:
			flag = True
	result.append(total)
for el in result:
	print(el)


n = int(input())
for i in range(n):
	s = input()
	if s.count('1') == 0:
		print(0)
	else:
		ind1 = 0
		ind2 = -1
		while s[0] == '0':
			s = s[1:]
		while s[-1] == '0':
			s = s[:-1]
		print(s.count('0'))


a = int(input())
ans = [0] * a
for l in range(a):
	p = 0
	q = 0
	s = input()
	if s.count('0') == 0 or s.count('1') == 0 or s.count('1') == 1:
		continue
	for i in range(len(s)):
		if s[i] == '1':
			p = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			q = i
			break
	for i in range(p, q + 1):
		if s[i] == '0':
			ans[l] += 1
for i in ans:
	print(i)


def solution():
	from sys import stdin, stdout
	(_int, _input, _print, _str, _range, _enumerate, _len) = (int, stdin.readline, stdout.write, str, range, enumerate, len)
	n = _int(_input())
	for _ in _range(n):
		s = _input()
		l = 0
		r = 0
		for (i, v) in _enumerate(s):
			if v == '1':
				l = i
				break
		for i in _range(_len(s) - 1, -1, -1):
			if s[i] == '1':
				r = i
				break
		_print(_str(s[l:r].count('0')) + '\n')
solution()


t = int(input())
for x in range(t):
	n = input()
	s = 0
	for i in range(len(n)):
		if n[i] == '1':
			break
	for j in range(len(n) - 1, -1, -1):
		if n[j] == '1':
			break
	for k in range(len(n)):
		s = s + int(n[k])
	h = j + 1 - i - s
	if s == 0:
		print(0)
	else:
		print(h)


r = int(input())
for i in range(r):
	s = input()
	s1 = s[s.find('1'):s.rfind('1')]
	print(s1.count('0'))


t = int(input())
for _ in range(t):
	s = int(input())
	s = str(s)
	s = s[::-1]
	s = int(s)
	s = str(s)
	if s == '0':
		print(0)
	else:
		print(s.count('0'))


n = int(input())
s1 = []
for i in range(n):
	s = input()
	n1 = s.count('0', s.find('1'), s.rfind('1'))
	s1.append(n1)
for j in s1:
	print(j)


for y in range(int(input())):
	lst = list(input())
	i = 0
	j = len(lst) - 1
	flag = 1
	while lst[i] != '1' or lst[j] != '1':
		if i >= j:
			flag = 0
			print(0)
			break
		if lst[i] != '1':
			i += 1
		if lst[j] != '1':
			j -= 1
	if flag == 1:
		lst = lst[i:j + 1]
		print(lst.count('0'))


for _ in range(int(input())):
	x = [int(i) for i in input()]
	size = len(x)
	ans = 0
	for i in range(size):
		if x[i] == 1:
			counter = 0
			for j in range(i + 1, size):
				if x[j] == 0:
					counter += 1
				if x[j] == 1:
					ans += counter
					counter = 0
					break
	print(ans)


n = int(input())
for i in range(n):
	t = input()
	z = len(t)
	u = 0
	i = 0
	j = len(t) - 1
	while t[i] == '0':
		if i < len(t) - 1:
			i = i + 1
		else:
			break
	while t[j] == '0':
		if j > 0:
			j = j - 1
		else:
			break
	for k in range(i, j + 1):
		if t[k] == '0':
			u = u + 1
	if t == '0':
		print('0')
	else:
		print(u)


t = input()
t = int(t)
while t > 0:
	s = input()
	s = str(s)
	x = int(s.find('1'))
	y = int(s.rfind('1'))
	z = str(s[x:y + 1])
	print(int(z.count('0')))
	t -= 1


def remove_zeroes(string):
	has_one = False
	zeroes_count = 0
	zeroes_inbetween = 0
	for letter in string:
		if letter == '0' and has_one:
			zeroes_count += 1
		elif letter == '1':
			zeroes_inbetween = zeroes_count
			if not has_one:
				has_one = True
	return zeroes_inbetween
for _ in range(int(input())):
	print(remove_zeroes(input()))


def zeroes(num):
	return num.strip('0').count('0')
for _ in range(int(input())):
	print(zeroes(input()))


n = int(input())
s1 = []
for i in range(n):
	count = 0
	s = list(input())
	for i in range(len(s)):
		if s[i] == '1':
			s1.append(i)
			break
	for j in range(1, len(s) + 1):
		if s[-j] == '1':
			s1.append(len(s) - j)
			break
	if len(s) > 2:
		if len(s1) > 1:
			for i in range(int(s1[0]), int(s1[1]) + 1):
				if s[i] == '0':
					count += 1
		print(count)
	else:
		print(count)
	s1 = []


def solve(s):
	if len(s) in [0, 1]:
		return 0
	else:
		try:
			start_1_index = s.index('1')
			end_1_index = len(s) - 1 - s[::-1].index('1')
		except ValueError:
			return 0
		count = 0
		for i in range(start_1_index + 1, end_1_index):
			if s[i] == '0':
				count += 1
		return count
T = int(input())
for _ in range(T):
	print(solve(input()))


for _ in range(int(input())):
	s = input()
	c = 0
	one = -1
	for i in range(len(s)):
		if s[i] == '1':
			one = i
			break
	for i in range(len(s)):
		if s[i] == '1':
			c += i - one
			one = i + 1
	print(c)


try:
	n = int(input())
	for _ in range(n):
		a = list(input())
		l = [i for (i, x) in enumerate(a) if x == '1']
		for i in range(len(l) - 1):
			l[i] = l[i + 1] - l[i] - 1
		if len(l) != 0:
			l.pop(-1)
		print(sum(l))
except:
	pass


def program():
	s = input()
	n = len(s)
	a = n
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			a = i
			break
	if a == n:
		print('0')
		return 0
	state = 0
	count = 0
	for i in range(0, a):
		if state == 0 and s[i] == '0':
			continue
		elif state == 0 and s[i] == '1':
			state = 1
		elif state == 1 and s[i] == '0':
			count += 1
	print(count)
t = int(input())
for i in range(t):
	program()


def main():
	t = int(input())
	for i in range(t):
		s = input()
		for k in (1, 2):
			j = 0
			while j < len(s):
				if s[j] == '1':
					break
				j += 1
			s = s[j:]
			s = s[::-1]
		print(s.count('0'))
main()


for _ in range(int(input())):
	s = input()
	if len(s) <= 2 or s.count('1') == 0 or s.count('0') == 0:
		print(0)
		continue
	f = s.index('1')
	l = len(s) - s[::-1].index('1') - 1
	print(s[f:l + 1].count('0'))


import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
INF = 1 << 60
MOD = 10 ** 9 + 7
t = int(input())
for i in range(t):
	s = input()
	ans = s.count('0')
	if ans == len(s):
		print(0)
		continue
	cnt = 0
	for j in s:
		if j == '1':
			break
		cnt += 1
	for j in s[::-1]:
		if j == '1':
			break
		cnt += 1
	print(ans - cnt)


b = int(input())
for i in range(b):
	a = input()
	lul = 0
	for i in a:
		if i == '1':
			lul += 1
	if lul == 0:
		print(0)
	else:
		o1 = 0
		o2 = 0
		k = 0
		for i in a:
			if i == '0':
				o1 += 1
			else:
				break
		a = a[::-1]
		for i in a:
			if int(i) <= len(a) - o1:
				if i == '0':
					o2 += 1
				else:
					break
			else:
				break
		for i in a:
			if i == '0':
				k += 1
		p = k - o1 - o2
		print(p)


def solve(s):
	one = 0
	total_one = s.count('1')
	zero = 0
	for i in s:
		if i == '0':
			if one > 0 and total_one > 0:
				zero += 1
		else:
			one += 1
			total_one -= 1
	print(zero)

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


for t in range(int(input())):
	s = input()
	f_idx = -1
	l_idx = -1
	for i in range(len(s)):
		if s[i] == '1':
			l_idx = i
			if f_idx == -1:
				f_idx = i
	print(s.count('0', f_idx, l_idx))


n = int(input())
sum = 0
for i in range(n):
	sum = 0
	s = str(input())
	for j in range(s.find('1'), s.rfind('1')):
		if s[j] == '0':
			sum += 1
	print(sum)


for i in range(int(input())):
	lin = input()
	zer = 0
	m = False
	for i in range(len(lin)):
		if m and lin[i] == '0':
			zer += 1
		if not m and lin[i] == '1':
			m = True
		if lin[i + 1:].count('1') == 0 and lin[i] == '1':
			break
	print(zer)


t = int(input())
while t > 0:
	t -= 1
	s = input()
	if len(s) == 1:
		print(0)
	else:
		cnt = 0
		o = False
		cur = 0
		for i in range(len(s)):
			if s[i] == '1' and o == False:
				o = True
			elif o == True:
				if s[i] == '0':
					cur += 1
				elif s[i] == '1':
					cnt += cur
					cur = 0
		print(cnt)


import math

def main():
	line = input()
	was1 = 0
	swap = 0
	prev = 1
	zero = 0
	for i in line:
		if i == '1':
			if was1 == 1 and prev == 0:
				swap += zero
				zero = 0
			prev = 1
			was1 = 1
		else:
			if was1 == 1:
				zero += 1
			prev = 0
	print(swap)
t = int(input())
for i in range(t):
	main()


t = int(input())
for i in range(t):
	s = input().strip('0')
	a = list(s)
	if len(a) == 0:
		print(0)
	else:
		print(a.count('0'))


def eraseZeros(num):
	if num.count('1') == 0:
		return 0
	elif len(num) == 1 and num[0] == '1':
		return 0
	else:
		c = 0
		prev = num[0]
		if prev == '1':
			c += 1
		for i in range(1, len(num)):
			if num[i] == '1' and prev != '1':
				c += 1
				prev = '1'
			elif num[i] == '0':
				prev = '0'
		if c == 1:
			return 0
		else:
			(count, count1) = (0, 0)
			pos = num.find('1')
			for i in range(pos, len(num)):
				if num[i] == '0':
					count += 1
			num_r = num[::-1]
			pos = num_r.find('1')
			for i in range(pos):
				if num_r[i] == '0':
					count1 += 1
			return count - count1
t = int(input())
while t:
	num = input()
	val = eraseZeros(num)
	print(val)
	t -= 1


def main():
	t = int(input())
	for _ in range(t):
		cnt = 0
		l = []
		s = input()
		if '1' not in s:
			print(0)
		else:
			cnt = 0
			for i in s:
				if i == '0':
					cnt += 1
				if i == '1':
					l.append(cnt)
					cnt = 0
			if s[len(s) - 1] != 1:
				l.append(cnt)
			if s[0] == '0':
				l.remove(l[0])
			if s[len(s) - 1] == '0':
				l.remove(l[len(l) - 1])
			print(sum(l))
main()


for _ in range(int(input())):
	st = input()
	ans = final = 0
	try:
		ans = st.index('1')
		for i in range(ans + 1, len(st)):
			if st[i] == '1':
				final += i - (ans + 1)
				ans += i - (ans + 1)
				ans = i
		print(final)
	except Exception:
		print(0)


n = int(input())
for i in range(n):
	s = input()
	c = 0
	s = s[s.find('1'):s.rfind('1') + 1]
	for x in s:
		if x == '0':
			c += 1
	print(c)


n = int(input())
for i in range(n):
	a = input()
	lastOne = -1
	total = 0
	for (j, car) in enumerate(a):
		if car == '1':
			if lastOne != -1:
				total += j - lastOne - 1
			lastOne = j
	print(total)


t = int(input())
for i in range(t):
	s = str(input())
	if s.count('1') == 0:
		print(0)
	else:
		j = s.index('1')
		check = 0
		n = 0
		while j < len(s):
			if s[j] == '0':
				check += 1
			elif s[j] == '1' and check != 0:
				n = n + check
				check = 0
			j += 1
		print(n)


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


n = int(input())
for x in range(n):
	s = input()
	c = 0
	l = 0
	r1 = 0
	m = 0
	i = 0
	r1 = -1
	r2 = -1
	for i in range(len(s)):
		if s[i] == '1' and r1 == -1:
			r1 = i
		if s[i] == '1':
			r2 = i
	if r2 > r1:
		i = r1
		m = s[r1:r2 + 1].count('0')
	print(m)


test = int(input())
a = []
while test > 0:
	string = input()
	check = False
	length = len(string)
	i = 0
	count = 0
	count_2 = 0
	temp = length - 1
	while temp >= 0:
		if string[temp] == '1':
			count_2 += 1
		temp -= 1
	while i < length:
		if string[i] == '1':
			check = True
			count_2 -= 1
			i += 1
		else:
			if i > 0 and i < length - 1 and (check == True) and (count_2 > 0):
				if string[i - 1] == '1' and string[i + 1] == '1':
					count += 1
				elif string[i - 1] == '1' or string[i + 1] == '0':
					count += 1
				elif string[i - 1] == '0' or string[i + 1] == '1':
					count += 1
				else:
					count += 1
			i += 1
	value = str(count)
	a.append(value)
	test -= 1
for i in a:
	print(i)


x = ''
for _ in range(int(input())):
	arr = input()
	x = x + str(arr.strip('0').count('0')) + '\n'
print(x)


t = int(input())
for q in range(t):
	s = input()
	(ans, temp) = (0, 0)
	lis = []
	for i in range(len(s)):
		if s[i] == '1':
			lis.append(i)
	for i in range(len(lis) - 1):
		ans += lis[i + 1] - lis[i] - 1
	print(ans)


def binarySearch(arr, x):
	l = 0
	r = len(arr) - 1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def js(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] <= x:
			ans = m
			l = m + 1
		else:
			r = m - 1
	return ans

def jg(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= x:
			ans = m
			r = m - 1
		else:
			l = m + 1
	return ans
from math import *

def ceil(a, b):
	if a % b == 0:
		return int(a / b)
	else:
		return a // b + 1
for __ in range(int(input())):
	s = input()
	if '1' in s:
		x = s.index('1')
		y = len(s) - s[::-1].index('1')
		print(s[x:y].count('0'))
	else:
		print(0)


import sys
input = sys.stdin.readline
Q = int(input())
Query = [list(input().rstrip()) for _ in range(Q)]
for S in Query:
	m = -1
	M = -1
	for (i, s) in enumerate(S):
		if s == '1':
			if m == -1:
				m = i
			M = i
	if m == -1:
		print(0)
	else:
		ans = 0
		for i in range(m, M):
			if S[i] == '0':
				ans += 1
		print(ans)


def main(string):
	sums = 0
	start = 0
	end = 0
	for i in range(len(string)):
		if string[i] == '1':
			start = i
			break
	for j in range(len(string) - 1, -1, -1):
		if string[j] == '1':
			end = j
			break
	new_ = string[start:end + 1]
	state = 0
	for char in new_:
		if char == '1':
			state = 1
		if char == '0' and state == 1:
			sums += 1
	return sums
a = int(input())
for i in range(a):
	print(main(input()))


for i in range(int(input())):
	s = input()
	try:
		(ix1, ix2) = (s.index('1'), len(s) - s[::-1].index('1'))
		ones = s[ix1:ix2].count('1')
		print(ix2 - ix1 - ones)
	except:
		print(0)


t = int(input())
while t:
	s = input()
	arr = []
	for i in range(len(s)):
		if s[i] == '1':
			arr.append(i)
	sum = 0
	for i in range(1, len(arr)):
		sum = sum + arr[i] - arr[i - 1] - 1
	print(sum)
	t = t - 1


t = int(input())
while t != 0:
	f1 = int(0)
	a = input()
	c = 0
	ans = 0
	for s in range(len(a)):
		if a[s] == '1' and f1 == 0:
			c = 0
			f1 = 1
		elif a[s] == '1' and f1 == 1:
			ans += c
			c = 0
		else:
			c += 1
	t -= 1
	print(ans)


from sys import stdin
input()
res = [str(line.strip('\n').strip('0').count('0')) for line in stdin]
print('\n'.join(res))


for j in range(int(input())):
	a = input()
	b = []
	for i in range(len(a)):
		if a[i] == '1':
			b.append(i)
	print(sum((b[i + 1] - b[i] - 1 for i in range(len(b) - 1))))


def getRes(s):
	count = 0
	if s.find('1') == -1:
		return 0
	else:
		s_index = s.find('1')
		e_index = s.rfind('1')
		for i in range(s_index, e_index):
			if s[i] == '0':
				count += 1
		return count
n = int(input())
for n_ in range(n):
	s = input()
	print(getRes(s))


t = int(input())
for _ in range(t):
	s = str(input())
	try:
		first_idx = s.index('1')
		last_idx = len(s) - 1 - s[::-1].index('1')
		print(s[first_idx:last_idx].count('0'))
	except ValueError:
		print(0)


def zero(n):
	out = []
	if '1' not in n:
		return 0
	if '0' not in n:
		return 0
	else:
		f = n.index('1')
		c = 0
		for i in range(f + 1, len(n)):
			if n[i] == '0':
				c += 1
			elif n[i] == '1':
				if c == 0:
					continue
				else:
					out.append(c)
					c = 0
	return sum(out)
n = int(input())
for i in range(n):
	s = input()
	print(zero(s))


t = int(input())
for i in range(t):
	s = input()
	re = 0
	l = []
	ones = []
	zeroes = []
	for i in s:
		if i == 1:
			l.append(i)
		else:
			l.append(i)
	for j in range(len(l)):
		if l[j] == '1':
			ones.append(j)
		else:
			zeroes.append(j)
	for i in range(len(ones) - 1):
		for j in range(len(zeroes)):
			if zeroes[j] > ones[i] and zeroes[j] < ones[i + 1]:
				re += 1
	print(re)


for i in range(int(input())):
	s = input()
	if '1' not in s:
		print(0)
	else:
		n = len(s)
		s1 = s[::-1]
		i1 = s.index('1')
		i2 = s1.index('1')
		cn = 0
		for j in range(i1, n - i2):
			if s[j] == '0':
				cn += 1
		print(cn)


from sys import *
from bisect import bisect_left as bl, bisect_right as br, bisect
from math import *
from time import clock as cl
from itertools import zip_longest as zl
from itertools import groupby as gb
from itertools import combinations as comb
from itertools import combinations_with_replacement as cwr
from collections import defaultdict as dd
from collections import deque as dq
from collections import Counter as c
mod = int(pow(10, 9)) + 7
mod2 = 998244353

def data():
	return input()

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 [[val for i in range(n)] for j in range(m)]
for _ in range(int(data())):
	s = data()
	i = 0
	while s[i] == '0':
		i += 1
		if i == len(s):
			break
	s = s[i:]
	s = s[::-1]
	i = 0
	if len(s) > 0:
		while s[i] == '0':
			i += 1
			if i == len(s):
				break
	s = s[i:]
	print(s.count('0'))


T = int(input())
for i in range(1, T + 1):
	s = list(input())
	if '1' not in s:
		print(0)
	else:
		first = s.index('1')
		for j in range(len(s) - 1, -1, -1):
			if s[j] == '1':
				last = j
				break
		count = 0
		for k in range(first, last):
			if s[k] == '0':
				count += 1
		print(count)


t = int(input())
answer = []
for _ in range(t):
	entry = input()
	n = len(entry)
	start = n
	end = 0
	count = 0
	for i in range(n):
		if entry[i] == '1':
			start = min(start, i)
			end = max(i, end)
		elif start != n and entry[i] == '0':
			count += 1
	if start != n:
		count += end - (n - 1)
	answer.append(str(count))
print('\n'.join(answer))


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


for i in [0] * int(input()):
	ans = 0
	z = 0
	f = 0
	l = input()
	for (v, x) in enumerate(l):
		if x == '1':
			if f == 1:
				ans += l[z:v].count('0')
			z = v
			f = 1
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	while True:
		if len(s) == 0:
			break
		if s[0] == '0':
			s = s[1:]
		else:
			break
	while True:
		if len(s) == 0:
			break
		if s[len(s) - 1] == '0':
			s = s[:len(s) - 1]
		else:
			break
	answer = 0
	for i in range(len(s)):
		if s[i] == '0':
			answer += 1
	print(answer)


for x in range(int(input())):
	a = input()
	b = []
	i = 0
	l = len(a)
	while i < l:
		if a[i] == '1':
			b.append(i)
		i += 1
	l = len(b)
	i = 0
	count = 0
	while i < l - 1:
		count += b[i + 1] - b[i] - 1
		i += 1
	print(count)


for x in range(int(input())):
	s = input()
	temp = []
	count = 0
	final = 0
	for x in s:
		temp.append(x)
		if x == '0' and '1' in temp:
			count += 1
		if x == '1' and '0' in temp:
			final = count
	print(final)


t = int(input())
for _ in range(t):
	n = [*input()]
	mi = -1
	for i in range(len(n)):
		if n[i] == '1':
			mi = i
			break
	for i in range(len(n)):
		if n[len(n) - i - 1] == '1':
			ma = len(n) - i - 1
			break
	if mi == len(n) - 1 or mi == -1:
		print(0)
	else:
		c = 0
		for i in range(mi, ma):
			if n[i] == '0':
				c += 1
		print(c)


t = int(input())
for i in range(t):
	ch = input()
	d = 0
	f = 0
	for i in range(len(ch)):
		if ch[i] == '1':
			d = i
			break
	k = -1
	for c in range(1, len(ch) + 1):
		if ch[-c] == '1':
			f = -c + len(ch)
			break
	s = 0
	for p in range(d, f):
		if ch[p] == '0':
			s = s + 1
	print(s)


t = int(input())
for _ in range(t):
	s = input()
	c = 0
	f = 0
	for i in range(len(s)):
		if s[i] == '1':
			for j in range(i + 1, len(s)):
				if s[j] == '0':
					f += 1
				else:
					c += f
					f = 0
					break
	print(c)


def solve_a():
	n = int(input())
	for _ in range(n):
		a()

def a():
	mode_one = False
	counter = 0
	s = input()
	n = len(s)
	while n > 0 and s[n - 1] == '0':
		n -= 1
	for x in s[:n]:
		if x == '1':
			mode_one = True
		if x == '0' and mode_one is True:
			counter += 1
	print(counter)
solve_a()


n = int(input())
for i in range(n):
	s = input()
	f = s.find('1')
	l = s[::-1].find('1')
	print(s[f:-(l + 1)].count('0'))


def main(s):
	if '1' not in s:
		return 0
	if '0' not in s:
		return 0
	index = find('1', s) + 1
	x = fiind('1', s)
	sum = 0
	while index < x:
		if s[index] == '0':
			sum = sum + 1
		index = index + 1
	return sum

def find(i, arr):
	index = 0
	while index < len(arr):
		if arr[index] == i:
			return index
		index = index + 1

def fiind(i, arr):
	index = len(arr) - 1
	while index >= 0:
		if arr[index] == i:
			return index
		index = index - 1
t = int(input())
for t_itr in range(t):
	s = input()
	res = main(s)
	print(res)


for t in range(int(input())):
	s = input()
	c = s[s.find('1'):s.rfind('1')].count('0')
	print(c)


def Solve(S, n):
	if n == 1:
		return 0
	prev = None
	remove = 0
	ones = []
	for i in range(n):
		if S[i] == '1':
			ones.append(i)
	for i in range(1, len(ones)):
		remove += ones[i] - ones[i - 1] - 1
	return remove
for _ in range(int(input())):
	S = input()
	n = len(S)
	print(Solve(S, n))


for _ in range(int(input())):
	a = input()
	n = len(a)
	c = 0
	j = 0
	k = 0
	for i in range(n):
		if a[i] == '1':
			j = i
			break
	for l in range(n - 1, -1, -1):
		if a[l] == '1':
			k = l
			break
	s = a[j:k + 1]
	if int(s) != 0:
		print(s.count('0'))
	else:
		print(0)


test = int(input())
for i in range(0, test, 1):
	s = str(input())
	yes = 0
	cnt = 0
	zero = 0
	for j in range(1, len(s), 1):
		if s[j - 1] == '1' and yes == 0 and (s[j] == '0'):
			zero = 1
			yes = 1
		elif yes == 1 and s[j] == '0':
			zero += 1
		else:
			cnt += zero
			yes = 0
			zero = 0
	print(cnt)


for _ in range(int(input())):
	s = input()
	l = 10000000009
	r = -10000000009
	ans = 0
	for i in range(len(s)):
		if s[i] == '1':
			l = min(l, i)
			r = max(r, i)
			ans += 1
	if ans == 0:
		print('0')
	else:
		print(r - l + 1 - ans)


T = int(input())
for t in range(T):
	str = input()
	begin = -1
	end = -2
	cnt = 0
	for i in range(len(str)):
		if str[i] == '1':
			cnt += 1
			if begin == -1:
				begin = i
			end = i
	print(end - begin + 1 - cnt)


for _ in range(int(input())):
	s = input()
	lt = []
	ans = 0
	for i in range(len(s)):
		if s[i] == '1':
			lt.append(i)
	for i in range(len(lt) - 1):
		if lt[i + 1] - lt[i] > 1:
			ans += lt[i + 1] - lt[i] - 1
	print(ans)


def erase(s):
	c = 0
	if len(s) == 1:
		return 0
	ns = ''
	if '1' in s:
		ns = s[s.index('1')]
		for i in range(s.index('1'), len(s) - 1):
			if ns[-1] == '1' and s[i] == '0' and ('1' in s[i:]):
				ns += '1'
				c += 1
	return c
tc = int(input())
for i in range(tc):
	s = input()
	print(erase(s))


t = int(input())
for _ in range(t):
	a = list(input())
	if a.count('0') == len(a):
		print(0)
		continue
	first = 0
	for (j, i) in enumerate(a):
		if i == '1':
			first = j
			break
	last = 0
	for (j, i) in enumerate(a):
		if i == '1':
			last = j
	b = a[first:last + 1]
	print(b.count('0'))


import sys

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j 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 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	S = input()
	N = len(S)
	if S.count('1') == 0:
		print(0)
		continue
	cnt = S.count('0')
	for a in S:
		if a == '0':
			cnt -= 1
		else:
			break
	for a in S[::-1]:
		if a == '0':
			cnt -= 1
		else:
			break
	print(cnt)


x = int(input())
for i in range(x):
	s = input()
	(b, e, k) = (s.find('1'), s.rfind('1'), 0)
	for j in range(b, e):
		if s[j] == '1':
			k = k + 1
	print(e - b - k)


n = int(input())
for _ in range(n):
	z = 0
	s = input()
	l = s.find('1')
	if l >= 0:
		r = s.rfind('1')
		z = s[l:r + 1].count('0')
	print(z)


f = int(input())
for q in range(f):
	s = input()
	a = 0
	b = 0
	c = []
	for i in range(len(s)):
		c.append(s[i])
	for i in range(len(s)):
		if s[i] == '1':
			break
		a += 1
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			break
		b += 1
	print((len(s) - (a + b + c.count('1'))) * int(c.count('1') > 0))


for _ in range(int(input())):
	S = input()
	if S.count('1') == 0:
		print(0)
	else:
		A = S[S.index('1'):S.rfind('1') + 1]
		print(A.count('0'))


for _ in range(int(input())):
	n = int(input())
	n = int(str(n)[::-1])
	if str(n).count('1') != 0:
		print(str(n).count('0'))
	else:
		print(0)


def main():
	q = int(input())
	for _ in range(q):
		s = input()
		o = False
		inc = 0
		i = 0
		for x in range(len(s)):
			if s[x] == '1':
				i = x
		for x in range(len(s)):
			if s[x] == '0' and o == True and (x < i):
				inc += 1
			if s[x] == '1':
				o = True
		print(inc)
main()


def continuousOnes(word):
	res = 0
	(first, last) = (0, len(word) - 1)
	while first < last and word[first] != '1':
		first += 1
	while last > 0 and word[last] != '1':
		last -= 1
	for i in range(first, last):
		if word[i] == '0':
			res += 1
	return res
for _ in range(int(input())):
	word = input()
	print(continuousOnes(word))


input_filename = ''
if input_filename:
	with open(input_filename, 'r') as file:
		text = file.read().splitlines()
line_number = -1

def iinput():
	if not input_filename:
		return input()
	else:
		global line_number
		line_number += 1
		return text[line_number]
N = int(iinput())
for k in range(N):
	x = iinput()
	sum = 0
	i = 0
	n = len(x)
	while i < n and x[i] == '0':
		i += 1
	while i < n:
		temp_sum = 0
		while i < n and x[i] == '1':
			i += 1
		while i < n and x[i] == '0':
			temp_sum += 1
			i += 1
		if i < n:
			sum += temp_sum
	print(sum)


n = int(input())
for i in range(0, n):
	s = input()
	flag = False
	left = 0
	for j in range(0, len(s)):
		if flag and s[j] == '0':
			left += 1
		if s[j] == '1':
			flag = True
	right = 0
	for j in range(len(s) - 1, -1, -1):
		if s[j] == '1':
			break
		right += 1
	if left - right < 0:
		print(0)
	else:
		print(left - right)


(t, arr) = (int(input()), [])
for i in range(t):
	(text, summ, count, k) = (input(), 0, 0, -1)
	for num in text:
		if num == '0' and k == -1:
			continue
		elif num == '1' and k == -1:
			k = 0
			continue
		elif num == '0':
			count += 1
		elif num == '1' and count > 0:
			summ += count
			count = 0
	arr.append(summ)
for i in arr:
	print(i)


t = int(input())
for _ in range(t):
	s = list(input())
	l = len(s)
	for i in range(l):
		if s[i] == '0':
			s[i] = '1'
		else:
			break
	for i in range(l - 1, -1, -1):
		if s[i] == '0':
			s[i] = '1'
		else:
			break
	print(l - s.count('1'))


import sys
queries = int(sys.stdin.readline())
for query in range(queries):
	text = sys.stdin.readline().strip()
	pos = 0
	answer = 0
	while pos < len(text) and text[pos] != '1':
		pos += 1
	pos += 1
	pos_right = len(text) - 1
	while pos_right >= 0 and text[pos_right] != '1':
		pos_right -= 1
	while pos < pos_right:
		if text[pos] == '0':
			answer += 1
		pos += 1
	print(answer)


numTestcases = int(input())
for i in range(numTestcases):
	cNum = list(input())
	try:
		first1 = cNum.index('1')
	except ValueError:
		print(0)
		continue
	for c in range(len(cNum) - 1, -1, -1):
		if cNum[c] == '1':
			last1 = c
			break
	numRemove = cNum[first1:last1 + 1].count('0')
	print(numRemove)


import sys
import math
from dataclasses import dataclass
t = int(input())
for ik in range(t):
	s = input()
	(ini, fin, ans) = (len(s), len(s), 0)
	for i in range(len(s)):
		if s[i] == '1':
			ini = i
			break
	for i in range(len(s)):
		if s[i] == '1':
			fin = i
	for i in range(ini, fin, 1):
		if s[i] == '0':
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	if not '1' in s or not '0' in s:
		print('0')
		continue
	i = 0
	for (idx, c) in enumerate(s):
		if s[idx] == '1':
			i = idx
			break
	s = s[i:]
	i = len(s)
	for idx in range(len(s) - 1, -1, -1):
		if s[idx] == '1':
			i = idx
			break
	s = s[:i + 1]
	print(s.count('0'))


test_cases = int(input())
for i in range(test_cases):
	s = input()
	possible_erase = 0
	erase = 0
	last_character = s[0]
	start_count = False
	for c in s[1:]:
		if last_character == '1' and c == '0':
			possible_erase += 1
			start_count = True
		elif last_character == '0' and c == '0' and start_count:
			possible_erase += 1
		elif c == '1' and start_count:
			start_count = False
			erase += possible_erase
			possible_erase = 0
		last_character = c
	print(erase)


def erasing_zeroes(s):
	stack = []
	ans = 0
	i = 0
	while i < len(s):
		if s[i] == '1':
			tmp = 0
			for j in range(i + 1, len(s)):
				if s[j] == '1':
					ans += tmp
					break
				else:
					tmp += 1
		i += 1
	return ans
t = int(input())
for i in range(t):
	s = input()
	print(erasing_zeroes(s))


T = int(input())
for t in range(T):
	s = input()
	n = len(s)
	pos = -1
	for i in range(n):
		if s[i] == '1':
			pos = i
			break
	if pos == -1:
		print(0)
		continue
	count = 0
	ans = 0
	for i in range(pos, n):
		if s[i] == '0':
			count += 1
		else:
			ans += count
			count = 0
	print(ans)


t = int(input())
for _ in range(t):
	count = 0
	indi = 0
	indh = 0
	s = input()
	for i in range(len(s)):
		if s[i] == '1':
			indi = i
			break
	for j in range(len(s) - 1, 0, -1):
		if s[j] == '1':
			indh = j
			break
	for k in range(indi, indh):
		if s[k] == '0':
			count += 1
	print(count)


t = int(input())
for __ in range(t):
	s = list(input())
	p = -1
	ans = 0
	for i in range(len(s)):
		if s[i] == '0':
			continue
		if p == -1:
			p = i
		elif p == i - 1:
			p = i
		else:
			ans += i - p - 1
			p = i
	print(ans)


import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	s = input().strip('0')
	flag = -1
	ans = 0
	c = -2
	for j in range(len(s)):
		if s[j] == '0':
			if flag == -1:
				flag = j
			c = j
		else:
			ans += c - flag + 1
			flag = -1
			c = -2
	print(ans)


lines = int(input())
for j in range(0, lines):
	num = input()
	num = str(num)
	p1 = 0
	p2 = 0
	cnt = 0
	for k in range(0, len(num)):
		p1 = k
		if num[k] == '1':
			break
	if p1 == len(num) - 1:
		print(0)
		continue
	p2 = p1
	for i in range(p1 + 1, len(num)):
		if num[i] == '1' and p1 == p2:
			continue
		elif num[i] == '1' and p1 != p2:
			cnt = cnt + (p2 - p1)
			p1 = p2 = i
		else:
			p2 += 1
	print(cnt)


for _ in range(int(input())):
	s = list(input())
	if '1' in s:
		x = s.count('1')
		m = 0
		ans = 0
		i = s.index('1')
		while m < x:
			if s[i] == '1':
				m += 1
			else:
				ans += 1
			i += 1
		print(ans)
	else:
		print(0)


t = int(input())
while t != 0:
	arr = list(map(int, input()))
	startBit = 0
	endBit = 0
	for i in range(len(arr)):
		if arr[i] == 1:
			startBit = i
			break
	for i in range(len(arr) - 1, 0, -1):
		if arr[i] == 1:
			endBit = i
			break
	if len(arr) == 1:
		print(0)
	else:
		numOfZero = 0
		for i in range(startBit, endBit):
			if arr[i] == 0:
				numOfZero += 1
		print(numOfZero)
	t -= 1


T = int(input())
result = ''
for t in range(T):
	counter = 0
	n = input()
	n = n.strip('0')
	for ch in range(len(n) - 1):
		if n[ch] == '0':
			counter += 1
	result += '\n' + str(counter)
print(result.strip('\n'))


t = int(input())
for case_num in range(t):
	s = input()
	a = []
	for i in range(len(s)):
		if s[i] == '1':
			a.append(i)
	if len(a) > 1:
		print(a[-1] - a[0] + 1 - len(a))
	else:
		print(0)


t = int(input())
for _ in range(t):
	s = input()
	if '1' in s:
		start = s.index('1')
		end = s.rindex('1')
		zero = s.count('0', start, end)
		print(zero)
	else:
		print(0)


t = int(input())
for i in range(t):
	s = int(input())
	v = str(s)
	y = 0
	for i in range(len(v) - 1):
		if v[i] == '1' and v[i + 1] == '0':
			x = i + 1
			for i in range(x, len(v)):
				if '1' not in v[x:len(v)]:
					y += 0
					break
				if v[i] == '0':
					y += 1
				if v[i] == '1':
					break
	print(y)


w = int(input())
a = []
for i in range(0, w):
	p = input()
	a.append(p)
for i in range(0, w):
	r = a[i]
	print(r.strip('0').count('0'))


T = int(input())
for kase in range(T):
	s = input()
	n = len(s)
	ans = 0
	for i in range(n):
		if s[i] == '0' and s[:i].count('1') > 0 and (s[i + 1:].count('1') > 0):
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	a = list(input().strip('0'))
	c = 0
	for i in range(len(a)):
		if a[i] == '0':
			c += 1
	print(c)


t = int(input())
for i in range(t):
	s = input()
	(x1, x2) = (s.find('1'), s.rfind('1'))
	s = s[x1:x2 + 1]
	print(s.count('0'))


cases = int(input())
while cases:
	cases -= 1
	arr = input()
	arr = int(arr)
	arr = str(arr)
	arr = arr[::-1]
	arr = int(arr)
	arr = str(arr)
	if '1' in arr:
		print(arr.count('0'))
	else:
		print(0)


t = int(input())
for i in range(t):
	count = 0
	st = input()
	ones = st.count('1')
	t = '1' * ones
	if t in st:
		print(0)
	else:
		index = st.find('1')
		lastIndex = st.rfind('1')
		for j in range(index + 1, lastIndex):
			if st[j] == '0':
				count += 1
		print(count)


t = int(input())
for _ in range(t):
	s = input()
	count = 0
	res = 0
	prev = ''
	for x in s:
		if x == '0':
			if prev == '1' or count != 0:
				count += 1
		elif count != 0:
			res += count
			count = 0
		prev = x
	print(res)


t = int(input())
while t > 0:
	s = input()
	s = s.rstrip('0')
	s = s.lstrip('0')
	if len(s) == 0:
		print('0')
	else:
		print(s.count('0'))
	t -= 1


def solve(s):
	flag = 0
	c = 0
	for i in range(len(s)):
		if s[i] != '1':
			c = c + 1
	print(c)
	return
for _ in range(int(input())):
	s = input().strip('0')
	solve(s)


t = int(input())
for i in range(t):
	n = input().strip('0')
	print(len(n) - sum((int(x) for x in n)))


def algo(s):
	cond = False
	soma = 0
	counter = 0
	for l in s:
		if l == '1':
			if cond == False:
				cond = True
			else:
				soma += counter
				counter = 0
		elif cond == True:
			counter += 1
	return soma
n = int(input())
for i in range(n):
	s = input()
	print(algo(s))


n = int(input())
for i in range(n):
	a = input()
	ind1 = -1
	ind2 = -1
	for i in range(len(a)):
		if a[i] == '1':
			ind1 = i
			break
	a = a[::-1]
	for i in range(len(a)):
		if a[i] == '1':
			ind2 = i
			break
	if ind1 == ind2 and ind2 == -1:
		print('0')
	else:
		ind2 = len(a) - ind2 - 1
		a = a[::-1]
		cnt = 0
		if ind1 == ind2:
			print('0')
		else:
			for i in range(ind1, ind2 + 1):
				if a[i] == '0':
					cnt = cnt + 1
			print(cnt)


t = int(input())
for d in range(t):
	s = []
	s = input()
	n = len(s)
	count1 = 0
	count0 = 0
	for i in s:
		if i == '1':
			count1 += 1
		elif i == '0' and count1 > 0:
			count0 += 1
	for g in range(n):
		if s[n - g - 1] == '0':
			count0 -= 1
		else:
			break
		g += 1
	if count0 > 0:
		print(count0)
	else:
		print(0)


import sys, itertools
input = sys.stdin.readline

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

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

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

def getStr():
	return input().strip()
t = getInt()
for i in range(t):
	s = getStr()
	r1 = s.find('1')
	r2 = s.rfind('1')
	r3 = s.count('1')
	if r3 == 0:
		print(0)
	else:
		print(len(s) - r3 - r1 - (len(s) - r2 - 1))


t = int(input())
for i in range(t):
	s = input()
	k = 0
	s1 = 0
	for i1 in s:
		if i1 == '1':
			k = 1
		elif k == 1:
			s1 += 1
	for i1 in s[::-1]:
		if i1 == '1':
			break
		s1 -= 1
	if s1 < 0:
		s1 = 0
	print(s1)


t = int(input())
while t:
	s = input()
	l = list(s)
	i = 0
	j = 0
	x = len(l)
	c = 0
	for i in range(0, len(l)):
		if l[i] == '1':
			break
	for j in range(x - 1, 0, -1):
		if l[j] == '1':
			break
	for k in range(i, j):
		if l[k] == '0':
			c = c + 1
	print(c)
	t = t - 1


for _ in range(int(input())):
	s = [int(__) for __ in input()]
	if len(set(s)) == 1:
		print(0)
		continue
	a = s.index(1)
	s.reverse()
	b = s.index(1)
	s.reverse()
	ans = 0
	for i in s[a:len(s) - b - 1 + 1]:
		if i == 0:
			ans += 1
	print(ans)


for _ in range(int(input())):
	a = input()
	c = d = 0
	if len(a) == 1 or a.count('0') == len(a):
		print(0)
	else:
		for i in range(0, len(a)):
			if a[i] == '1':
				c = i
				break
		for i in range(1, len(a)):
			if a[len(a) - i] == '1':
				d = len(a) - i
				break
		print(a[c:d + 1].count('0'))


t = int(input())
for i in range(t):
	x = input()
	(left, right) = (0, 0)
	for j in range(len(x)):
		if x[j] == '1':
			left = j
			break
	for j in range(len(x) - 1, -1, -1):
		if x[j] == '1':
			right = j
			break
	count = 0
	for j in range(left, right):
		if x[j] == '0':
			count += 1
	print(count)


t = int(input())
for i2 in range(t):
	x = str(input())
	(st, count, ans) = (0, 0, 0)
	for i in range(len(x)):
		if x[i] == '1':
			st = 1
		if st == 1 and x[i] == '0':
			count += 1
		elif st == 1 and x[i] == '1':
			ans += count
			count = 0
	print(ans)


num_cases = int(input())
for i in range(num_cases):
	number = int(input())
	oneStart = False
	counter = 0
	total = 0
	while number > 0:
		if number % 10 == 1:
			oneStart = True
			total += counter
			counter = 0
		if number % 10 == 0 and oneStart:
			counter += 1
		number = number // 10
	print(total)


for _ in range(int(input())):
	a = input()
	l = -1
	ss = 0
	for i in range(len(a)):
		if a[i] == '1':
			if l == -1:
				l = i
			else:
				ss += i - l - 1
				l = i
	print(ss)


n = int(input())
for i in range(n):
	s = input()
	s = s.strip('0')
	count = 0
	for ch in s:
		if ch == '0':
			count += 1
	print(count)


import sys
import math
input = sys.stdin.readline
t = int(input())
while t > 0:
	t -= 1
	a = list(input().rstrip())
	prev = -9
	c = 0
	for i in range(len(a)):
		if a[i] == '1':
			if prev == -9:
				prev = i
			else:
				c += i - prev - 1
				prev = i
	print(c)


t = int(input())
for i in range(t):
	s = input()
	lst = []
	for i in range(len(s)):
		if s[i] == '1':
			lst.append(i)
	count = 0
	for i in range(1, len(lst)):
		if lst[i] - lst[i - 1] != 1:
			count = count + lst[i] - lst[i - 1] - 1
	print(count)


for i in range(int(input())):
	s = input()
	c = 0
	k = 0
	firstZero = True
	l = len(s)
	while k < l:
		if s[k] == '1' and firstZero:
			firstZero = False
		if not firstZero and s[k] == '0':
			for _ in range(k, l):
				if s[_] == '1':
					c = c + _ - k
					k = _ - 1
					break
		k += 1
	print(c)


b = int(input())
x = int(0)
while x < b:
	a = list(input())
	k = sorted(a)
	l = len(a)
	if k[l - 1] != '1':
		print(0)
	else:
		m = a.index('1')
		a.reverse()
		n = -1 + l - a.index('1')
		p = a.count('1')
		print(n - m - p + 1)
	x = x + 1


a = int(input())
for i in range(a):
	c = input()
	s = 0
	l = []
	for k in range(len(c)):
		if int(c[k]) == 1:
			l.append(k)
	if len(l) > 1:
		for t in range(len(l) - 1):
			s += l[t + 1] - l[t] - 1
	print(s)


from sys import stdin, stdout
cases = int(stdin.readline().strip())
for i in range(cases):
	txt = stdin.readline().strip()
	if len(txt) == 1:
		stdout.write('0\n')
		continue
	if txt.count('1') == 0:
		stdout.write('0\n')
		continue
	l = txt.index('1')
	r = txt.rindex('1')
	txt = txt[l:r]
	stdout.write('%d\n' % txt.count('0'))


t = int(input())
for i in range(t):
	x = input()
	for j in range(len(x)):
		x = x.strip('0')
	print(x.count('0'))


import sys
Input = sys.stdin.readline
for _ in range(int(input())):
	k = input()
	k = k.strip('0')
	k = k.split('1')
	k = ''.join(k)
	print(len(k))


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

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 * p, n + 1, p):
				prime[i] = False
		p += 1
	l = []
	for i in range(2, n + 1):
		if prime[i]:
			l.append(i)
	return l

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if val >= ll[mid][0] and val <= ll[mid][1]:
			return mid
		elif val < ll[mid][0]:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def deci(n):
	s = ''
	while n != 0:
		if n % 2 == 0:
			n = n // 2
			s = '0' + s
		else:
			n = n // 2
			s = '1' + s
	return s

def diff(s1, s2):
	if len(s1) < len(s2):
		v = len(s1)
		while v != len(s2):
			s1 = '0' + s1
			v = v + 1
	else:
		v = len(s2)
		while v != len(s1):
			s2 = '0' + s2
			v = v + 1
	c = 0
	for i in range(len(s1)):
		if s1[i:i + 1] != s2[i:i + 1]:
			c = c + 1
	return c
from sys import stdin, stdout

def fac(a, b):
	v = a
	while a != b:
		v *= a - 1
		a = a - 1
	return v

def bino(l, r, n):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		val1 = math.log(n / mid + 1, 2)
		val2 = int(val1)
		if val1 == val2:
			return val1
		elif val1 < 1.0:
			return bino(l, mid - 1, n)
		else:
			return bino(mid + 1, r, n)

def binary(l, r, ll, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		if ll[mid] == val:
			return ll[mid]
		elif ll[mid] < val:
			ans = ll[mid]
			return binary(mid + 1, r, ll, val, ans)
		else:
			return binary(l, mid - 1, ll, val, ans)

def check(n):
	v = 1
	while n != 0:
		if n % 10 == 0 or n % 10 == 1:
			n = n // 10
		else:
			v = 0
			break
	return v
t = int(input())
for i in range(t):
	s = str(input())
	l = []
	for i in range(len(s)):
		if s[i:i + 1] == '1':
			l.append(i)
	c = 0
	for i in range(len(l) - 1):
		c += l[i + 1] - l[i] - 1
	print(c)


T = int(input())
while T > 0:
	n = input()
	print(n.strip('0').count('0'))
	T -= 1


t = int(input())
for _ in range(t):
	s = list(input())
	table = []
	for (i, x) in enumerate(s):
		if x == '1':
			table.append(i)
	diff = [table[i + 1] - table[i] for i in range(len(table) - 1)]
	ans = 0
	for x in diff:
		ans += x - 1
	print(ans)


for _ in range(int(input())):
	x = [x for x in input()]
	t = x[::-1]
	for i in range(len(t)):
		if t[i] == '0':
			t[i] = '2'
		else:
			break
	t = t[::-1]
	for i in range(len(t)):
		if t[i] == '0':
			t[i] = '2'
		else:
			break
	print(t.count('0'))


for _ in range(int(input())):
	s = input()
	c1 = 0
	c0 = 0
	minimum = 0
	for i in s:
		if i == '1':
			c1 += 1
			if c0 > 0:
				minimum += c0
			c0 = 0
		elif i == '0' and c1 > 0:
			c0 += 1
	if minimum == float('inf'):
		print(0)
	else:
		print(minimum)


t = int(input())
for i in range(0, t):
	s = input()
	d = '1'
	if d not in s:
		print('0')
		continue
	e = '0'
	if e not in s:
		print('0')
		continue
	f = s.count('1')
	if f == 1:
		print('0')
		continue
	c = len(s)
	for i in range(0, c):
		if s[i] == '1':
			o = i
			break
	for j in range(-1, -c - 1, -1):
		if s[j] == '1':
			g = c + j
			break
	count = 0
	for y in range(o, g + 1):
		if s[y] == '0':
			count = count + 1
	print(count)


def get_zeroes(s):
	l = r = 0
	for (i, c) in enumerate(s):
		if c == '1':
			l = i
			break
	for (i, c) in enumerate(s[::-1]):
		if c == '1':
			r = len(s) - 1 - i
			break
	res = 0
	if l >= r:
		return 0
	for i in range(l, r + 1):
		if s[i] == '0':
			res += 1
	return res
t = int(input())
for _ in range(t):
	print(get_zeroes(input()))


for _ in range(int(input())):
	s = input()
	r = 0
	for k in range(s.find('1'), s.rfind('1')):
		r += s[k] == '0'
	print(r)


tests = int(input())
for tt in range(0, tests):
	s = input()
	i = 0
	while i < len(s) and s[i] == '0':
		i = i + 1
	l = i
	i = len(s) - 1
	while i >= 0 and s[i] == '0':
		i = i - 1
	r = i
	z = 0
	for i in range(l, r + 1):
		if s[i] == '0':
			z = z + 1
	print(z)


t = int(input())
for tc in range(t):
	s = input()
	n = len(s)
	a = 0
	b = 0
	ans = []
	if s[0] == '0':
		a += 1
	if s[-1] == '0':
		b += 1
	i = 0
	while i < n:
		count = 0
		if s[i] == '0':
			while i < n and s[i] == '0':
				count += 1
				i += 1
			ans.append(count)
		else:
			i += 1
	if '1' not in s:
		print(0)
	elif a == 1 and b == 1 and (len(ans) == 2):
		print(0)
	elif a == 1 and b == 1 and (len(ans) > 2):
		print(sum(ans) - ans[0] - ans[-1])
	elif a == 1 and b == 0 and (len(ans) >= 1):
		print(sum(ans) - ans[0])
	elif a == 0 and b == 1 and (len(ans) >= 1):
		print(sum(ans) - ans[-1])
	else:
		print(sum(ans))


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


t = int(input())
while t > 0:
	t -= 1
	l = input()
	d = dict()
	d['0'] = []
	d['1'] = []
	for i in range(len(l)):
		d[l[i]].append(i)
	if len(d['0']) == 0 or len(d['1']) == 0:
		print(0)
	else:
		n = len(d['0']) - d['1'][0]
		n -= len(l) - 1 - d['1'][len(d['1']) - 1]
		print(n)


t = int(input())
for j in range(t):
	n = input()
	r = 0
	c = 0
	x = 0
	for i in range(len(n)):
		if n[i] == '1':
			x = 1
		if x == 1 and n[i] == '0':
			c = c + 1
		if x == 1 and n[i] == '1':
			r = r + c
			c = 0
	print(r)


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


def check(string):
	last_one = 0
	last_zero = 0
	count = 0
	for i in string:
		if i == '0' and last_one != 0:
			count += 1
			last_zero += 1
		if i == '1' and last_one == 0:
			last_one = 1
		if i == '1':
			last_zero = 0
	return count - last_zero
n = int(input(''))
ans = []
for i in range(n):
	string = str(input(''))
	ans.append(check(string))
for i in ans:
	print(i)


t = int(input())
for i in range(t):
	s = input()
	if '1' not in s:
		print(0)
		continue
	e = s.find('1')
	r = s.rfind('1')
	print(s[e:r].count('0'))


n = int(input())
for t in range(n):
	sc = str(input())
	if '1' not in sc:
		print(0)
	else:
		ini = sc.index('1')
		sc = sc[ini:len(sc)]
		cont = 0
		for i in range(len(sc)):
			if '1' not in sc[i:len(sc)]:
				break
			if sc[i] == '0':
				cont += 1
		print(cont)


t = int(input())
while t > 0:
	s = input()
	started = False
	from_start = 0
	from_end = 0
	i = 0
	for char in s:
		if char == '1':
			if not started:
				from_start = i
				started = True
			from_end = i
		i += 1
	ans = 0
	for i in range(from_start, from_end):
		if s[i] == '0':
			ans += 1
	t -= 1
	print(ans)


q = int(input())
for i in range(q):
	answer = 0
	w = input()
	q1 = w.find('1')
	q2 = w.rfind('1')
	if q1 == -1:
		print(0)
	else:
		for x in range(q1, q2):
			if w[x] == '0':
				answer += 1
		print(answer)


x = int(input())
d = ''
for i in range(0, x):
	bolbol = 0
	counter1 = 0
	counter2 = 0
	d = input()
	for j in d:
		if j == '1':
			bolbol = bolbol + 1
		if bolbol % 2 != 0 and j == '0':
			counter1 = counter1 + 1
		elif bolbol % 2 == 0 and j == '1':
			counter2 = counter2 + counter1
			counter1 = 0
			bolbol = 1
	print(counter2)


t = int(input())
for _ in range(t):
	s = input()
	if '1' not in s:
		print(0)
		continue
	l = s.index('1')
	r = s.rindex('1')
	cnt = 0
	for i in range(l, r):
		if s[i] == '0':
			cnt += 1
	print(cnt)


import re
t = int(input())
arr = []
for i in range(t):
	arr.append(input())
for s in arr:
	somme = 0
	x = re.split('^0+', s)
	y = re.findall('0+1', x[-1])
	for i in y:
		somme += len(i) - 1
	print(somme)


def inp():
	return list(map(int, input().split()))
for tc in range(int(input())):
	s = input()
	if len(set(s)) == 2:
		a = s.index('1')
		b = len(s) - s[::-1].index('1')
		c = s[a:b]
		print(c.count('0'))
	else:
		print('0')


for _ in range(int(input())):
	s = input()
	n = len(s)
	if '1' in s:
		l = s.index('1')
		u = n - 1 - s[::-1].index('1')
		print(s[l:u + 1].count('0'))
	else:
		print(0)


def main():
	t = int(input().strip())
	for _ in range(t):
		s = input().strip()
		result = s.strip('0').count('0')
		print(result)
main()


for _ in range(int(input())):
	n = list(input())
	ans = 0
	temp = 0
	index = 0
	for i in range(len(n)):
		if n[i] == '1':
			index = i
			break
	for i in range(index, len(n)):
		if n[i] == '0':
			temp += 1
		if n[i] == '1':
			ans += temp
			temp = 0
	print(ans)


t = int(input())
a = []
for i in range(t):
	s = str(input())
	(start, end) = (0, len(s))
	for sym in s:
		if sym == '1':
			break
		start += 1
	for sym in s[::-1]:
		if sym == '1':
			break
		end -= 1
	nulls = 0
	for sym in s[start:end]:
		if sym == '0':
			nulls += 1
	a.append(nulls)
for i in a:
	print(i)


from sys import stdin
r = stdin.readline

def main():
	cases = int(r())
	for case in range(cases):
		t = r().strip()
		n = len(t)
		ans = 0
		(lo, hi) = (0, n - 1)
		found = False
		for i in range(len(t)):
			if t[i] == '1':
				lo = i
				found = True
				break
		for i in range(len(t) - 1, -1, -1):
			if t[i] == '1':
				hi = i
				break
		onescnt = 0
		for x in t:
			if x == '1':
				onescnt += 1
		if not found or onescnt == 1:
			print(0)
		else:
			i = lo
			while i <= hi:
				if t[i] == '0':
					(j, ac) = (i, 0)
					while j <= hi and t[j] == '0':
						ac += 1
						j += 1
					ans += ac
					i = j
				i += 1
			print(ans)
main()


for _ in range(int(input())):
	s = input()
	ar = []
	for i in range(len(s)):
		if s[i] == '1':
			ar.append(i)
	if len(ar) == 1:
		print(0)
	else:
		count = 0
		for i in range(1, len(ar)):
			count += ar[i] - ar[i - 1] - 1
		print(count)


def solve(s):
	n = len(s)
	i = 0
	while i < n and s[i] == '0':
		i += 1
	j = n - 1
	while j >= 0 and s[j] == '0':
		j -= 1
	if j <= i:
		print(0)
		return
	ans = 0
	for k in range(i, j + 1):
		if s[k] == '0':
			ans += 1
	print(ans)

def main():
	tc = int(input())
	for _ in range(tc):
		s = input()
		solve(s)
main()


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

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

def mi():
	return map(int, input().split())
for _ in range(ii()):
	n = input()
	try:
		first_one = n.index('1')
		last_one = len(n) - list(reversed(n)).index('1')
	except:
		print(0)
		continue
	zeros = 0
	for ele in n[first_one:last_one]:
		if ele == '0':
			zeros += 1
	print(zeros)


t = int(input())
for y in range(t):
	s = input()
	n = len(s)
	z = s.count('0')
	ctf = ctb = 0
	if z == n:
		print(0)
		continue
	for i in range(n):
		if s[i] == '1':
			break
		ctf += 1
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			break
		ctb += 1
	print(z - ctf - ctb)


t = 0
s_arr = ''

def read_input():
	global t, s_arr
	t = int(input())
	s_arr = [''] * t
	for i in range(t):
		s_arr[i] = input()

def solve():
	count_arr = []
	for s in s_arr:
		first_occur = s.find('1')
		last_occur = s.rfind('1')
		count = 0
		if first_occur == -1 and last_occur == -1:
			count_arr.append(count)
			continue
		for i in range(first_occur, last_occur + 1):
			if s[i] == '0':
				count = count + 1
		count_arr.append(count)
	return count_arr
read_input()
count_arr = solve()
for count in count_arr:
	print(count)


for _ in range(int(input())):
	s = input()
	if not s.count('1'):
		print(0)
	else:
		c = 0
		s = s.strip('0')
		s = s.lstrip('0')
		print(s.count('0'))


def mi():
	return map(int, input().split())
for _ in range(int(input())):
	a = list(input())
	ar = a[::-1]
	if '1' not in a:
		print(0)
		continue
	s = a.index('1')
	e = ar.index('1')
	ans = 0
	for i in range(s, len(a) - e):
		if a[i] == '0':
			ans += 1
	print(ans)


for t in range(int(input())):
	s = input()
	j = len(s) - 1
	k = 0
	for i in range(len(s)):
		if s[i] == '1':
			j = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			k = i
			break
	ct = 0
	for i in range(j + 1, k, 1):
		if s[i] == '0':
			ct += 1
	print(ct)


def do(s):
	c = s.count('1')
	a = s.find('1')
	if c == 0:
		return 0
	elif c == 1:
		return 0
	else:
		b = s.rindex('1')
		st = s[a:b + 1]
		d = st.count('0')
		return d
t = int(input())
for i in range(t):
	s = input()
	print(do(s))


from collections import defaultdict, deque
from itertools import permutations
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
from math import ceil
int_input = lambda : int(stdin.readline())
string_input = lambda : stdin.readline()
multi_int_input = lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input = lambda : list(map(int, stdin.readline().split()))
string_list_input = lambda : list(string_input())
MOD = pow(10, 9) + 7
test = int_input()
for _ in range(test):
	string = string_input()
	countOne = 0
	start = False
	counter = 0
	temp = 0
	for i in string:
		if i == '1':
			countOne += 1
		if i == '1' and start == False:
			start = True
		elif i == '0' and start == True:
			temp += 1
		elif i == '1' and start == True:
			counter += temp
			temp = 0
	if countOne == 0:
		print(0)
	else:
		print(counter)


n = int(input())
for _ in range(n):
	a = list(input())
	l = len(a)
	s = 0
	su = 0
	try:
		while True:
			l1 = a.index('1', s, l)
			s = l1 + 1
			l2 = a.index('1', s, l)
			s = l2
			su = su + l2 - l1 - 1
	except:
		print(su)


n = input()
r = []
for i in range(0, int(n)):
	a = input().strip('0')
	r.append(a.count('0'))
for x in r:
	print(x)


n = int(input())
for i in range(n):
	s = input()
	x = len(s)
	f = 0
	l = x - 1
	for j in range(x):
		if s[j] == '0':
			f += 1
		else:
			break
	for j in range(x - 1, -1, -1):
		if s[j] == '0':
			l -= 1
		else:
			break
	if x == 1:
		print(0)
	else:
		res = s[f:l + 1].count('0')
		print(res)


import sys
import math
from collections import defaultdict
from collections import deque
from itertools import combinations
from itertools import permutations
input = lambda : sys.stdin.readline().rstrip()
read = lambda : list(map(int, input().split()))
go = lambda : 1 / 0

def write(*args, sep='\n'):
	for i in args:
		sys.stdout.write('{}{}'.format(i, sep))
INF = float('inf')
MOD = int(1000000000.0 + 7)
YES = 'YES'
NO = 'NO'
for _ in range(int(input())):
	try:
		s = input()
		if s.count('1') == 0:
			print(0)
			go()
		l = INF
		r = -INF
		for i in range(len(s)):
			if s[i] == '1':
				l = min(l, i)
				r = max(r, i)
		cnt = 0
		for i in range(l, r + 1):
			cnt += s[i] == '1'
		print(r - l + 1 - cnt)
	except ZeroDivisionError:
		continue
	except Exception as e:
		print(e)
		continue


n = int(input())
for i in range(n):
	s = input()
	c = 0
	l = len(s) - 1
	result = 0
	while c <= l and s[c] == '0':
		c += 1
	while c <= l and s[l] == '0':
		l -= 1
	for i in range(c, l + 1):
		if s[i] == '0':
			result += 1
	print(result)


def main():
	t = int(input())
	for _ in range(t):
		s = input()
		n = len(s)
		arr = []
		for i in range(n):
			if s[i] == '1':
				if i - 1 >= 0 and s[i - 1] == '1':
					arr[-1][1] = i
				else:
					arr.append([i, i])
		ret = 0
		for i in range(1, len(arr)):
			ret += arr[i][0] - arr[i - 1][1] - 1
		print(ret)
main()


import sys
import math
import heapq
import collections

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 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):
	s = inputstring()
	start = 0
	end = len(s) - 1
	for i in range(len(s)):
		if s[i] == '1':
			start = i
			break
	for i in reversed(range(len(s))):
		if s[i] == '1':
			end = i
			break
	if s.count('1') == 0:
		print(0)
		continue
	cnt = 0
	for i in range(start, end + 1):
		if s[i] == '0':
			cnt += 1
	print(cnt)


t = int(input())
for _ in range(t):
	s = input()
	indx1 = s.find('1')
	indx2 = s[::-1].find('1')
	indx2 = len(s) - 1 - indx2
	if indx1 == -1:
		print(0)
	else:
		mid = 0
		for i in range(indx1, indx2 + 1):
			if s[i] == '0':
				mid += 1
		print(mid)


for _ in range(int(input())):
	s = list(map(int, input()))
	ans = 0
	z = []
	p = 0
	for i in range(len(s)):
		if s[i] == 1 and len(z) == 0:
			z.append(i)
		if s[i] == 1:
			if i - z[-1] > 1:
				ans += i - z[-1] - 1
				z.append(i)
			else:
				z.append(i)
	print(ans)


for _ in range(int(input())):
	a = input()
	l = len(a)
	j = 0
	r = 0
	o = 0
	for i in range(l):
		if a[i] == '1':
			if j != 1:
				j = 1
			else:
				r += o
				o = 0
		if j == 1:
			if a[i] == '0':
				o += 1
	print(r)


t = int(input())
for _ in range(t):
	s = list(input())
	if '1' in s and len(s) > 2:
		start = s.index('1')
		end = len(s) - s[::-1].index('1') - 1
		d = 0
		for i in range(start, end):
			if s[i] == '0':
				d += 1
		print(d)
	else:
		print('0')


x = int(input())
for kayra in range(x):
	sayac = 0
	x = input()
	bir = 0
	ilk = 0
	son = 0
	for i in range(len(x)):
		if x[i] == '1':
			ilk = i
			break
	for i in range(1, len(x) + 1):
		if x[-i] == '1':
			son = len(x) - i
			break
	for i in range(ilk, son):
		if x[i] == '0':
			sayac += 1
	for i in range(len(x)):
		if x[i] == '1':
			bir += 1
	if len(x) == 1:
		print(0)
	elif bir < 2:
		print(0)
	else:
		print(sayac)


for i in range(int(input())):
	s = input()
	c = s.count('1')
	answer = 0
	if c == 0:
		print(0)
		continue
	for j in range(len(s) - 1):
		if c == 0:
			break
		if s[j] == '1':
			c -= 1
			for x in range(j + 1, len(s)):
				if s[x] == '1' or c == 0:
					break
				if s[x] == '0':
					answer += 1
					continue
	print(answer)


from sys import stdin, stdout, exit as sys_ret
(f_input, f_print, f_flush) = (stdin.readline, stdout.write, stdout.flush)
for _ in range(int(f_input())):
	string = f_input()
	(prev_one, count) = (-1, 0)
	for i in range(len(string)):
		if string[i] == '1':
			if prev_one != -1:
				count += i - prev_one - 1
			prev_one = i
	f_print(str(count) + '\n')


testcases = int(input())
for _ in range(testcases):
	s = input()
	zeros = s.count('0')
	zeros_pad_left = s.find('1')
	if zeros_pad_left == -1:
		print('0')
		continue
	zeros_pad_right = s[::-1].find('1')
	print(zeros - zeros_pad_left - zeros_pad_right)


for i in range(int(input())):
	s = input()
	ans = 0
	if s.count('1') >= 2:
		(i_pos, f_pos) = (s.index('1'), s.rindex('1'))
		ans = s[i_pos:f_pos + 1].count('0')
	print(ans)


def solve(s):
	if s.count('1') == 0 or s.count('0') == 0:
		return 0
	ind = []
	for i in range(len(s)):
		if s[i] == '1':
			ind.append(i)
	ans = s[min(ind):max(ind)].count('0')
	return ans

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


def main():
	t = int(input())
	for i in range(t):
		s = 0
		e = 0
		S = list(input())
		for j in range(len(S)):
			if S[j] == '1':
				s = j
				break
		for j in range(len(S) - 1, -1, -1):
			if S[j] == '1':
				e = j
				break
		ans = 0
		for j in range(s, e):
			if S[j] == '0':
				ans += 1
		print(ans)
main()


t = int(input())
l = []
a = []
for i in range(0, t):
	cnt = 0
	s = input()
	s = int(s)
	k = s
	while k > 0:
		r = k % 10
		k = k // 10
		l.append(r)
	if s == 0:
		l.append(s)
	l.reverse()
	e = l[0]
	for i in range(1, len(l)):
		if l[i] == 0:
			if e == 1:
				cnt += 1
		else:
			e = 1
	if cnt > 0:
		for i in range(len(l) - 1, 0, -1):
			if l[i] == 0:
				cnt -= 1
			else:
				break
	a.append(cnt)
	cnt = 0
	l = []
for i in a:
	print(i)


t = int(input())
for _ in range(t):
	s = input()
	if s.count('1') == 0:
		print(0)
		continue
	val = s[s.index('1'):s.rindex('1') + 1].count('0')
	print(val)


s = []
for i in range(int(input())):
	s.append(input())

def improve_pattern(pattern):
	zeros_removed = 0
	pattern = pattern[pattern.find('1'):pattern.rfind('1') + 1]
	while True:
		zero_find = pattern.find('0')
		if zero_find != -1:
			pattern = pattern[:zero_find] + pattern[zero_find + 1:]
			zeros_removed += 1
		else:
			break
	return zeros_removed
for pattern in s:
	print(improve_pattern(pattern))


for _ in range(int(input())):
	print(len(input().strip('0').replace('1', '')))


t = int(input())
for _ in range(t):
	s = input()
	(first, last) = (len(s), 0)
	for (i, c) in enumerate(s):
		if c == '1':
			first = min(i, first)
			last = max(i, last)
	if first != len(s):
		print(sum((1 if c == '0' else 0 for c in s[first:last])))
	else:
		print(0)


a = int(input())
mas = []
for i in range(a):
	st = input()
	if st.count('1'):
		st = st[st.index('1'):]
		st = st[::-1]
		st = st[st.index('1'):]
		mas.append(st.count('0'))
	else:
		mas.append(0)
for i in range(len(mas)):
	print(mas[i])


t = int(input())
for qewqeq in range(t):
	s = input()
	if s.count('1') != 0:
		s = s[s.index('1'):len(s) - s[::-1].index('1')]
		print(s.count('0'))
	else:
		print(0)


for __ in range(int(input())):
	s = input()
	k = 0
	ind = 0
	if '1' in s:
		ind = s.index('1')
	for i in range(ind, len(s)):
		if s[i] == '0' and '1' in s[i:len(s) + 1]:
			k += 1
	print(k)


t = int(input())
for i in range(t):
	n = str(input())
	count = 0
	rev = ''
	for item in range(len(n) - 1, 0, -1):
		rev += n[item]
	try:
		frindex = n.index('1')
		baindex = len(n) - rev.index('1')
	except:
		print(0)
		continue
	for j in range(frindex, baindex):
		if n[j] == '1':
			continue
		else:
			count += 1
	print(count)


t = int(input())
for i in range(t):
	s = input()
	if '1' not in s:
		print(0)
		continue
	s = s.strip('0')
	print(s.count('0'))


t = int(input(''))
while t > 0:
	s = input('')
	l = list(s)
	min1 = 1000000000000000000000
	max1 = 0
	for i in range(0, len(l)):
		if l[i] == '1':
			if max1 < i:
				max1 = i
			if min1 > i:
				min1 = i
	count1 = 0
	if min == max:
		print(0)
	else:
		for i in range(min1, max1 + 1):
			if l[i] == '0':
				count1 += 1
		print(count1)
	t = t - 1


for _ in range(int(input())):
	s = input()
	s1 = s[::-1]
	n = len(s)
	if '1' not in s:
		print(0)
	else:
		st = s.index('1')
		end = n - s1.index('1')
		print(s[st:end].count('0'))


def main():
	for test in range(int(input().strip())):
		print(input().strip('0').count('0'))
main()


n = int(input())
for i in range(0, n):
	t = input()
	c = 0
	for j in range(len(t)):
		if t[j] == '1':
			break
	for k in range(len(t) - 1, -1, -1):
		if t[k] == '1':
			break
	for l in range(j, k, 1):
		if t[l] == '0':
			c = c + 1
	print(c)


for _ in range(int(input())):
	flag = 0
	s = input()
	l = list(s)
	r = l[::-1]
	if '1' in l:
		fi = l.index('1')
	else:
		flag = 1
	if flag == 0:
		la = r.index('1')
		x = len(s) - la
		n = l[fi:x]
		print(n.count('0'))
	else:
		print(0)


def problem1(input_str):
	digits_to_remove_buffer = 0
	remove_sig = False
	digits_to_remove = 0
	prev_c = None
	for c in input_str:
		if prev_c == '1' and c == '0':
			remove_sig = True
		if prev_c == '0' and c == '1':
			remove_sig = False
			digits_to_remove += digits_to_remove_buffer
			digits_to_remove_buffer = 0
		prev_c = c
		if remove_sig:
			digits_to_remove_buffer += 1
	return digits_to_remove
N = int(input())
for i in range(N):
	input_str = input()
	print(problem1(input_str))


t = int(input())
for i in range(t):
	str = input()
	j = 0
	(num, sum) = (0, 0)
	while j != len(str) and str[j] == '0':
		j += 1
	while j != len(str):
		if str[j] == '1':
			sum += num
			num = 0
			while j != len(str) and str[j] == '1':
				j += 1
		while j != len(str) and str[j] == '0':
			num += 1
			j += 1
	print(sum)


t = int(input())
for i in range(0, t):
	c = 0
	s = input()
	lens = len(s)
	for j in range(0, lens - 1):
		if s[j] == '1' and s[j + 1] == '0':
			for k in range(j + 1, lens):
				if s[k] == '1':
					c += k - j - 1
					break
	print(c)


n = int(input())
while n > 0:
	s = str(input())
	z = 0
	got = 0
	id = 0
	for i in range(0, len(s)):
		if s[i] == '1':
			id = i
			break
	sum = 0
	for i in range(id, len(s)):
		if s[i] == '0':
			z += 1
		elif s[i] == '1' and z > 0:
			sum = sum + z
			z = 0
			id = 1
	if id == 1:
		print(sum)
	else:
		print(0)
	n = n - 1


from math import *

def solve():
	T = int(input())
	for i in range(T):
		str = input()
		print(str.strip('0').count('0'))
solve()


t = int(input())
for i in range(t):
	s = input()
	if s == '0' or s == '1' or '1' not in s or ('0' not in s):
		print(0)
		continue
	a = s.index('1')
	b = s.rfind('1')
	res = 0
	for j in range(len(s)):
		if s[j] == '0' and j >= a and (j <= b):
			res += 1
	print(res)


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	i = 0
	a = []
	i = 0
	while i < len(s):
		if s[i] == '0':
			i += 1
		else:
			start = i
			j = i + 1
			while j < n:
				if s[j] == '0':
					break
				j += 1
			end = j - 1
			a.append((start, end))
			i = j
	cnt = 0
	for i in range(len(a) - 1):
		cnt += a[i + 1][0] - a[i][1] - 1
	print(cnt)


for _ in range(int(input())):
	s = input()
	n = len(s)
	(ans, cnt) = (0, 0)
	f = False
	for i in range(n):
		if s[i] == '1':
			ans += cnt
			cnt = 0
			f = True
		if s[i] == '0' and f:
			cnt += 1
	print(ans)


from math import ceil, sqrt, gcd

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

def si():
	return input()

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

def li():
	return list(mi())
t = ii()
while t:
	t -= 1
	s = si()
	c = 0
	s1 = 0
	f = 0
	for i in range(len(s)):
		if s[i] == '1':
			f = 1
			s1 += c
			c = 0
		elif f == 1:
			c += 1
	print(s1)


t = int(input())
while t > 0:
	(erased, counter) = (0, -1)
	k = str(input())
	look = False
	for lol in range(0, len(k)):
		if k[lol] == '0':
			continue
		elif counter >= 0:
			erased += lol - counter - 1
		counter = lol
	print(erased)
	t -= 1


t = int(input())
for i in range(t):
	s = input()
	first_one = -1
	last_one = -1
	count = 0
	for (pos, j) in enumerate(s):
		if j == '1':
			if first_one == -1:
				first_one = pos
			last_one = pos
			count += 1
	if first_one == -1 or count == 1:
		print(0)
	else:
		print(last_one - first_one + 1 - count)


import sys
import math

def read_line():
	return sys.stdin.readline()[:-1]

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

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]
t = read_int()
for i in range(t):
	s = read_line()
	cnt = 0
	j = 0
	while j < len(s) and s[j] == '0':
		j += 1
	while j < len(s):
		if s[j] == '0':
			cnt += 1
		j += 1
	j = len(s) - 1
	if cnt > 0:
		while j > 0 and s[j] == '0':
			j -= 1
			cnt -= 1
	print(cnt)


t = int(input())
while t:
	s = input()
	first = s.find('1')
	last = s.rfind('1')
	if first == -1 or last == -1:
		print(0)
	else:
		print(s[first:last].count('0'))
	t -= 1


t = int(input())
for i in range(t):
	s = input()
	cnt = 0
	for c in s:
		cnt += 1 - int(c)
	si = 0
	while si < len(s) and s[si] == '0':
		si += 1
	cnt -= si
	if si != len(s):
		ei = len(s) - 1
		while ei >= 0 and s[ei] == '0':
			ei -= 1
		cnt -= len(s) - ei - 1
	print(cnt)


for _ in range(int(input())):
	a = list(map(str, input()))
	index1 = []
	m = 0
	for i in range(len(a)):
		if a[i] == '1':
			index1.append(i)
	for i in range(len(index1) - 1):
		if abs(index1[i] - index1[i + 1]) != 1:
			m += index1[i + 1] - index1[i] - 1
	print(m)


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


t = int(input())
inputs = [''] * t
for i in range(t):
	inputs[i] = input()
for s in inputs:
	l = s.find('1')
	if l < 0:
		print(0)
		continue
	r = s.rindex('1')
	s = s[l:r + 1]
	print(sum(map(lambda c: int(c == '0'), s)))


n = int(input())
for _ in range(n):
	num = input()
	erase = 0
	count = 0
	flag = 0
	for i in num:
		if i == '0':
			count += 1
		if i == '1':
			if flag == 0:
				flag = 1
				count = 0
			else:
				erase += count
				count = 0
	print(erase)


def quick_sort(array):
	if len(array) < 2:
		return array
	else:
		pivot = array[0]
		less = [i for i in array[1:] if i <= pivot]
		greater = [i for i in array[1:] if i > pivot]
		return quick_sort(less) + [pivot] + quick_sort(greater)
t = int(input())
counter = int()
result = str()
for i in range(t):
	s = list(map(int, list(input())))
	if 1 in s:
		counter = len(s)
		sorted_s = quick_sort(s)
		counter -= len(sorted_s[sorted_s.index(1):])
		counter -= len(s[:s.index(1)])
		s.reverse()
		counter -= len(s[:s.index(1)])
	else:
		counter = 0
	result += f'\n{counter}'
print(result.strip())


t = int(input())
for _ in range(t):
	l = list()
	s = input()
	for i in range(0, len(s)):
		if s[i] == '1':
			l.append(i)
	if len(l) == 0:
		print(0)
		continue
	j = max(l)
	i = min(l)
	k = s[i:j + 1]
	count = 0
	for i in k:
		if i == '0':
			count += 1
	print(count)


for i in range(int(input())):
	c = 0
	ans = 0
	f = True
	for x in input():
		if x == '0':
			if f:
				continue
			c += 1
		else:
			f = False
			ans += c
			c = 0
	print(ans)


def no_zero(sequence):
	erase = 0
	one = -1
	list(sequence)
	for d in range(0, len(sequence)):
		if sequence[d] == '1':
			if d - one > 1 and one != -1:
				erase += d - one - 1
			one = d
	print(erase)
T = int(input())
for x in range(T):
	caso = input()
	no_zero(caso)


for _ in range(int(input())):
	s = input()
	(first, last) = (-1, -1)
	for (i, j) in enumerate(s):
		if j == '1':
			if first == -1:
				first = i
			last = i
	ans = 0
	for i in range(first, last):
		if s[i] == '0':
			ans += 1
	print(ans)


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


t = int(input())
while t:
	t -= 1
	s = list(map(int, input()))
	n = len(s)
	i = 0
	p1 = 0
	ans = 0
	while i < n:
		tem = 0
		if p1 == 1 and s[i] == 0:
			for j in range(i, n):
				if s[j] == 0:
					tem += 1
				else:
					p1 = 1
					ans += tem
					break
			i += j - i + 1
		else:
			if s[i] == 1:
				p1 = 1
			i += 1
	print(ans)


n = int(input())
for i in range(n):
	y = 0
	ans = 0
	s = input()
	lk = 0
	for k in range(len(s) - 1, -1, -1):
		if s[k] == '1':
			lk = k
			break
	for j in range(lk):
		if s[j] == '1':
			y = 1
		if s[j] == '0' and y:
			ans += 1
	print(ans)


def sol(l):
	lastOne = ''
	zeroSince = 0
	res = 0
	for (i, c) in enumerate(l):
		if c == '1':
			res += zeroSince
			lastOne = i
			zeroSince = 0
		elif lastOne != '' and c == '0':
			zeroSince += 1
	return res

def main():
	n = int(input())
	for l in range(n):
		print(sol(input()))
main()


s = int(input())
rs = []
for i in range(s):
	c = input()
	if int(c) > 1:
		c_int = int(c)
		c_str = str(c_int)
		c_str_rv = c_str[::-1]
		c_to_int = int(c_str_rv)
		c_rs = str(c_to_int)
		rs.append(c_rs.count('0'))
	else:
		rs.append('0')
for i in rs:
	print(i)


import sys
import math as mt
t = int(input())
for __ in range(t):
	s = input()
	ans = 0
	prev = 0
	cnt = 0
	l1 = []
	for i in range(len(s)):
		if s[i] == '1':
			cnt = 0
			for j in range(i + 1, len(s)):
				if s[j] == '0':
					cnt += 1
				else:
					ans += cnt
					break
	print(ans)


from math import factorial
from collections import Counter
from heapq import heapify, heappop, heappush
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 comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')

def main():
	N = int(input())
	for _ in range(N):
		s = input()
		rec = -1
		res = 0
		for i in range(len(s)):
			c = s[i]
			if c == '1':
				if rec != -1 and rec != i - 1:
					res += i - rec - 1
				rec = i
		print(res)
main()


T = int(input())
for _ in range(T):
	word = input()
	N = len(word)
	(i1, i2) = (None, None)
	onecount = 0
	for i in range(N):
		if i1 == None and word[i] == '1':
			i1 = i
		if word[i] == '1':
			onecount += 1
			i2 = i
	if i1 == i2 or i1 == i2 == None:
		print(0)
	else:
		print(i2 - i1 + 1 - onecount)


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	flg = 0
	for i in s:
		if i == '1':
			flg = 1
			break
	if flg == 0:
		print(0)
	else:
		for i in range(len(s)):
			if s[i] == '1':
				start = i
				break
		for i in range(len(s)):
			if s[i] == '1':
				end = i
		zeros = 0
		for i in range(start, end + 1):
			if s[i] == '0':
				zeros += 1
		print(zeros)


t = int(input())
for _ in range(t):
	s = input()
	first = s.find('1')
	last = s.rfind('1')
	print(s[first:last].count('0'))


t = int(input())
for j in range(t):
	h = list(input())
	c = 0
	(s, l) = (1, 1)
	for i in range(len(h)):
		if h[i] == '1':
			s = i
			break
	for i in range(len(h)):
		if h[i] == '1':
			l = i
	for i in range(s, l):
		if h[i] == '0':
			c = c + 1
	print(c)


import sys
import math
import bisect

def main():
	for _ in range(int(input())):
		s = input()
		n = len(s)
		l = n
		r = n
		for i in range(n):
			if s[i] == '1' and l == n:
				l = i
			if s[i] == '1':
				r = i
		if l == n:
			print(0)
		else:
			ans = 0
			for i in range(l, r + 1):
				if s[i] == '0':
					ans += 1
			print(ans)
main()


n = int(input())
for fwefewi in range(n):
	s = input()
	k = len(s)
	start = -1
	end = -1
	for i in range(k):
		if s[i] == '1':
			start = i
			break
	for i in range(k):
		j = k - 1 - i
		if s[j] == '1':
			end = j
			break
	if start == -1:
		print(0)
	else:
		print(s[start:end + 1].count('0'))


for _ in range(int(input())):
	s = input()
	if '1' in s:
		(f, l, c) = (s.index('1'), len(s) - s[::-1].index('1'), s.count('1'))
		print(l - f - c)
	else:
		print(0)


from sys import stdin
test_case = True
if test_case:
	t = int(stdin.readline())
	while t:
		t -= 1
		s = input()
		l = []
		for i in range(len(s)):
			if s[i] == '1':
				l.append(i)
		c = 0
		if len(l) > 1:
			for i in range(1, len(l)):
				c += l[i] - l[i - 1] - 1
			print(c)
		else:
			print('0')
else:
	n = int(stdin.readline())
	(x, y) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))


for i in range(int(input())):
	a = input()
	n = len(a)
	(fst, lst) = (-1, -1)
	f = 0
	for i in range(n):
		if a[i] == '1':
			fst = i
			f = 1
			break
	for i in range(n - 1, -1, -1):
		if a[i] == '1':
			lst = i
			f = 1
			break
	if f == 1:
		print(a[fst:lst + 1].count('0'))
	else:
		print(0)


lst = []
output = []
t = int(input())
for i in range(0, t):
	element = int(input())
	lst.append(element)
for i in lst:
	i = str(i)
	e = len(i)
	k = e - 1
	e -= 1
	counter = 0
	while k >= 0:
		if i[k] == '1':
			e = k
			break
		else:
			k = k - 1
	for n in range(0, e):
		if i[n] == '0':
			counter = counter + 1
	print(counter)


T = int(input())
for _ in range(T):
	s = input().strip('0')
	if '0' not in s:
		print(0)
	else:
		c = s.count('0')
		print(c)


for _ in range(int(input())):
	s = input()
	if s.count('1') == 0:
		print(0)
	else:
		i = 0
		for h in range(len(s)):
			if s[h] == '1':
				i = h
				break
		s = s[::-1]
		j = 0
		for h in range(len(s)):
			if s[h] == '1':
				j = h
				break
		s = s[::-1]
		j = len(s) - j - 1
		print(s[i:j + 1].count('0'))


def solve():
	s = input().strip('0')
	ret = 0
	if '1' in s:
		ret = s.count('0')
	return ret
t = int(input())
for i in range(t):
	print(solve())


q = int(input())
for _ in range(q):
	s = input()
	lex = [[s[0], 0, 0]]
	curr = s[0]
	j = 0
	del0s = 0
	for i in range(len(s)):
		if curr != s[i]:
			lex[j][2] = i - 1
			lex.append([s[i], i, i])
			j += 1
			curr = s[i]
	lex[j][2] = len(s) - 1
	if lex[0][0] == '0':
		lex.pop(0)
	if len(lex) > 0:
		if lex[-1][0] == '0':
			lex.pop(-1)
	for l in lex:
		if l[0] == '0':
			del0s += l[2] - l[1] + 1
	print(del0s)


n = int(input())
for _ in range(n):
	s = input()
	l = len(s)
	raw = []
	for i in range(l):
		raw.append(int(s[i]))
	for i in range(l):
		if raw[i] == 0:
			raw[i] = 1
		else:
			break
	for i in range(l)[::-1]:
		if raw[i] == 0:
			raw[i] = 1
		else:
			break
	print(l - sum(raw))


for _ in range(int(input())):
	n = int(input())
	n = str(n)
	n = list(reversed(n))
	n = ''.join(n)
	n = str(int(n))
	c = 0
	if len(n) > 1:
		for i in n:
			if i == '0':
				c += 1
	print(c)


import math
t = int(input())
for _ in range(t):
	l = list(map(int, input().strip()))
	t1 = l.count(1)
	count1 = 0
	count0 = 0
	flag = 0
	for i in range(len(l)):
		if l[i] == 1:
			flag = 1
		if flag == 1 and count1 < t1:
			if l[i] == 0:
				count0 += 1
			if l[i] == 1:
				count1 += 1
	print(count0)


test_cases = int(input(''))
tests = []
for i in range(test_cases):
	tests.append(input(''))
for test in tests:
	count = 0
	start = 0
	ans = 0
	for c in test:
		if c == '1':
			ans += count
			start = 1
			count = 0
		elif start:
			count += 1
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	s = input().strip()
	if not '1' in s:
		print(0)
		continue
	first = -1
	for i in range(len(s)):
		if s[i] == '1':
			if first == -1:
				first = i
			last = i
	ANS = 0
	for i in range(first, last):
		if s[i] == '0':
			ANS += 1
	print(ANS)


t = int(input())
for tt in range(t):
	s = input()
	i = 0
	j = len(s) - 1
	while i < len(s) and s[i] == '0':
		i += 1
	while j >= 0 and s[j] == '0':
		j -= 1
	i += 1
	cnt = 0
	while i < j:
		if s[i] == '0':
			cnt += 1
		i += 1
	print(cnt)


t = int(input())
for _ in range(t):
	s = str(input())
	n = len(s)
	ans = 0
	for i in range(n):
		if s[i] == '0':
			if i == 0 or i == n - 1:
				continue
			p = s[0:i + 1]
			q = s[i + 1:]
			if '1' in p and '1' in q:
				ans += 1
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for tt in range(t):
	s = input()
	(posl, posr) = (-1, -1)
	count = 0
	for i in range(len(s)):
		if s[i] == '1' and posl == -1:
			posl = i
		elif s[i] == '1' and posl != -1:
			posr = i
	for i in range(len(s)):
		if s[i] == '0' and posl < i < posr:
			count += 1
	print(count)


t = int(input())
while t > 0:
	s = input()
	if '1' not in s:
		print(0)
	else:
		fi = s.index('1')
		r = s[::-1]
		la = len(s) - 1 - r.index('1')
		co = s.count('1')
		print(la - fi + 1 - co)
	t = t - 1


import sys

def count_zeroes(number_str):
	remove_zeros = False
	remove_count = 0
	remove_count_temp = 0
	for digit in number_str:
		if digit == '1':
			if remove_zeros:
				remove_count += remove_count_temp
				remove_count_temp = 0
			remove_zeros = True
		elif digit == '0':
			if remove_zeros:
				remove_count_temp += 1
	return remove_count

def test():
	print(count_zeroes('00110'), 0)
	print(count_zeroes('00101010'), 2)

def main():
	input = sys.stdin.readlines()
	n = int(input[0])
	for i in range(1, n + 1):
		print(count_zeroes(input[i]))
main()


for _ in range(int(input())):
	L = list(input())
	N = len(L)
	ans = 0
	for i in range(N - 1):
		if L[i] == '1':
			count = 0
			for j in range(i + 1, N):
				if L[j] == '0':
					count += 1
				else:
					ans += count
					break
	print(ans)


import math
t = int(input())
for _ in range(t):
	x = input()
	i1 = -1
	j1 = -1
	for i in range(len(x)):
		if x[i] == '1':
			i1 = i
			break
	for i in range(len(x) - 1, -1, -1):
		if x[i] == '1':
			j1 = i
			break
	if i1 == -1 or j1 == -1:
		print(0)
	else:
		c = 0
		for i in range(i1, j1 + 1):
			if x[i] == '0':
				c += 1
		print(c)


t = int(input())
for i in range(t):
	s = input()
	ct = 0
	ans = 0
	j = 0
	while True:
		if s[j] == '1':
			break
		j += 1
		if j >= len(s):
			break
	for k in range(j, len(s)):
		if s[k] == '0':
			ct += 1
		else:
			ans = ct
	print(ans)


for _ in range(int(input())):
	b = input()
	if '1' not in b or b.count('1') == len(b):
		print(0)
	else:
		boshi = b.index('1')
		oxiri = len(b) - b[::-1].index('1')
		print(b[boshi:oxiri].count('0'))


import sys
read = sys.stdin.buffer.readline
mi = lambda : map(int, read().split())
li = lambda : list(mi())
cin = lambda : int(read())
for _ in range(cin()):
	s = input().strip('0')
	print(s.count('0'))


import sys
input = sys.stdin.readline

def main():
	for _ in range(int(input())):
		is_one = False
		one_cnt = 0
		ret = 0
		for c in input():
			if c == '1' and (not is_one):
				is_one = True
			elif c == '1' and is_one:
				ret += one_cnt
				one_cnt = 0
			if c == '0' and is_one:
				one_cnt += 1
		print(ret)
main()


from collections import Counter

def foo(s):
	return Counter(s.strip('0'))['0']
n = int(input())
for _ in range(n):
	s = input()
	print(foo(s))


n = int(input())
a = []
for i in range(n):
	x = list(input())
	j = len(x) - 1
	while x[j] != '1' and j >= 0:
		j = j - 1
	k = 0
	while x[k] != '1' and k < len(x) - 1:
		k = k + 1
	z = 0
	for l in range(k, j + 1):
		if x[l] == '0':
			z = z + 1
	a.append(z)
for i in range(len(a)):
	print(a[i])


import math, collections, sys
for _ in range(int(input())):
	s = input()
	a = s.find('1')
	b = s.rfind('1')
	if '1' not in s:
		print(0)
		continue
	count = 0
	for i in range(a, b + 1):
		if s[i] == '0':
			count += 1
	print(count)


t = int(input())
while t:
	a = input()
	diff = a.find('1')
	ans = 0
	temp = 0
	for i in range(diff + 1, len(a)):
		if a[i] == '1':
			temp = max(temp, i - diff - 1)
			ans = max(ans, temp + ans)
			temp = 0
			diff = i
	t -= 1
	print(ans)


n = int(input())
for i in range(n):
	pos1 = []
	arr = []
	diff = 0
	s = input()
	for x in s:
		arr.append(x)
	for f in range(len(arr)):
		if arr[f] == '0':
			continue
		elif arr[f] == '1':
			pos1.append(f)
	for d in range(len(pos1) - 1):
		if pos1[d + 1] - pos1[d] > 1:
			diff += pos1[d + 1] - pos1[d] - 1
	print(diff)


for _ in range(int(input())):
	s = input()
	counter = 0
	ans = 0
	for i in s:
		if i == '1':
			counter += 1
		if s.count('1') > counter >= 1 and i == '0':
			ans += 1
	print(ans)


import os, sys, math
t = int(sys.stdin.readline().strip())
for i in range(t):
	s = sys.stdin.readline().strip()
	nr = s.count('1')
	if nr < 2:
		print(0)
	else:
		ind1 = s.index('1')
		ind2 = len(s) - list(reversed(s)).index('1')
		print(s[ind1:ind2].count('0'))


def continuous(s):
	i = 0
	count = 0
	last = None
	for i in range(len(s)):
		if s[i] == '1':
			if last:
				count += i - last
				last = i + 1
			else:
				last = i + 1
	return count
n = int(input())
for _ in range(n):
	print(continuous(input()))


t = int(input())
v1 = [0] * t
for i in range(len(v1)):
	v1[i] = int(input())
for i in range(len(v1)):
	conzeros = 0
	num = v1[i]
	if num == 0:
		print(0)
	else:
		while num % 2 == 0:
			num = num // 10
		while num > 0:
			ultimodigito = num % 10
			num = num // 10
			if ultimodigito == 0:
				conzeros += 1
		print(conzeros)


t = int(input())
for _ in range(t):
	s = input()
	one_first = s.find('1')
	one_last = s.rfind('1')
	print(s[one_first:one_last + 1].count('0'))


for _ in range(int(input())):
	s = input()
	r = s.count('1')
	t = r
	f = 0
	if r == 0 or r == 1:
		print(0)
	else:
		for i in s:
			if i == '1':
				t -= 1
			elif t == r:
				continue
			elif t == 0:
				break
			else:
				f += 1
		print(f)


t = int(input())
b = ''
for i in range(t):
	a = input()
	if '1' in a:
		x = a.find('1')
		y = ''.join(a).rindex('1')
		z = a[x:y]
		k = b + z
		q = k.count('0')
		print(q)
	else:
		print(0)


t = int(input())
L = []
for i in range(t):
	L.append(int(input()))
for i in L:
	while i % 10 == 0 and i != 0:
		i //= 10
	print(str(i).count('0') if i != 0 else 0)


test_count = int(input())
for _ in range(test_count):
	s = input()
	ans = 0
	left = s.find('1')
	right = s.rfind('1')
	if left == -1 or left == right:
		ans = 0
	else:
		ans = s[left:right + 1].count('0')
	print(ans)


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


def check(word):
	zflag = 0
	indx = 0
	for i in range(0, len(word) - 1):
		if word[i] == '1' and word[i + 1] == '0' and (zflag == 0):
			zflag = 1
			indx = i + 1
		elif zflag == 1:
			if word[i + 1] == '1':
				zflag = 0
				temp = word[:indx]
				for j in range(indx, i + 1):
					temp = temp + '*'
				temp = temp + word[i + 1:]
				word = temp
	print(word.count('*'))
for i in range(int(input())):
	word = str(input())
	check(word)


for i in range(int(input())):
	s = input()
	cnt = s.count('1')
	if cnt < 2:
		print(0)
	else:
		ans = 0
		for j in range(len(s)):
			if s[j] == '1':
				cnt -= 1
				for t in range(j + 1, len(s)):
					if cnt == 0:
						break
					if s[t] != '1':
						ans += 1
					else:
						cnt -= 1
				break
		print(ans)


t = int(input())
for _ in range(t):
	s = list(input())
	arr = [int(i) for i in s]
	n = len(s)
	count_0 = 0
	if n == 1:
		count_0 = 0
	elif 1 in arr:
		idx_val = arr.index(1)
		idx_val1 = n - 1 - arr[n - 1::-1].index(1)
		if idx_val1 - idx_val + 1 != sum(arr[idx_val:idx_val1 + 1]):
			count_0 = idx_val1 - idx_val + 1 - arr.count(1)
		else:
			count_0 = 0
	else:
		count_0 = 0
	print(count_0)


t = int(input())
for i in range(t):
	n = input()
	n = list(n)
	s = 0
	c = []
	for j in n:
		if j == '1':
			x = n.index(j)
			n[x] = '3'
			c.append(x)
	for i in range(1, len(c)):
		s = s + c[i] - c[i - 1] - 1
	print(s)


for _ in range(int(input())):
	s = input()
	ans = 0
	if '1' not in s:
		ans = 0
	else:
		t = s.index('1')
		tt = len(s) - s[::-1].index('1') - 1
		ans = s[t:tt].count('0')
	print(ans)


t = int(input())
for i1 in range(t):
	(i, s, k, l, seq) = (0, input(), 0, 0, [])
	if s[0] == '1':
		seq += [0]
	while i < len(s):
		l = 0
		while i < len(s) and s[i] == s[k]:
			i += 1
			l += 1
		seq += [l]
		k = i
	if s[i - 1] == '1':
		seq += [0]
	if len(seq) < 3:
		M = 0
	else:
		M = sum([seq[i] for i in range(2, len(seq) - 1, 2)])
	print(M)


t = int(input())
for i in range(t):
	s = str(input())
	ans = 0
	for j in range(len(s) - 1):
		if s[j] == '1' and s[j + 1] == '0':
			cnt = j + 1
			index = 0
			while cnt < len(s):
				if s[cnt] == '1':
					index = cnt
					break
				cnt += 1
			if index != 0:
				ans += index - j - 1
	print(ans)


t = int(input())
for i in range(0, t):
	s = str(input())
	n = len(s)
	x = []
	y = 0
	for j in range(0, n):
		if s[j] == '1':
			x.append(j)
	if x == [] or x == [0] or x == [1]:
		print(0)
	else:
		p = x[0]
		q = x[-1]
		for k in range(p, q + 1):
			if s[k] == '0':
				y = y + 1
		print(y)


t = int(input())
for _ in range(t):
	s = input()
	s = list(s)
	x = s[0]
	a = 0
	if x == '1':
		s = s[::-1]
		j = 0
		for i in range(len(s)):
			if s[i] == '1':
				break
			j += 1
		for i in range(j, len(s) - 1):
			if s[i] == '0':
				a += 1
		print(a)
	else:
		j = 0
		for i in range(len(s)):
			if s[i] == '1':
				break
			j += 1
		s = s[::-1]
		k = 0
		for i in range(len(s)):
			if s[i] == '1':
				break
			k += 1
		s = s[::-1]
		for i in range(j + 1, len(s) - k):
			if s[i] == '0':
				a += 1
		print(a)


col = int(input())

def prov(s, k):
	for i in range(k, len(s)):
		if s[i] == '1':
			return True
	return False
for _ in range(col):
	x = 0
	s1 = ''
	s = list(input())
	for i in range(len(s)):
		if s[i] == '1':
			s1 = s[i:]
			break
	for i in range(len(s1)):
		if s1[i] == '0' and prov(s1, i):
			x += 1
	print(x)


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	s = stdin.readline().strip()
	f1 = False
	ctr = 0
	tctr = 0
	for i in range(len(s)):
		if s[i] == '1':
			f1 = True
		if f1 == True and s[i] == '0':
			tctr += 1
		if f1 == True and s[i] == '1':
			ctr += tctr
			tctr = 0
	stdout.write(str(ctr) + '\n')


test = int(input())
for t in range(test):
	s = input()
	count = 0
	prev_1 = 0
	final_1 = 0
	flag = True
	for i in range(len(s)):
		if s[i] == '1':
			final_1 = i
			if flag:
				prev_1 = final_1
				flag = False
			else:
				count += final_1 - prev_1 - 1
				prev_1 = final_1
	print(count)


final = []
for ___ in range(int(input())):
	string = input().rstrip('0').lstrip('0')
	final.append(string.count('0'))
for thing in final:
	print(thing)


from sys import stdin
input = stdin.readline
for xoxo in range(1):
	for _ in range(int(input())):
		s = input()
		if s.count('1') == 0:
			print('0')
			continue
		for i in range(len(s)):
			if s[i] == '1':
				k = i
				break
		s = s[k:]
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '1':
				k = i
				break
		s = s[:k + 1]
		print(s.count('0'))


for i in range(int(input())):
	s = input()
	a = []
	for i in range(len(s)):
		if s[i] == '1':
			a.append(i)
	if len(a) == 0:
		print(0)
	else:
		print(s[a[0]:a[len(a) - 1]].count('0'))


n = int(input())
for i in range(n):
	s = input()
	if s.count('1') > 0:
		f = s.index('1')
		s = s[f + 1:]
		gap = 0
		while s.count('1') != 0:
			f2 = s.index('1')
			if f2 != 0 and f2 != len(s) - 1:
				gap = gap + f2
				s = s[f2 + 1:]
			else:
				s = s[f2 + 1:]
				gap = gap + f2
		print(gap)
	else:
		print(0)


from collections import defaultdict
from itertools import permutations
from os import system
import sys
import queue
import math
for i in range(int(input())):
	word = input()
	start = None
	end = None
	counter = 0
	for i in range(0, len(word)):
		if word[i] == '1':
			if start == None:
				start = i
			end = i
	if start != None and end != None:
		for i in range(start, end + 1):
			if word[i] == '0':
				counter += 1
	print(counter)


n = int(input())
while n > 0:
	s = input()
	num = []
	for k in s:
		num.append(int(k))
	fi = num.count(0)
	if len(num) == 1:
		print(0)
	elif fi == len(num):
		print(0)
	else:
		i1 = num.index(1)
		nd = num[0:]
		num.reverse()
		i2 = len(num) - num.index(1) - 1
		nu = nd[i1:i2 + 1]
		c = nu.count(0)
		print(c)
	n -= 1


for _ in range(int(input())):
	a = list(input())
	n = len(a)
	prev = -1
	ans = 0
	for i in range(0, n):
		if prev == -1 and a[i] == '1':
			prev = i
		elif a[i] == '1':
			ans += i - prev - 1
			prev = i
	print(ans)


def main():
	n = int(input())
	for i in range(n):
		a = input()
		b = [a[0]]
		c = [1]
		for i in range(1, len(a)):
			if a[i] == b[-1]:
				c[-1] += 1
			else:
				b.append(a[i])
				c.append(1)
		summ = 0
		for i in range(1, len(b) - 1):
			if b[i] == '0':
				summ += c[i]
		print(summ)
main()


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 10 ** 9 + 7

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').split(' ')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	s = li3()
	tot = tru = curr = 0
	for i in s:
		if i == 0 and tru:
			curr += 1
		elif i == 1 and tru:
			tot += curr
			curr = 0
		elif i == 1:
			tru = 1
	print(tot)


T = int(input())
for _ in range(T):
	s = input()
	s = s.strip('0')
	print(sum((x == '0' for x in s)))


from sys import stdin, stdout
from os import path
if path.exists('inp.txt'):
	stdin = open('inp.txt', 'r')
q = int(stdin.readline())
for _ in range(q):
	s = stdin.readline()
	b = []
	ans = 0
	for i in range(len(s)):
		if s[i] == '1':
			b.append(i)
	for i in range(len(b) - 1):
		ans += b[i + 1] - b[i] - 1
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = input().rstrip() + '0'
	left = s.find('1')
	right = s.rfind('1')
	cnt = s[left:right + 1].count('0')
	print(cnt)


T = int(input())

def solve(x):
	x = x.rstrip('0')
	x = x.lstrip('0')
	return x.count('0')
for _ in range(T):
	print(solve(input()))


t = int(input())
t1 = 0
while t1 < t:
	x = input()
	f = l = -1
	i = 0
	for ch in x:
		if ch == '1':
			if f == -1:
				f = i
			elif f != -1:
				l = i
		i = i + 1
	j = 0
	ans = 0
	for ch in x:
		if j < f:
			j = j + 1
			continue
		elif j > f:
			if j < l:
				if ch == '0':
					ans = ans + 1
		j = j + 1
	print(ans)
	t1 = t1 + 1


for _ in range(int(input())):
	s = input()
	ans = 0
	l = s.find('1')
	h = s.rfind('1')
	for i in range(l + 1, h):
		if s[i] == '0':
			ans += 1
	print(ans)


for _ in [0] * int(input()):
	s = str(input())
	l = 0
	r = 0
	ans = 0
	for i in range(len(s)):
		if s[i] == '1':
			l = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			r = i
			break
	for i in range(l + 1, r):
		if s[i] == '0':
			ans += 1
	print(ans)


try:
	t = int(input())
	for _ in range(t):
		string = str(input())
		start = 0
		n = len(string)
		if '1' in string:
			start = string.index('1')
		end = n - 1
		i = end
		while i >= 0:
			if string[i] == '0':
				end -= 1
				i -= 1
			else:
				break
		print(string.count('0', start, end + 1))
except Exception:
	pass


t = int(input())
for _ in range(t):
	s = input()
	start = -1
	k = 0
	start = end = -1
	while k < len(s):
		if s[k] == '1':
			start = k
			break
		k += 1
	k = len(s) - 1
	while k >= 0:
		if s[k] == '1':
			end = k
			break
		k -= 1
	if start == end == -1:
		print(0)
	else:
		print(s[start:end + 1].count('0'))


t = int(input())
for _ in range(t):
	s = str(input())
	if len(s.split('1', 1)) > 1 and s.count('1') > 1:
		print(s.split('1', 1)[1].rsplit('1', 1)[0].count('0'))
	else:
		print('0')


l = int(input())
for _ in range(l):
	s = input()
	try:
		st = s.find('1')
		end = s.rfind('1')
	except:
		print('0')
		continue
	print(s[st:end].count('0'))


def solve():
	lst = list(input())
	if len(lst) == 1:
		print(0)
		return
	if '1' not in lst:
		print(0)
		return
	for i in range(len(lst)):
		if lst[i] == '1':
			k = i
			break
	for i in range(len(lst) - 1, -1, -1):
		if lst[i] == '1':
			k1 = i
			break
	ans = lst[k:k1].count('0')
	print(ans)
t = int(input())
for i in range(t):
	solve()


def f(s):
	ans = 0
	counting = False
	zeroes = 0
	for c in s:
		if c == '0':
			if counting:
				zeroes += 1
		else:
			counting = True
			ans += zeroes
			zeroes = 0
	return ans

def main():
	for t in range(int(input())):
		print(f(input()))
main()


t = int(input())
for _ in range(t):
	string = input()
	a = [0 for _ in range(len(string) + 1)]
	for (i, s) in enumerate(string):
		if s == '1':
			a[i + 1] = a[i] + 1
		else:
			a[i + 1] = a[i]
	l = 1
	while l < len(a) and (not a[l]):
		l += 1
	r = len(a) - 1
	while r and a[r] == a[r - 1]:
		r -= 1
	print(max(0, r - l + 1 - (a[r] - a[l - 1])))


n = int(input())
for _ in range(n):
	s = input()
	ans = 0
	count = 0
	check = 0
	for i in range(len(s)):
		if s[i] == '1':
			if check:
				ans += count
			count = 0
			check = 1
		else:
			count += 1
	print(ans)


for i in range(int(input())):
	a = input()
	b = list(a)
	if b.count('1') == 0:
		print(0)
	else:
		c = b.index('1')
		b.reverse()
		d = b.index('1')
		d = len(a) - 1 - d
		e = b.count('1')
		print(abs(e - (d - c + 1)))


from sys import stdin
n = int(stdin.readline().rstrip())
for _ in range(n):
	bits = stdin.readline().rstrip()
	found_left = False
	li = 0
	c = 0
	for (i, bit) in enumerate(bits):
		if bit == '1':
			if found_left and bits[i - 1] == '0':
				c += i - li - 1
			else:
				found_left = True
			li = i
	print(c)


def num_zeros_to_remove(s):
	s = s.strip('0')
	count = 0
	for c in s:
		if c == '0':
			count += 1
	return count

def contiguous_subsegment():
	t = int(input())
	for i in range(t):
		print(num_zeros_to_remove(input()))
contiguous_subsegment()


for _ in range(int(input())):
	m = input()
	count = 0
	index1 = 0
	index2 = 0
	for i in range(len(m)):
		if m[i] == '1':
			index1 = i
			break
	for i in range(len(m) - 1, -1, -1):
		if m[i] == '1':
			index2 = i
			break
	for i in range(index1, index2):
		if m[i] == '0':
			count += 1
	print(count)


from sys import stdin, stdout
q = int(stdin.readline())
for x in range(q):
	str1 = str(stdin.readline())
	if '1' in str1:
		start = str1.index('1')
	else:
		print('0')
		continue
	str2 = str1[::-1]
	end = len(str2) - str2.index('1')
	str3 = str1[start:end]
	num1 = str3.count('0')
	print(num1)


for _ in range(int(input())):
	st = input()
	a = [i for i in range(len(st)) if st[i] == '1']
	ctr = 0
	for i in range(len(a) - 1):
		ctr += a[i + 1] - a[i] - 1
	print(ctr)


def I():
	return list(map(int, input().split()))
for t in range(int(input())):
	s = input()
	c = 0
	f = 0
	i = 0
	while i < len(s):
		if s[i] == '1':
			while i < len(s) and s[i] == '1':
				i += 1
			if i < len(s):
				ct = 0
				while i < len(s) and s[i] == '0':
					ct += 1
					i += 1
				if i < len(s):
					c += ct
		else:
			i += 1
	print(c)


def analyze_string(st):
	print(st.strip('0').count('0'))

def main():
	number_of_test_cases = int(input())
	for _ in range(number_of_test_cases):
		test_case = input()
		analyze_string(test_case)
main()


for _ in range(int(input())):
	st = input()
	try:
		print(st[st.find('1'):st.rindex('1') + 1].count('0'))
	except ValueError:
		print(0)


n = int(input())
for _ in range(n):
	s = list(input())
	i = 0
	say = 0
	el = 0
	t = 0
	while i < len(s) - 1:
		if s[i] == '1' and s[i + 1] == '0':
			del s[i + 1]
			t = 1
			i -= 1
			el += 1
		elif t == 1:
			t = 0
			say += el
			el = 0
		i += 1
	print(say)


t = int(input())
inputs = [''] * t
for i in range(t):
	inputs[i] = input()
for s in inputs:
	s = s.strip('0')
	print(sum(map(lambda c: int(c == '0'), s)))


t = int(input())
s = ''
for z in range(t):
	s = input()
	for i in range(len(s)):
		if s[0] == '0':
			s = s[1:]
		else:
			break
	for i in range(len(s)):
		if s[-1] == '0':
			s = s[:-1]
		else:
			break
	print(s.count('0'))


for _ in range(int(input())):
	s = input()
	l = [s[0]]
	f = [1]
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			f[-1] += 1
		else:
			l.append(s[i])
			f.append(1)
	ans = 0
	for i in range(len(l)):
		if l[i] == '0':
			ans += f[i]
	if l[0] == '0':
		ans -= f[0]
	if l[-1] == '0':
		ans -= f[-1]
		if len(l) == 1:
			ans += f[-1]
	print(ans)


n = int(input())
for i in range(n):
	s = input()
	if s[0] == '0':
		while True:
			if len(s) == 0 or s[0] == '1':
				break
			s = s[1:]
	if len(s) != 0 and s[-1] == '0':
		while True:
			if len(s) == 0 or s[-1] == '1':
				break
			s = s[:-1]
	if len(s) == 0:
		print(0)
		continue
	now = '1'
	count = 0
	lst = []
	for i in range(len(s)):
		if s[i] != now:
			lst.append(count)
			now = '0' if now == '1' else '1'
			count = 1
		else:
			count += 1
	print(sum(lst[1::2]))


t = int(input())
for _ in range(t):
	s = input()
	flag = 0
	arr = []
	for i in range(len(s)):
		if s[i] == '1':
			arr.append(i)
	ans = 0
	if len(arr) > 0:
		start = arr[0]
		for i in range(1, len(arr)):
			ans += arr[i] - start - 1
			start = arr[i]
	print(ans)


t = int(input())
for z in range(t):
	st = input()
	st2 = st[::-1]
	_sum = 0
	s = st.find('1')
	if s == -1:
		print(0)
		continue
	fi = st2.find('1')
	for i in range(s, len(st) - fi):
		if st[i] == '0':
			_sum += 1
	print(_sum)


n = int(input())
m = []
for i in range(n):
	s = int(input())
	m.append(s)
for s in m:
	t = 0
	if s > 0:
		while s % 10 == 0:
			s = s // 10
		s = str(s)
		for i in s:
			if i == '0':
				t += 1
	print(t)


from sys import stdin

def inp():
	return (ss.rstrip() for ss in stdin).__next__()

def itg():
	return int(inp())

def mpint():
	return map(int, inp().split())
for case in range(itg()):
	s = inp()
	first_1 = s.find('1')
	if first_1 < 0:
		print(0)
		continue
	last_1 = s.rfind('1')
	ans = s[first_1 + 1:last_1].count('0')
	print(ans)


import sys
t = int(sys.stdin.readline().rstrip())

def main():
	for _ in range(t):
		s = sys.stdin.readline().rstrip()
		prev = '0'
		cnt = 0
		res = 0
		flag = False
		for char in s:
			if char == '0':
				if flag:
					cnt += 1
			else:
				flag = True
				if prev == '0':
					res += cnt
					cnt = 0
		yield res
ans = main()
print(*ans, sep='\n')


for _ in range(int(input())):
	inp = input()
	start = None
	end = None
	res = 0
	for i in range(len(inp)):
		char = inp[i]
		if char == '1':
			if start == None:
				start = i
			end = i
	if start != None:
		for char in inp[start:end + 1]:
			if char == '0':
				res += 1
	print(res)


t = int(input())
while t:
	s = input()
	ls = []
	for i in range(len(s)):
		if s[i] == '1':
			ls.append(i)
	if len(ls) == 0:
		print(0)
	else:
		count = 0
		for i in range(ls[0], ls[-1]):
			if s[i] == '0':
				count += 1
		print(count)
	t -= 1


x = int(input())
for i in range(x):
	curr_s = str(input())
	both_removed = curr_s.strip('0')
	curr_s = str(both_removed)
	count = 0
	for c in curr_s:
		if c == '0':
			count += 1
	print(count)


import sys
from functools import reduce
from collections import Counter
import time
import datetime
import math

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

def sip():
	return input()

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

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

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

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.insert(i, arr)
	return lst

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

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
n = ip()
while n:
	n -= 1
	s = sip()
	flag = 0
	count = 0
	for i in s:
		if i == '1':
			flag = 1
		if i == '0':
			if flag == 1:
				count += 1
	s = s[::-1]
	for i in s:
		if i == '1':
			flag = 0
			break
		if i == '0':
			count -= 1
	print(max(count, 0))


MOD = 1000000007
MOD2 = 998244353
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())
for _ in range(ii()):
	s = si()
	n = len(s)
	c = 0
	fg1 = 0
	for i in range(n):
		if fg1 != 1 and s[i] == '1':
			fg1 = 1
		if fg1 and s[i] == '0' and ('1' in s[i + 1:]):
			c += 1
	print(c)


t = int(input())
for _ in range(t):
	arr = list(map(int, input().strip()))
	n = len(arr)
	fir = 0
	for i in range(n):
		if arr[i] == 1:
			fir = i
			break
	last = -1
	for i in range(n - 1, -1, -1):
		if arr[i] == 1:
			last = i
			break
	last -= 1
	if last <= fir:
		print(0)
	else:
		print(last - fir - sum(arr) + 2)


isVerbose = False

def verbosity(msg):
	if isVerbose:
		print(msg)
all_test_cases = []
nmb_remove_zeros = []
nmb_test_cases = int(input())
verbosity(f'nmb_test_cases: {nmb_test_cases}')
for test_case in range(nmb_test_cases):
	verbosity('und rein')
	inp_str = input()
	all_test_cases.append(inp_str)
verbosity(f'all test cases: {all_test_cases}')
for test_case in all_test_cases:
	verbosity(f'\nder test case: {test_case}')
	if not '1' in test_case:
		nmb_remove_zeros.append('0')
		continue
	index_first_one = list(test_case).index('1')
	verbosity(f'erster: {index_first_one}')
	rev_test_case = list(test_case)
	rev_test_case.reverse()
	index_last_one = rev_test_case.index('1')
	verbosity(f'letzter: {index_last_one}')
	verbosity(f'die liste: {list(test_case[index_first_one:len(test_case) - index_last_one - 1])}')
	index_last_one = -1 * index_last_one - 1
	result = list(test_case[index_first_one:index_last_one]).count('0')
	verbosity(f'result: {result}')
	nmb_remove_zeros.append(result)
verbosity(3 * '\n')
print(*nmb_remove_zeros, sep='\n')


import math

def main(val):
	ans = 0
	start = None
	for i in range(len(val) - 1):
		if val[i] == '0' and val[i + 1] == '1' and (start != None):
			ans += i - start
		elif val[i] == '1' and val[i + 1] == '0':
			start = i
	print(ans)

def runner():
	val = input()
	for i in range(int(val)):
		ans = input()
		main(ans)
runner()


t = int(input())
while t > 0:
	a = input()
	n = len(a)
	for i in range(n):
		if a[i] == '1':
			break
	ans = 0
	cur = 0
	i += 1
	while i < n:
		if a[i] == '1':
			ans += cur
			cur = 0
		else:
			cur += 1
		i += 1
	print(ans)
	t -= 1


def main():
	import sys
	input = sys.stdin.readline
	t = int(input())
	for _ in range(t):
		s = input().rstrip('\n')
		ans = 0
		c = s.count('1')
		cnt = 0
		for si in s:
			if 0 < cnt < c:
				if si == '0':
					ans += 1
			if si == '1':
				cnt += 1
		print(ans)
main()


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


e = int(input())
for t in range(e):
	s = input()
	n = 0
	first1 = -1
	last1 = 0
	zero = 0
	for i in s:
		if i == str(1) and first1 == -1:
			first1 = n
		if i == str(1):
			last1 = n
		n += 1
	n = 0
	for i in s:
		if n >= first1 and n <= last1 and (last1 != 0):
			if i == str(0):
				zero += 1
		n += 1
	print(zero)


n = int(input())
for i in range(n):
	s = input()
	k = 0
	if '1' in s:
		f = s.index('1')
		w = list(s[::-1])
		l = w.index('1')
		l = len(s) - l
		for i in range(f, l):
			if s[i] == '0':
				k += 1
	print(k)


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

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

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def summarizeList(l):
	sl = l
	a = sl[0]
	c = 1
	res = []
	for x in sl[1:]:
		if x == a:
			c += 1
		else:
			res.append([a, c])
			a = x
			c = 1
	res.append([a, c])
	return res

def main():
	n = I()
	ans = []
	for _ in range(n):
		s = list(S())
		sl = summarizeList(s)
		x = 0
		n = len(sl)
		for (i, (a, c)) in enumerate(sl):
			if i != 0 and i != n - 1:
				if a == '0':
					x += c
		ans.append(x)
	for x in ans:
		print(x)
main()


for i in range(int(input())):
	s = input()
	if s.count('1') > 1:
		b1 = s.find('1')
		a1 = len(s) - 1 - s[::-1].find('1')
		print(s[b1:a1].count('0'))
	else:
		print('0')


for t in range(int(input())):
	a = [int(v) for v in input()]
	c = 0
	for i in range(len(a)):
		if a[i]:
			kf = i
			break
	for j in range(len(a) - 1, 0, -1):
		if a[j]:
			kb = j
			break
	if sum(a) == 1:
		print(c)
	elif sum(a):
		for i in range(kf + 1, kb, 1):
			if not a[i]:
				c += 1
		print(c)
	else:
		print(c)


for _ in range(int(input())):
	s = input()
	n = len(s)
	l = 0
	r = n - 1
	while l < n - 1 and s[l] == '0':
		l += 1
	while r > 0 and s[r] == '0':
		r -= 1
	res = 0
	if l == r:
		print(0)
	else:
		for i in range(l, r + 1):
			if s[i] == '0':
				res += 1
		print(res)


t = int(input())

def solve():
	case = input()
	sep = []
	temp = ''
	indices = []
	for i in case:
		if i == '0':
			if temp != '':
				sep.append(temp)
				temp = ''
				indices.append(len(sep) - 1)
				sep.append(i)
			else:
				sep.append(i)
		else:
			temp += '1'
	if temp != '':
		sep.append(temp)
		indices.append(len(sep) - 1)
	count = 0
	for i in range(1, len(indices)):
		count += indices[i] - indices[i - 1] - 1
	print(count)
for i in range(t):
	solve()


t = int(input())
for _ in range(t):
	ans = 0
	s = input()
	s_rev = s[::-1]
	if s.count('1') != 0:
		rev_ind = s_rev.index('1')
		ind = s.index('1')
		if ind < len(s):
			s = s[ind:len(s) - rev_ind]
			for i in s:
				if i == '0':
					ans += 1
	print(ans)


t = int(input())
for f in range(t):
	x = input()
	if len(x) == x.count('0'):
		print('0')
	else:
		fz = x.index('1')
		i = len(x) - 1
		c = 0
		while i >= 0:
			if x[i] == '0':
				c = c + 1
				i = i - 1
			else:
				break
		if len(x) - fz - c == x.count('1'):
			print(0)
		else:
			print(len(x) - x.count('1') - fz - c)


for t in range(int(input())):
	a = input()
	l = a.find('1')
	r = a.rfind('1')
	if l == r:
		print('0')
	else:
		print(a.count('0', l, r))


from collections import deque

def makeRepeat(s):
	repeat = [[s[0], 0]]
	for ch in s:
		if ch == repeat[-1][0]:
			repeat[-1][1] += 1
		else:
			repeat.append([ch, 1])
	return repeat

def solve(S):
	repeat = deque(makeRepeat(S))
	if len(repeat) == 1:
		return 0
	if repeat[0][0] == '0':
		repeat.popleft()
	if repeat and repeat[-1][0] == '0':
		repeat.pop()
	total = 0
	for (char, count) in repeat:
		if char == '0':
			total += count
	return total
(T,) = map(int, input().split())
for t in range(T):
	S = input()
	ans = solve(S)
	print(ans)


from itertools import groupby as gb
n = int(input())
for i in range(n):
	s = input()
	g = gb(list(s))
	l = []
	for (k, v) in g:
		l.append([k, len(list(v))])
	if l[0][0] == '0':
		l = l[1:]
	if len(l) == 0:
		print(0)
		continue
	if l[-1][0] == '0':
		l = l[:-1]
	res = 0
	for (k, v) in l:
		if k == '1':
			continue
		res += v
	print(res)


q = int(input())
for i in range(0, q):
	s = input()
	if s.count('1') == 0:
		print(0)
	else:
		p = 0
		while s[p] == '0':
			p = p + 1
		q = len(s) - 1
		while s[q] == '0':
			q = q - 1
		print(q - p + 1 - s.count('1'))


for _ in range(int(input())):
	s = input()
	ss1 = s.find('1')
	ss2 = s[::-1].find('1')
	c = 0
	if ss1 == ss2 == -1:
		print(0)
	else:
		ss2 = len(s) - ss2
		for i in range(ss1, ss2):
			if s[i] == '0':
				c += 1
		print(c)


t = int(input())
for _ in range(t):
	s = input()
	s = list(s)
	if '1' not in s:
		print(0)
	else:
		start = s.index('1')
		end = len(s) - 1 - s[::-1].index('1')
		count = 0
		for item in range(start, end + 1):
			if s[item] == '0':
				count += 1
		print(count)


n = int(input())
for _ in range(n):
	count = 0
	mid = 0
	start = False
	i = input()
	for x in i:
		if not start:
			if x == '1':
				start = True
				continue
		elif start:
			if x == '1':
				count += mid
				mid = 0
			elif x == '0':
				mid += 1
	print(count)


for i in range(int(input())):
	s = input()
	if '1' not in s or s.count('1') == 1:
		print(0)
	else:
		a = list(s)
		a.reverse()
		q = s[s.find('1'):len(s) - ''.join(a).find('1')]
		print(q.count('0'))


tc = int(input())
for i in range(tc):
	s = input()
	(c, tc, r) = (0, 0, 1)
	l = len(s)
	if s[0] != '1':
		try:
			r = s.index('1') + 1
		except ValueError as e:
			r = l
	for j in range(r, l):
		if s[j] != '1':
			tc += 1
		elif tc > 0:
			c += tc
			tc = 0
	print(c)


test = int(input())
while test:
	tmp = input()
	step = 0
	sum = 0
	for i in range(len(tmp) - 1):
		if tmp[i] == '1' and tmp[i + 1] == '0':
			i += 1
			while i < len(tmp) and tmp[i] == '0':
				step += 1
				i += 1
			if i != len(tmp):
				sum += step
				step = 0
	test -= 1
	print(sum)


n = int(input())
for k in range(n):
	string = input()
	i = 0
	counter = 0
	while i < len(string):
		if string[i] == '1':
			pred = string[i]
			old = i
			while i < len(string) - 1 and string[i + 1] == '0':
				i += 1
			if i < len(string) - 1 and pred == string[i + 1]:
				counter += i - old
		i += 1
	print(counter)


import sys
import math
read = lambda : list(map(int, sys.stdin.readline().strip().split()))
for _ in range(int(input())):
	s = input()
	c = 0
	st = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
	ans = 0
	for i in range(len(s)):
		if s[i] == '1':
			st += 1
			c -= 1
		if c > 0 and st > 0:
			if s[i] == '0':
				ans += 1
	print(ans)


t = int(input(''))
mat = []
for i in range(t):
	mat.append(input(''))
for i in range(t):
	tst = mat[i]
	l = len(tst)
	try:
		fst = tst.index('1')
		rev = tst[l::-1]
		lst = l - rev.index('1')
		print(tst[fst:lst].count('0'))
	except:
		print(0)


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = input()
	st = -1
	for i in range(len(s)):
		if s[i] == '1':
			st = i
			break
	end = -1
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			end = i
			break
	ans = 0
	if st != end:
		for i in range(st + 1, end):
			if s[i] == '0':
				ans += 1
	print(ans)


for _ in range(int(input())):
	a = input()
	a = a[a.find('1'):len(a) - a[::-1].find('1')].strip('0')
	print(a.count('0'))


v = int(input())
for j in range(v):
	a = input()
	k = 0
	for i in a:
		if int(i) == 1:
			k += 1
	m = 0
	i = 1
	t = 0
	for i in range(len(a)):
		if int(a[i]) == 1:
			m = 1
			k -= 1
		if m == 1 and int(a[i]) == 0 and (k > 0):
			t += 1
		i += 1
	print(t)


import re
test = int(input())
for i in range(test):
	text = re.findall('1([0].*)1', input())
	if not len(text) == 0:
		print(text[0].count('0'))
	else:
		print('0')


t = int(input())
for _ in range(t):
	a = input()
	if '1' in a:
		print(a[a.index('1'):len(a) - a[::-1].index('1')].count('0'))
	else:
		print('0')


for i in range(int(input())):
	s = str(input())
	x = 0
	y = 0
	counter = 0
	if s.count('1') == 0 or s.count('0') == 0:
		print(0)
	else:
		for j in s:
			if j == '1':
				x = s.index(j)
				break
		s = s[x:]
		w = s[::-1]
		for k in w:
			if k == '1':
				y = w.index(k)
				break
		w = w[y:]
		for u in w:
			if u == '0':
				counter += 1
		print(counter)


n = input()
a = []
for _ in range(int(n)):
	a.append(input().strip('0'))
for i in a:
	temp = 0
	for j in i:
		if j == '0':
			temp += 1
	print(temp)


t = int(input())
for _ in range(t):
	string = str(input())
	res = 0
	arr = []
	for i in range(len(string)):
		if string[i] == '1':
			arr.append(i)
	i = 1
	while i < len(arr):
		res += arr[i] - arr[i - 1] - 1
		i += 1
	print(res)


n = int(input())
while n > 0:
	prev_count = 0
	count = 0
	ans = 0
	s = input()
	l = [0] * n
	f = 0
	for i in range(0, len(s)):
		if s[i] == '0':
			count = count + 1
		if s[i] == '1':
			if f != 0:
				ans = ans + (count - prev_count)
			f = 1
			prev_count = count
	print(ans)
	n = n - 1


T = int(input())
i = 0
while i < T:
	s = input()
	s = [int(x) for x in s]
	ans = 0
	if sum(s) == 0:
		print(0)
	else:
		t = s.index(1)
		n = len(s)
		s.reverse()
		t1 = s.index(1)
		s.reverse()
		for x in s[t:n - t1]:
			if x == 0:
				ans += 1
		print(ans)
	i += 1


t = int(input())
while t != 0:
	n = input()
	pos = n.find('1')
	posr = n.rfind('1')
	x = 0
	for i in range(pos + 1, posr):
		if n[i] == '0':
			x += 1
		else:
			x += 0
	print(x)
	t -= 1


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


t = int(input())
for i in range(t):
	answer = 0
	s = input()
	ones = s.count('1')
	zeroes = len(s) - ones
	if ones <= 1:
		answer = 0
	else:
		first_one = -1
		last_one = -1
		for j in range(len(s)):
			if s[j] == '1':
				first_one = j
				break
		for j in range(len(s) - 1, first_one, -1):
			if s[j] == '1':
				last_one = j
				break
		for j in range(first_one, last_one):
			if s[j] == '0':
				answer += 1
	print(answer)


n = int(input())
for i in range(n):
	s = input()
	x = s.find('1')
	y = s.rfind('1')
	if x == -1:
		print(0)
		continue
	p = 0
	for j in range(x, y, 1):
		if s[j] == '0':
			p += 1
	print(p)


import math
import collections
import functools
import sys
import os

def solve():
	s = input()
	(me, mx) = (10 ** 9 + 7, -1)
	cnt = 0
	for i in range(len(s)):
		if s[i] == '0':
			continue
		mx = max(mx, i)
		me = min(me, i)
		cnt += 1
	if cnt == 0:
		print(0)
	else:
		print(mx + 1 - me - cnt)

def main():
	T = 1
	T = int(input())
	while T:
		solve()
		T -= 1
main()


for _ in range(int(input())):
	l = list(input())
	for i in range(len(l)):
		l[i] = int(l[i])
	prev = -1
	d = 0
	o = 0
	for i in l:
		if i == 1:
			if prev != 1:
				prev = 1
			else:
				o += d
				d = 0
		elif prev == 1:
			d += 1
	print(o)


import math
import itertools
from sys import stdin
from functools import reduce
from collections import deque
from sys import setrecursionlimit
from collections import defaultdict
import heapq
input = stdin.readline

def I():
	return int(input())

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

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

def LIN(N):
	return [list(map(int, input().split())) for _ in range(N)]
gcd = math.gcd
Inf = float('Inf')

def solve():
	s = input()
	l = 0
	r = 0
	for i in range(len(s)):
		if s[i] == '1':
			l = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			r = i
			break
	ans = 0
	for i in range(l, r):
		if s[i] == '0':
			ans += 1
	print(ans)

def main():
	t = 1
	t = I()
	for i in range(1, t + 1):
		solve()
main()


for i in range(int(input())):
	c = 0
	s = input()
	f = s.find('1')
	if f == -1:
		print(0)
		continue
	for i in range(f + 1, len(s)):
		if s[i] == '1':
			c += i - f - 1
			f = i
	print(c)


from math import *
from copy import *
from string import *
from random import *
from bisect import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
from collections import defaultdict

def solve(s):
	n = len(s)
	one = 0
	if s.count('1') < 2:
		return 0
	last = n - 1 - s[::-1].find('1')
	ans = 0
	for i in range(last + 1):
		if s[i] == '1':
			one = 1
		elif one:
			ans += 1
	return ans
T = int(input())
for _ in range(T):
	s = input()
	print(solve(s))


t = int(input())
while t:
	n = input()
	try:
		start = n.index('1')
		end = len(n) - n[::-1].index('1')
	except:
		print(0)
		t -= 1
		continue
	print(n[start:end].count('0'))
	t -= 1


for _ in range(int(input())):
	s = str(input())
	arr = []
	for (n, i) in enumerate(s):
		if i == '1':
			arr.append(n)
	if '1' in s:
		f = arr[0]
		l = arr[-1]
		print(s.count('0', f, l))
	else:
		print(0)


for t in range(int(input())):
	s = input()
	prev = -1
	count = 0
	c = 0
	for i in range(len(s)):
		if s[i] == '1':
			if prev == -1:
				prev = i
			else:
				count += c
				prev = i
			c = 0
		else:
			c += 1
	print(count)


n = int(input())
while n > 0:
	st = input()
	l = st.find('1')
	r = st.rfind('1')
	if l == r:
		print('0')
	else:
		count = 0
		for i in range(l, r + 1):
			if st[i] == '0':
				count += 1
		print(count)
	n -= 1


for _ in range(int(input())):
	res = 0
	t = 0
	start = False
	for c in input():
		if c == '1':
			start = True
		if start and c == '0':
			t += 1
		if start and c == '1':
			res += t
			t = 0
	print(res)


for case in range(int(input())):
	s = input()
	indices = []
	for i in range(len(s)):
		if s[i] == '1':
			indices.append(i)
	ans = 0
	for i in range(1, len(indices)):
		ans += indices[i] - indices[i - 1] - 1
	print(ans)


t = int(input())
for i in range(t):
	str1 = list(input())
	if len(str1) == 1:
		print(0)
	elif str1.count('1') == 0:
		print(0)
	elif str1.count('1') == 1:
		print(0)
	else:
		lst = []
		sum1 = 0
		for i in range(len(str1)):
			if str1[i] == '1':
				lst.append(i)
		for i in range(len(lst) - 1):
			sum1 += lst[i + 1] - lst[i] - 1
		print(sum1)


for i in range(int(input())):
	var = input()
	if var.count('1') == 0:
		print(0)
	else:
		var = var[var.index('1'):]
		x = var[::-1]
		var = x[x.index('1'):][::-1]
		print(var.count('0'))


local = False
if local:
	file = open('A.txt', 'r')

def IN():
	if local:
		return file.readline()
	else:
		return input()

def solve(s):
	ans = start = end = 0
	while start < len(s) - 1:
		while start < len(s) - 1:
			if s[start] == '1' and s[start + 1] == '0':
				break
			start += 1
		end = start + 2
		while end < len(s):
			if s[end] == '1' and s[end - 1] == '0':
				ans += end - start - 1
				start = end
				break
			end += 1
		if end == len(s):
			break
	return ans
t = int(IN())
for i in range(t):
	s = IN()
	print(solve(s))


t = int(input())
while t > 0:
	s = input()
	flag = 0
	tc = 0
	count = 0
	for i in range(len(s)):
		if s[i] == '0':
			count += 1
		if s[i] == '1' and flag == 0:
			flag += 1
			count = 0
		if s[i] == '1' and flag != 0:
			tc += count
			count = 0
	t -= 1
	print(tc)


def limpa_zeros(list):
	count = 0
	for count in range(len(list)):
		if list[count] == '0':
			count += 1
		elif list[count] == '1':
			return count
	return 0
w = input()
infos = []
for i in range(int(w)):
	info = input()
	infos.append(info)
for string in infos:
	zeros = 0
	i = 0
	string = list(string)
	for i in range(len(string)):
		if string[i] == '1':
			zeros += limpa_zeros(string[i + 1:])
	print(zeros)


p = int(input())
for i in range(p):
	s = input()
	count = 1
	arr = []
	last = s[0]
	out = 0
	for j in s[1:]:
		if j == last:
			count += 1
			last = j
		else:
			arr.append((last, count))
			count = 1
			last = j
	arr.append((last, count))
	last = arr[0][0]
	for j in range(1, len(arr)):
		if last == '1' and j != len(arr) - 1:
			out += arr[j][1]
		last = arr[j][0]
	print(out)


n = int(input())
res = []
for i in range(n):
	c = input()
	if '1' in c:
		f = c.index('1')
		s = len(c) - c[::-1].index('1') - 1
		n = c[f:s]
		res.append(n.count('0'))
		print
	else:
		res.append(0)
for x in res:
	print(x)


import math
t = int(input(''))
for i in range(t):
	n = input('')
	if n.count('1') == 0:
		print(0)
	else:
		pos2 = 0
		for j in range(len(n) - 1, -1, -1):
			if n[j] == '1':
				pos2 = j
				break
		print(n[n.index('1'):pos2 + 1:1].count('0'))


t = int(input())
mass = []
for i in range(t):
	s = input()
	c = 0
	for j in range(s.find('1'), s.rfind('1')):
		if s[j] == '0':
			c += 1
	mass.append(c)
for i in mass:
	print(i)


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict

def solution(s):
	s = list(s)
	if '1' not in s:
		print(0)
		return
	while s[-1] == '0':
		s.pop()
	while s[0] == '0':
		s.pop(0)
	print(s.count('0'))

def main():
	for _ in range(int(input())):
		solution(input())
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')
main()


q = int(input())
for _ in range(q):
	s = input()
	t = s[::-1]
	try:
		id1 = s.index('1')
		id2 = len(s) - t.index('1')
		a = s[id1:id2]
		b = a.replace('0', '')
		print(len(a) - len(b))
	except:
		print(0)


n = input()
for i in range(int(n)):
	string = input()
	lest = 0
	res = 0
	b = True
	for ch in string:
		if ch == '0':
			if b:
				continue
			else:
				res += 1
				lest += 1
		else:
			lest = 0
			b = False
	res = res - lest
	print(res)


import sys
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())
t = inp()
for i in range(t):
	s = insr()
	c = 0
	for j in range(len(s)):
		if s[j] == '1':
			for k in range(j + 1, len(s)):
				if s[k] == '1':
					c = c + (k - j - 1)
					j = k
					break
		else:
			continue
	print(c)


import sys
x = int(input())
for i in range(x):
	str = input()
	index = str.find('1')
	sum = 0
	tmp = 0
	for j in range(index + 1, len(str)):
		if str[j] == '0':
			tmp += 1
		else:
			sum += tmp
			tmp = 0
	print(sum)


import sys
input = sys.stdin.readline
import math
for _ in range(int(input())):
	s = input()
	a = len(s)
	t = True
	l = 0
	ans = 0
	for i in range(a - 1):
		if s[-(i + 1)] == '1':
			l = a - i - 1
			break
	for i in range(a):
		if s[i] == '1':
			k = i
			for j in range(k, l + 1):
				if s[j] == '0':
					ans += 1
			break
	print(ans)


T = int(input())
for _ in range(T):
	a = input()
	pre = False
	era = 0
	ans = 0
	for i in a:
		if i == '1' and pre == False:
			pre = True
		elif i == '0' and pre == True:
			era += 1
		elif i == '1' and pre == True:
			ans += era
			era = 0
	print(ans)


n = int(input())
for i in range(n):
	s = input()
	c = 0
	for j in range(len(s)):
		if s[j] == '0':
			c += 1
	j1 = 0
	while j1 < len(s) and s[j1] == '0':
		c -= 1
		j1 += 1
	j2 = len(s) - 1
	while j2 > -1 and s[j2] == '0':
		c -= 1
		j2 -= 1
	if j2 == -1:
		print(0)
	else:
		print(c)


t = int(input())
for i in range(t):
	s = input()
	if len(s) == 1:
		print(0)
	elif len(s) == 2:
		print(0)
	else:
		c = 0
		prev_ind = s.find('1')
		i = prev_ind + 1
		p = s.find('0')
		if prev_ind == -1:
			print(0)
		else:
			while i < len(s):
				if s[i] == '1':
					c = c + (i - prev_ind - 1)
					prev_ind = i
				i = i + 1
			print(c)


for _ in range(int(input())):
	s = input()
	ans = 0
	c = 0
	n = len(s)
	f = 0
	for i in range(n):
		if s[i] == '0':
			c += 1
		else:
			if f == 1:
				ans += c
			c = 0
			f = 1
	print(ans)


for _ in range(int(input())):
	s = input()
	i = 0
	while i < len(s):
		if s[i] == '1':
			break
		i += 1
	a = []
	while i <= len(s) - 1:
		if s[i] == '0':
			a.append(i)
		i += 1
	k = len(s) - 1
	i = len(a) - 1
	cn = 0
	while i >= 0:
		if a[i] != k:
			break
		cn += 1
		k -= 1
		i -= 1
		a.pop()
	print(len(a))


for _ in range(int(input())):
	s = input()
	cnt = s.count('1')
	if cnt > 0:
		cnt = s.rfind('1') - s.find('1') + 1 - cnt
	print(cnt)


try:
	t = int(input())
	for i in range(t):
		s = input()
		b = 0
		e = 0
		for i in range(len(s)):
			if s[i] == '1':
				b = i
				break
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '1':
				e = i
				break
		if b != e:
			l = s[b:e + 1].count('0')
			print(l)
		else:
			print(b - e)
except EOFError as e:
	pass


t1 = int(input())
for _ in range(t1):
	a = str(input())
	p = 0
	if set(a) == {'0'} or set('a') == {1}:
		print(0)
	else:
		for i in a:
			if i == '0':
				p += 1
			else:
				break
		a = a[::-1]
		for i in a:
			if i == '0':
				p += 1
			else:
				break
		print(a.count('0') - p)


n = int(input())
for i in range(n):
	str = input()
	count = 0
	for i in range(len(str) - 1):
		if str[i] == '1' and str[i + 1] == '0':
			if '1' in str[i + 2:]:
				j = str[i + 2:].find('1')
				i = i + j + 2
				count += j + 1
	print(count)


N = int(input())
S = [0] * N
for i in range(N):
	S[i] = input()
for i in range(N):
	flag = False
	flag2 = False
	count = 0
	for j in range(len(S[i])):
		if j != len(S[i]) - 1:
			if flag == False and S[i][j] == '1':
				flag = True
				flag2 = True
			elif flag == True and S[i][j] == '0' and (S[i][j + 1] != '1'):
				count += 1
			elif flag == True and S[i][j] == '0' and (S[i][j + 1] == '1'):
				count += 1
				flag = False
		elif flag == True and S[i][j] == '0':
			count += 1
	if S[i][-1] == '0' and flag2 == True:
		k = -2
		count -= 1
		while True:
			if S[i][k] == '0':
				count -= 1
				k -= 1
			else:
				break
	print(count)


output = []

def f(string):
	string_length = len(string)
	(left_border, right_border) = (-1, -1)
	for i in range(string_length):
		if left_border == -1 and string[i] == '1':
			left_border = i
		tmp = string_length - 1 - i
		if right_border == -1 and string[tmp] == '1':
			right_border = tmp
	output.append(string.count('0', left_border, right_border + 1))
for i in range(int(input())):
	f(input())
print(*output, sep='\n')


import sys

def main():
	n = int(input())
	op = ''
	for i in range(0, n):
		ip = input().strip('0')
		o_count = 0
		for char in ip:
			if char == '0':
				o_count += 1
		op += str(o_count) + '\n'
	print(op)
main()


def erz(l):
	if len(l) == 1 or len(l) == 2:
		print(0)
		return
	elif l.count(1) == 0 or l.count(0) == 0:
		print(0)
		return
	s = l.index(1)
	e = len(l) - l[::-1].index(1) - 1
	c = 0
	for i in range(s, e):
		if l[i] == 0:
			c = c + 1
	print(c)
	return
n = int(input())
for i in range(n):
	t = input()
	l = list(map(int, t))
	erz(l)


import collections, heapq

def main():
	T = int(input().strip())
	for _ in range(T):
		s = input().strip('0')
		print(s.count('0'))
main()


n = int(input())
Result_list = []
for i in range(0, n):
	num_of_one = 0
	take_index = []
	take_str = input()
	for j in range(0, len(take_str)):
		if take_str[j] is '1':
			num_of_one += 1
			take_index.append(j)
	if len(take_index) > 0:
		take_index.sort()
		diff = take_index[len(take_index) - 1] - take_index[0]
		to_remove = diff + 1 - num_of_one
	else:
		to_remove = 0
	Result_list.append(to_remove)
for i in range(0, n):
	take = Result_list[i]
	print(take)


num = int(input())
strings = {}
for i in range(num):
	curr_str = str(input())
	both_removed = curr_str.strip('0')
	curr_str = str(both_removed)
	strings[curr_str] = 0
	count = 0
	for c in curr_str:
		if c == '0':
			count += 1
		strings[curr_str] = count
	print(count)


t = int(input())
for i in range(t):
	s = list(str(input().rstrip()))
	l = 0
	flag = False
	for i in range(len(s)):
		if s[i] == '1':
			l = i
			flag = True
			break
	r = len(s) - 1
	for i in reversed(range(len(s))):
		if s[i] == '1':
			r = i
			break
	ans = 0
	for i in range(l, r + 1):
		if s[i] == '0':
			ans += 1
	cnt_0 = 0
	for i in s:
		if i == '0':
			cnt_0 += 1
	if cnt_0 == len(s):
		print(0)
	else:
		print(ans)


repeat = int(input())
for i in range(repeat):
	ppi = input()
	ppi = list(ppi)
	if ppi[0] == '0' and len(ppi) == 1:
		print(0)
	else:
		err = True
		while ppi[0] == '0':
			if ppi[0] == '0' and len(ppi) == 1:
				err = False
				break
			ppi.pop(0)
		while ppi[len(ppi) - 1] == '0':
			if ppi[0] == '0' and len(ppi) == 1:
				err = False
				break
			ppi.pop()
		if err == True:
			print(ppi.count('0'))
		else:
			print(0)


def reverse(s):
	if len(s) == 0:
		return s
	else:
		return reverse(s[1:]) + s[0]
for i in range(int(input())):
	s = input()
	c2 = 0
	if len(s) == 1:
		print(0)
		continue
	for i in range(len(s)):
		if int(s[i]) == 0:
			c2 = c2 + 1
	if c2 == len(s):
		print(0)
		continue
	p = reverse(s)
	c = 0
	c1 = 0
	count = 0
	for i in range(len(s)):
		if int(s[i]) == 1:
			c = i
			break
	for i in range(len(p)):
		if int(p[i]) == 1:
			c1 = i
			break
	s1 = s[c:len(s) - c1]
	for i in range(len(s1)):
		if int(s1[i]) == 0:
			count = count + 1
	print(count)


n = int(input())
for _ in range(n):
	a = input()
	for i in range(len(a)):
		if a[i] == '1':
			break
	for j in range(len(a) - 1, -1, -1):
		if a[j] == '1':
			break
	k = 0
	for v in a[i:j]:
		if v == '0':
			k += 1
	print(k)


t = int(input())
for i in range(t):
	s = list(input())
	count = 0
	n1 = 0
	debut = 0
	for j in range(len(s)):
		if s[j] == '1':
			n1 = n1 + 1
	x = 0
	for k in range(len(s)):
		if s[k] == '1':
			count = count + 1
			debut = 1
		elif debut == 1 and count < n1:
			x = x + 1
	print(x)


n = int(input())
for j in range(n):
	s = input()
	a = 0
	b = 0
	p = 0
	for i in range(len(s)):
		if s[i] == '1':
			a = 1
		if a == 1 and s[i] == '0':
			b = b + 1
		if a == 1 and s[i] == '1':
			p = p + b
			b = 0
	print(p)


results = []
for s in range(int(input())):
	selectednum = input()
	low = 0
	high = 0
	for i in range(0, len(selectednum)):
		if selectednum[i] == '1':
			low = i
			break
	for x in range(len(selectednum) - 1, -1, -1):
		if selectednum[x] == '1':
			high = x
			break
	new = selectednum[low:high]
	count = 0
	if '1' in new:
		for c in new:
			if c == '0':
				count += 1
	else:
		count = 0
	results.append(count)
for v in results:
	print(v)


t = int(input())
for _ in range(t):
	s = input()
	i = 0
	n = len(s)
	for i in range(n):
		if s[i] == '1':
			break
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			break
	if i >= j:
		print(0)
	else:
		ans = 0
		for k in range(i, j + 1):
			if s[k] == '0':
				ans += 1
		print(ans)


n = int(input())
for _ in range(n):
	s = input().lstrip('0')
	prev_index = 0
	result = 0
	for i in range(1, len(s)):
		if s[i] == '1':
			current_index = i
			result += current_index - prev_index - 1
			prev_index = current_index
	print(result)


inputs = list(map(lambda x: input(), range(int(input()))))
for input in inputs:
	count = 0
	for i in range(input.find('1'), input.rfind('1')):
		if input[i] == '0':
			count += 1
	print(count)


for i in range(int(input())):
	s = input()
	s = s.strip('0')
	n = 0
	for j in s:
		if j == '0':
			n += 1
	print(n)


for _ in range(int(input())):
	s = input()
	l = -1
	x = 0
	for i in range(len(s)):
		if s[i] == '1':
			if l != -1:
				x += i - l - 1
			l = i
	print(x)


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	X = input().rstrip()
	if '1' not in X:
		print(0)
	else:
		print(len(X) - X[::-1].find('1') - X.find('1') - X.count('1'))


t = int(input())
while t:
	t -= 1
	n = input().strip('0')
	print(n.count('0'))


t = int(input())
for i in range(t):
	string = input()
	count = 0
	answer = 0
	flag = 0
	for j in string:
		if j == '0' and flag == 1:
			count += 1
		elif j == '1' and flag == 1:
			answer += count
			count = 0
		elif j == '1' and flag == 0:
			flag = 1
	print(answer)


tests = int(input())
cases = []
for i in range(tests):
	temp = input()
	cases.append(temp)
for j in range(len(cases)):
	first1 = False
	stack = []
	length = 0
	for k in range(len(cases[j])):
		if cases[j][k] == '1':
			first1 = True
		if first1 and cases[j][k] == '0':
			stack.append('0')
		if first1 and cases[j][k] == '1' and (len(stack) > 0):
			length += len(stack)
			stack = []
	print(length)


def calculate(string):
	flag = False
	totalCount = 0
	thisCount = 0
	for bit in string:
		if bit == '0' and flag:
			thisCount += 1
		elif bit == '1' and (not flag):
			flag = True
		elif bit == '1' and flag:
			totalCount += thisCount
			thisCount = 0
	return totalCount

def main():
	numberOfTest = input()
	arr = []
	for i in range(int(numberOfTest)):
		string = input()
		sol = calculate(string)
		arr.append(sol)
	for sol in arr:
		print(sol)
main()


T = int(input().strip())
for t in range(T):
	S = str(input().strip())
	firstOne = -1
	lastOne = -1
	sumOnes = 0
	idx = 0
	for c in S:
		if c == '1':
			if firstOne == -1:
				firstOne = idx
				lastOne = idx
			else:
				lastOne = idx
			sumOnes += 1
		idx += 1
	if sumOnes > 0 and lastOne - firstOne != sumOnes - 1:
		print(lastOne - firstOne - (sumOnes - 1))
	else:
		print(0)


import sys
import collections
input = sys.stdin.readline

def printnl(val):
	sys.stdout.write(str(val) + '\n')

def solve(s):
	(first, last) = (-1, -1)
	ans = 0
	n = len(s)
	for i in range(n):
		if s[i] == '1':
			ans += 1
			if first == -1:
				first = i
				last = i
			else:
				last = i
	if last > first:
		return last - first + 1 - ans
	else:
		return 0
T = int(input())
while T:
	s = input()
	print(solve(s))
	T -= 1


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

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

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	t = I()
	rr = []
	for _ in range(t):
		s = S()
		n = len(s)
		si = 0
		for i in range(n):
			si = i
			if s[i] == '1':
				break
		sj = n - 1
		for i in range(n - 1, -1, -1):
			sj = i
			if s[i] == '1':
				break
		r = 0
		for i in range(si + 1, sj):
			if s[i] == '0':
				r += 1
		rr.append(r)
	return JA(rr, '\n')
print(main())


n = int(input())

def count_zero(str_input):
	if str_input == 0:
		return 0
	elif '1' in str_input:
		right = str_input[str_input.index('1') + 1:]
		return str_input.index('1') + count_zero(right)
	else:
		return 0

def pre_input(str_org):
	if str_org.count('1') <= 1:
		return 0
	else:
		need_idx = str_org.index('1')
		return str_org[need_idx:]
for i in range(n):
	print(count_zero(pre_input(input())))


t = int(input())
for i in range(0, t):
	s = input()
	z = 0
	flag = 0
	for j in range(0, len(s)):
		if s[j] == '1':
			p = j
			flag = 1
			break
	if flag == 1:
		for k in range(len(s) - 1, p - 1, -1):
			if s[k] == '1':
				l = k
				break
		if l == p:
			print('0')
		else:
			for n in range(l, p, -1):
				if s[n] == '0':
					z = z + 1
			print(z)
	else:
		print('0')


t = int(input())
while t:
	t -= 1
	s = input()
	s = s.rstrip('0')
	s = s[-1::-1]
	s = s.rstrip('0')
	s = s[-1::-1]
	c = 0
	l = len(s)
	print(s.count('0'))


t = int(input())
for x in range(0, t):
	str1 = input()
	fst = str1.find('1')
	lst = str1.rfind('1')
	str2 = str1[fst:lst + 1]
	ats = str2.count('0')
	print(ats)


for _ in range(int(input())):
	s = list(input())
	a = 0
	for i in range(len(s)):
		if s[i] == '1':
			for j in range(i + 1, len(s)):
				if s[j] == '1':
					a += j - i - 1
					break
	print(a)


for t in range(int(input())):
	n = input()
	l = len(n)
	total = 0
	fi = 0
	for i in range(0, l):
		if n[i] == '1':
			fi = i
			break
	li = n.rfind('1')
	if li != -1:
		for x in range(fi, li):
			if n[x] == '0':
				total += 1
	print(total)


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


t = int(input())
while t:
	t -= 1
	s = input()
	if '1' not in s or '0' not in s:
		print(0)
		continue
	else:
		fi = -1
		n = 0
		for i in range(len(s)):
			if s[i] == '1' and fi == -1 and (i != len(s) - 1) and (s[i + 1] == '0'):
				fi = i
			elif s[i] == '1' and fi != -1:
				n += i - fi - 1
				fi = i
	print(n)


t = int(input())
for i in range(t):
	s = input()
	s = list(s)
	if len(s) == 1 or len(s) == s.count('0'):
		print(0)
	else:
		while s[0] == '0' or s[-1] == '0':
			if s[0] == '0':
				s.pop(0)
			if s[-1] == '0':
				s.pop(-1)
		c = 0
		for i in s:
			if i == '0':
				c += 1
		print(c)


n = int(input())
for i in range(n):
	s = input()
	if int(s) == 0:
		print(0)
	else:
		number_of_1s = 0
		for i in range(len(s)):
			if s[i] == '1':
				number_of_1s += 1
		index = 0
		while s[index] != '1':
			index += 1
		zeros_to_omete = 0
		ones_passed = 0
		while index < len(s) and ones_passed < number_of_1s:
			if s[index] == '0':
				zeros_to_omete += 1
			else:
				ones_passed += 1
			index += 1
		print(zeros_to_omete)


n = int(input())
k = 0
o = 0
l = ''
g = 0
for i in range(n):
	a = input()
	k = a.count('1')
	for j in range(len(a)):
		if a[j] == '1':
			o = o + 1
		if o > 0 and a[j] == '0' and (o != k):
			g = g + 1
		if o == k:
			break
	print(g)
	o = 0
	g = 0


t = int(input())
for i in range(t):
	s = input()
	n = len(s)
	st = 0
	k = 0
	for j in range(n):
		if s[j] == '1':
			st = j
			break
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			k = n - j - 1
			break
	m = len(''.join(s.split('0')))
	if m == 0:
		print(0)
	else:
		print(n - m - k - st)


for t in range(int(input())):
	s = input()
	l = len(s)
	tot = 0
	sta = 0
	stp = 0
	for i in range(l):
		if s[i] == '1':
			sta = i
			break
	for i in range(l - 1, -1, -1):
		if s[i] == '1':
			stp = i
			break
	if sta == stp:
		print(0)
		continue
	for i in range(sta, stp + 1, 1):
		if s[i] == '0':
			tot += 1
	print(tot)


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	ones = s.count('1')
	if ones <= 1:
		print(0)
	else:
		first = 0
		last = 0
		for i in range(n):
			if s[i] == '1':
				first = i
				break
		for j in range(n - 1, -1, -1):
			if s[j] == '1':
				last = j
				break
		zeroes = 0
		for k in range(first, last):
			if s[k] == '0':
				zeroes += 1
		print(zeroes)


numbertest = int(input())
for i in range(0, numbertest):
	list = []
	word = input()
	if len(word) > 1:
		for x in range(0, len(word)):
			if word[x] == '1':
				list.append(x)
		if len(list) > 1:
			print(int(list[-1]) - int(list[0]) + 1 - len(list))
		if len(list) <= 1:
			print('0')
	if len(word) == 1:
		print('0')


a = int(input())
for i in range(a):
	d = 0
	c = input()
	for i in range(len(c)):
		if c[i] == '0':
			d += 1
		else:
			break
	for i in range(len(c[::-1])):
		if c[::-1][i] == '0':
			d += 1
		else:
			break
	e = c.count('1')
	print(max(len(c) - d - e, 0))


T = int(input())
for _ in range(0, T):
	s = input()
	ptr1 = 0
	for i in range(0, len(s)):
		if s[i] == '1':
			ptr1 = i
			break
	ptr2 = 0
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			ptr2 = i
			break
	if s.count('1') < 2:
		print(0)
	else:
		c = 0
		for i in range(ptr1, ptr2 + 1):
			if s[i] == '0':
				c += 1
		print(c)


kl = int(input())
for l in range(kl):
	s = str(input())
	pr = 1
	k = s.find('1')
	if k == -1:
		print(0)
		pr = 0
	else:
		s = s[k:]
	rz = 0
	while k != -1:
		r = s.find('0')
		if r == -1:
			break
		s = s[r:]
		k = s.find('1')
		if k == -1:
			break
		rz += k
		s = s[k:]
	if pr:
		print(rz)


t = int(input())
for i in range(t):
	s = input()
	m = 0
	for j in range(len(s)):
		if s[j] == '0' and s.find('1', 0, j) > -1 and (s.find('1', j + 1, len(s)) > -1):
			m += 1
	print(m)


import sys
q = int(input())
for _ in range(q):
	s = input()
	started = False
	result = 0
	first = -1
	for i in range(len(s)):
		if first == -1 and s[i] == '1':
			first = i
			break
	last = -1
	for i in range(len(s)):
		if s[i] == '1':
			last = i
	for i in range(len(s)):
		if i > first and i < last and (s[i] == '0'):
			result += 1
	print(result)


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *

def main():
	ntest = int(stdin.readline())
	for test in range(ntest):
		n = stdin.readline().strip()
		res = 0
		k = -1
		for (ind, d) in enumerate(n):
			if d == '1':
				if k >= 0:
					res += ind - k - 1
				k = ind
		stdout.write('%d\n' % res)
	return 0
main()


import sys
inp = sys.stdin.readline
input = lambda : inp().strip()
flush = sys.stdout.flush

def iin():
	return int(input())

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

def main():
	t = iin()
	while t:
		t -= 1
		a = map(int, list(input()))
		ans = 0
		ch1 = 0
		ch = 0
		for i in a:
			if i == 1:
				ch1 = 1
				ans = ch
			elif ch1:
				ch += 1
		print(ans)
main()


def erase0(str):
	mc = 0
	cc = 0
	mode = 'OFF'
	for (i, l) in enumerate(str):
		if mode == 'ON' and l == '0':
			cc += 1
		elif l == '1' and mode == 'OFF':
			mode = 'ON'
		elif l == '1' and mode == 'ON' and (str[i - 1] == '0'):
			mc += cc
			cc = 0
	print(mc)
n = int(input())
for i in range(n):
	str = input()
	erase0(str)


for _ in range(int(input())):
	s = input()
	if '1' not in s:
		print(0)
	else:
		print(s.rindex('1') - s.index('1') - s.count('1') + 1)


t = int(input())
while t != 0:
	l = list(input())
	i = 0
	c = 0
	flag = 0
	while i < len(l):
		j = i + 1
		if l[i] == '1':
			while j < len(l):
				if l[j] == '1':
					flag = 1
					break
				j = j + 1
		if flag == 1:
			c = c + abs(j - i) - 1
			flag = 0
		i = j
	print(c)
	t = t - 1


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


def remover(l, idx1, idx2, count):
	for i in range(idx1, idx2):
		if l[i] == '0':
			count += 1
	return count

def finder(l):
	temp = []
	for i in range(len(l)):
		if l[i] == '1':
			temp.append(i)
	return temp
for _ in range(int(input())):
	s = input()
	l = list(s)
	c = 0
	t = finder(l)
	for i in range(1, len(t)):
		c = remover(l, t[i - 1], t[i], c)
	print(c)


t = int(input())
for _ in range(t):
	s = input()
	flag = False
	(count, r, x) = (0, 0, 0)
	for i in range(len(s) - 1):
		if s[i] == '0' and s[i + 1] == '0':
			if flag:
				x += 1
		if s[i] == '1' and s[i + 1] == '0':
			flag = True
			x = 0
		if s[i] == '0' and s[i + 1] == '1':
			if flag:
				x += 1
			count += x
			flag = False
	print(count)


for _ in range(int(input())):
	s = input()
	(pos1, pos2, cnt) = (0, 0, 0)
	for i in range(len(s)):
		if s[i] == '1':
			pos1 = i
			break
	for i in range(len(s) - 1, pos1, -1):
		if s[i] == '1':
			pos2 = i
			break
	for i in range(pos1, pos2):
		if s[i] == '0':
			cnt += 1
		else:
			continue
	print(cnt)


t = int(input())
for i in range(t):
	line = input()
	soma = 0
	for j in line:
		if j == '1':
			soma += 1
	count = 0
	delete = 0
	for j in range(len(line)):
		if line[j] == '0' and count != 0:
			delete += 1
		elif line[j] == '1':
			count += 1
		if count == soma:
			print(delete)
			break


n = int(input())
for i in range(n):
	s = input()
	count = 0
	temp = 0
	flag = 0
	for j in range(len(s)):
		if s[j] == '1':
			flag = 1
			temp = temp + count
			count = 0
		elif flag == 1:
			count = count + 1
	print(temp)


for i in range(int(input())):
	s = input()
	s = list(s)
	ct = s.count('1')
	j = 0
	k = 0
	for i in range(len(s)):
		if s[i] == '1':
			j = i
			break
	for i in range(len(s) - 1, 0, -1):
		if s[i] == '1':
			k = i
			break
	if s.count('0') == len(s):
		print('0')
	else:
		print(k - j + 1 - ct)


t = int(input())
for _ in range(t):
	s = input()
	j = 0
	for (j, i) in enumerate(s):
		if i == '0':
			continue
		else:
			break
	s = s[j:]
	k = len(s)
	for k in range(len(s) - 1, -1, -1):
		if s[k] == '0':
			continue
		else:
			k = k + 1
			break
	s = s[:k]
	ans = 0
	i = 0
	while i < len(s):
		if s[i] == '1':
			i += 1
			continue
		temp = 1
		for j in range(i + 1, len(s)):
			if s[j] == '0':
				temp += 1
				continue
			else:
				i = j
				ans = ans + temp
				break
	print(ans)


for i in range(int(input())):
	string = input()
	left = string.find('1')
	right = string.rfind('1')
	if left == -1 or right == -1:
		print(0)
		continue
	string = string[left:right + 1]
	print(len(string) - string.count('1'))


t = int(input())
for _ in range(t):
	s = str(input())
	n = len(s)
	c = 0
	strt = end = n
	for i in range(n):
		if s[i] == '1':
			strt = i
			break
	for i in range(-1, -n - 1, -1):
		if s[i] == '1':
			end = n + i
			break
	for i in range(strt, end):
		if s[i] == '0':
			c += 1
	print(c)


for _ in range(int(input())):
	s = input()
	l = 0
	while l < len(s) and s[l] == '0':
		l += 1
	r = len(s)
	while r > l and s[r - 1] == '0':
		r -= 1
	print(r - l - s.count('1'))


t = int(input())
while t:
	s = input()
	s1 = s[::-1]
	i = -1
	k = 0
	for j in range(len(s)):
		if s[j] == '1':
			i = j
			break
	for j in range(len(s1)):
		if s1[j] == '1':
			k = j
			break
	if i == -1:
		print(0)
	else:
		c = 0
		for j in range(i + 1, len(s) - k):
			if int(s[j]) - 1 != 0:
				c += 1
		print(c)
	t -= 1


t = int(input())
for i in range(t):
	s = input()
	q = s[::-1]
	if '1' not in s or '0' not in s:
		print(0)
	else:
		s = s[s.index('1'):len(s) - q.index('1')]
		print(s.count('0'))


for i in range(int(input())):
	a = input()
	b = []
	c = 0
	for i in range(len(a)):
		if a[i] == '0' and a[:i].count('1') > 0 and (a[i + 1:].count('1') > 0):
			c += 1
	print(c)


T = int(input())
for i in range(T):
	save = 0
	count = 0
	str = input().strip('0')
	a = list(str)
	for i in range(1, len(a)):
		if a[i] == '1':
			save = i
	if save == 0:
		count = 0
	else:
		for i in range(1, save + 1):
			if a[i] == '0':
				count += 1
	print(count)


t = int(input())
for i in range(t):
	a = input()
	reva = a[::-1]
	le = len(a)
	f1 = -1
	f2 = -1
	res = 0
	for i in range(le):
		if a[i] == '1':
			f1 = i
			break
	for j in range(le):
		if reva[j] == '1':
			f2 = le - j - 1
			break
	for k in range(f1, f2 + 1):
		if a[k] == '0':
			res += 1
	if f1 == -1:
		print('0')
	else:
		print(res)


from collections import Counter
from collections import defaultdict
import math
t = int(input())
for i in range(0, t):
	a = input()
	a = list(a)
	k = -1
	g = -1
	for i in range(0, len(a)):
		if a[i] == '1':
			k = i
			break
	for i in range(k, len(a)):
		if a[i] == '1':
			g = i
	c = 0
	if k == -1 and g == -1:
		print(0)
		continue
	for i in range(k, g + 1):
		if a[i] == '0':
			c = c + 1
	print(c)


import sys
readline = sys.stdin.readline
T = int(readline())
Ans = [None] * T
for qu in range(T):
	s = readline().strip()
	Ans[qu] = s.strip('0').count('0')
print('\n'.join(map(str, Ans)))


import sys
t = int(sys.stdin.readline())
for i in range(t):
	s = sys.stdin.readline().strip()
	count = 0
	for i in range(len(s)):
		if s[i] == '1':
			count += 1
	if count <= 1:
		print(0)
	else:
		f = s.find('1')
		l = s.rfind('1')
		ans = 0
		for i in range(f + 1, l):
			if s[i] == '0':
				ans += 1
		print(ans)


for _ in range(int(input())):
	s = input()
	z = 0
	while z < len(s):
		if s[z] == '0':
			z += 1
		else:
			break
	pc = 0
	tc = 0
	while z < len(s):
		if s[z] == '1' and tc != 0:
			z += 1
			pc += tc
			tc = 0
		elif s[z] == '1':
			z += 1
		else:
			tc += 1
			z += 1
	print(pc)


def getSeq(n):
	tCount = 0
	count = 0
	start = False
	for i in n:
		if i == '1' and (not start):
			start = True
		elif i == '1' and count > 0:
			tCount += count
			count = 0
		if i == '0' and start:
			count += 1
	return tCount
T = int(input())
for i in range(T):
	print(getSeq(input()))


t = int(input())
for i in range(0, t):
	n = input()
	j = 0
	fp = 0
	while j < len(n):
		if n[j] == '1':
			fp = j
			break
		j += 1
	j = len(n)
	j = j - 1
	lp = 0
	while j >= 0:
		if n[j] == '1':
			lp = j
			break
		j -= 1
	nd = 0
	for j in range(fp + 1, lp):
		if n[j] == '0':
			nd += 1
	print(nd)


for i in range(int(input())):
	s = input()
	start = s.find('1')
	end = s.rfind('1')
	print(s[start:end].count('0'))


t = int(input())
for i in range(t):
	s = input()
	imax = 0
	imin = 99999
	for i in range(len(s)):
		if s[i] == '1':
			imax = max(imax, i)
			imin = min(imin, i)
	if imin == 99999:
		imin = 0
	print(s[imin:imax].count('0'))


for _ in range(int(input())):
	s = input()
	ini = 108
	f = -1
	c1 = s.count('1')
	n = len(s)
	for i in range(n):
		if s[i] == '1':
			ini = min(ini, i)
			f = max(f, i)
	ans = 0
	ans = f - ini + 1 - c1
	if ini == 108:
		ans = 0
	print(ans)


n = int(input())
for j in range(n):
	s = input()
	f = False
	count = 0
	l = 0
	for i in s:
		if i == '1' and f == True:
			count = count + l
			l = 0
		elif f == True:
			l += 1
		elif i == '1':
			f = True
	print(count)


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	x = -1
	y = n
	c = 0
	for i in range(n):
		if s[i] == '1':
			x = i
			break
	for i in range(n - 1, x - 1, -1):
		if s[i] == '1':
			y = i
			break
	if x != -1 and y != n:
		for i in range(x + 1, y):
			if s[i] == '0':
				c += 1
	print(c)


import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
from functools import lru_cache
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	a = input().strip()
	res = 0
	flag = False
	n = len(a)
	st = 0
	end = n - 1
	for i in range(n):
		if a[i] == '1':
			st = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] == '1':
			end = i
			break
	if a.count('1') == 0:
		print(0)
		continue
	print(end - st + 1 - a.count('1'))


t = int(input())
x = []
for _ in range(t):
	count = 0
	a = input()
	if len(a) <= 1 or a.count('1') == 0:
		x.append(count)
		continue
	j = a.index('1')
	k = len(a) - a[::-1].index('1')
	for i in range(j, k):
		if a[i] != a[j]:
			count += 1
	x.append(count)
for i in x:
	print(i)


print(*[input().strip('0').count('0') for _ in range(int(input()))], sep='\n')


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
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))
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 graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

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

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

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

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

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

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

def bs(a, l, h, x):
	while l < h:
		mid = (l + h) // 2
		if a[mid] == x:
			return mid
		if a[mid] < x:
			l = mid + 1
		else:
			h = mid
	return l

def sieve(a):
	for i in range(3, 10 ** 6 + 1, 2):
		a[i] = 1
	for i in range(3, 10 ** 6 + 1, 2):
		for j in range(i * i, 10 ** 6 + 1, i):
			a[j] = 0
	a[2] = 1
	return a

def solve():
	s = list(inp())
	n = len(s)
	cnt = 0
	for i in range(0, n):
		if s[i] == '1':
			cnt += 1
	if cnt == 0:
		print(0)
		return
	ans = 0
	ind = s.index('1') + 1
	count = 1
	while count < cnt:
		if s[ind] == '0':
			ans += 1
		else:
			count += 1
		ind += 1
	print(ans)
testcase(int(inp()))


def f(s):
	while len(s) > 0 and s[0] == '0':
		s = s[1:]
	while len(s) > 0 and s[-1] == '0':
		s = s[:-1]
	return len([char for char in s if char == '0'])
numberofcases = int(input())
for _ in range(numberofcases):
	print(f(input()))


n = int(input())
for i in range(n):
	a = input()
	if a.count('0') == len(a):
		print(0)
	elif a.count('1') == len(a):
		print(0)
	else:
		l = []
		for i in range(0, len(a)):
			if a[i] == '1':
				l.append(i)
		print(a[l[0]:l[-1]].count('0'))


test = int(input())
while test != 0:
	str1 = input()
	inp_str = list(str1)
	(count1, index) = (0, 0)
	for j in range(len(str1)):
		if inp_str[j] == '1':
			index = j
			break
		else:
			count1 += 1
	if count1 == len(str1):
		print(0)
	else:
		count2 = 0
		summ = 0
		if index == len(str1) - 1:
			print(0)
		else:
			for i in range(j + 1, len(str1)):
				if inp_str[i] == '0':
					count2 += 1
				elif inp_str[i] == '1':
					summ += count2
					count2 = 0
			print(summ)
	test -= 1


def main():
	t = int(input())
	while t > 0:
		prev = -1
		ans = 0
		s = input()
		for i in range(len(s)):
			c = s[i]
			if c == '1':
				if prev == -1:
					prev = i
				else:
					ans += i - prev - 1
					prev = i
		print(ans)
		t -= 1
main()


t = int(input())
s = []
for jnjn in range(0, t):
	x = input()
	n = len(x)
	f1 = 0
	f2 = 0
	for i in range(0, n):
		if x[i] == '1':
			f1 = i
			break
	for i in range(n - 1, -1, -1):
		if x[i] == '1':
			f2 = i
			break
	g = 0
	for i in range(f1, f2):
		if x[i] == '0':
			g += 1
	s.append(g)
for i in s:
	print(i)


t = int(input())
for j in range(t):
	s = input()
	i = 0
	while s[i] == '0':
		i += 1
		if i == len(s):
			break
	if i == len(s):
		print(0)
		continue
	else:
		prev = False
		strike = 0
		gaps = []
		prev = False
		while i < len(s):
			if s[i] == '1':
				if prev:
					gaps.append(strike)
					strike = 0
				prev = False
			else:
				if prev:
					strike += 1
				else:
					strike = 1
				prev = True
			i += 1
		if len(gaps) == 0:
			print(0)
		else:
			print(sum(gaps))


t = int(input())
for r in range(t):
	s = input()
	if s.count('1') >= 2:
		in1 = s.index('1')
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '1':
				in2 = i
				break
		if in1 != in2:
			print(s[in1 + 1:in2].count('0'))
	else:
		print('0')


def res(ch):
	sum1 = 0
	if ch.find('1') != -1 and ch.find('0') != -1:
		m = [i for i in range(len(ch)) if ch[i] == '1']
		for k in range(len(m) - 1, 0, -1):
			sum1 += m[k] - m[k - 1] - 1
	return sum1
	return sum1
n = int(input())
L = list()
for i in range(n):
	ch = input()
	L.append(res(ch))
for i in range(len(L)):
	print(L[i])


from math import *
from collections import *
from operator import itemgetter
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
t = ii()
for _ in range(t):
	s = input()
	n = len(s)
	c = 0
	d = []
	(prev, cur) = (-1, -1)
	for i in range(n):
		if s[i] == '1':
			d.append(i)
	for i in range(1, len(d)):
		c += d[i] - d[i - 1] - 1
	print(c)


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


def remove(string):
	c = 0
	for i in range(len(string) - 1):
		if string[i] == '1':
			temp = 0
			j = i + 1
			while string[j] == '0' and j < len(string) - 1:
				temp += 1
				j += 1
			if string[j] == '1':
				c += temp
	return c
t = int(input())
for i in range(t):
	st = input()
	print(remove(st))


n = int(input())
for i in range(n):
	string = input()
	seen = False
	answer = 0
	holder = 0
	for j in range(len(string)):
		if string[j] == '0' and seen:
			holder += 1
		elif string[j] == '1' and seen:
			answer += holder
			holder = 0
		elif string[j] == '1' and (not seen):
			seen = True
	print(answer)


from copy import copy

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

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

def int_inp():
	return int(input())

def float_inp():
	return float(input())

def comp(a):
	return a[0]

def gcd(a, b):
	if b != 0:
		return gcd(b, a % b)
	else:
		return a
for _ in range(int_inp()):
	was_one = False
	out = 0
	buf_out = 0
	for ch in input():
		if ch == '0':
			if was_one:
				buf_out += 1
		elif was_one:
			out += buf_out
			buf_out = 0
		else:
			was_one = True
			buf_out = 0
	print(out)


import math
n = int(input())
for i in range(n):
	s = input()
	one_met = False
	zeroes = 0
	count = 0
	for ch in s:
		if one_met:
			if ch == '1':
				count += zeroes
				zeroes = 0
			else:
				zeroes += 1
		if ch == '1':
			one_met = True
	print(count)


def erase_zeroes(input_list):
	try:
		for each_input in input_list:
			print(each_input.strip('0').count('0'))
	except Exception as e:
		print(str(e))
input_list = []
no_of_inputs = int(input())
for i in range(0, no_of_inputs):
	input_list.append(input())
erase_zeroes(input_list)


t = int(input())
for _ in range(t):
	a = input()
	arr = []
	u = 0
	for i in range(len(a)):
		if a[i] == '1':
			arr.append(i)
	if len(arr) > 0:
		u = max(arr) - min(arr) + 1
	print(u - len(arr))


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


t = int(input())
for _ in range(t):
	s = input()
	p = 0
	if '1' in s:
		for i in range(s.index('1'), len(s) - 1):
			if s[i] == '0' and '1' in s[i + 1:]:
				p += 1
	print(p)


def erasing(strs):
	strs = [int(i) for i in strs]
	index = 0
	erase = 0
	visit = set()
	for i in range(len(strs)):
		if i not in visit:
			if strs[i] == 1:
				index = i
				while index <= len(strs) - 1 and strs[index] == 1:
					visit.add(index)
					index += 1
				oneStop = index
				if index == len(strs):
					return erase
				while index <= len(strs) - 1 and strs[index] == 0:
					visit.add(index)
					index += 1
				if index == len(strs):
					return erase
				erase += index - oneStop
	return erase

def main():
	n = eval(input())
	for i in range(n):
		inp = input()
		print(erasing(inp))
main()


def solve():
	t = int(input())
	for i in range(t):
		s = ''.join([s if s == '1' else ' ' for s in input()]).strip()
		print(s.count(' '))
solve()


n = int(input())
for i in range(0, n):
	x = input()
	ar = []
	for j in x:
		ar.append(j)
	s = 0
	for k in range(0, len(ar)):
		if ar[k] == '1':
			r = 0
			for h in range(k + 1, len(ar)):
				if ar[h] == '0':
					r = r + 1
				else:
					s = s + r
					break
	print(s)


t = int(input())
for _ in range(t):
	b = input()
	start = b.find('1')
	binv = b[::-1]
	end = len(b) - binv.find('1') - 1
	count = 0
	if start == -1:
		end = -1
	for i in range(start, end):
		if b[i] == '0':
			count += 1
	print(count)


mod = 10 ** 9 + 7
import math
from bisect import bisect_left
from collections import Counter
from itertools import combinations

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

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

def f(x, y):
	return (x | y) - y
for _ in range(int(input())):
	s = input()
	n = len(s)
	i = 0
	j = n - 1
	c = 0
	while i < n and s[i] != '1':
		i += 1
	while j >= i and s[j] != '1':
		j -= 1
	for x in range(i, j + 1):
		if s[x] == '0':
			c += 1
	print(c)


from collections import defaultdict, Counter, deque
from math import sqrt, log10, log, floor, factorial
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations
import sys, io, os
input = sys.stdin.readline
inf = float('inf')
mod = 10 ** 9 + 7

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

def yn(a):
	print('YES' if a else 'NO')
ceil = lambda a, b: (a + b - 1) // b
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')
t = int(input())
for i in range(t):
	s = input().strip()
	index1 = s.find('1')
	index2 = s.rfind('1')
	print(len([i for i in range(len(s)) if s[i] == '0' and index1 <= i <= index2]))


t = int(input())
for i in range(t):
	s = input()
	if s.count('1') < 2:
		print(0)
	else:
		n = len(s)
		start = s.find('1')
		stop = n - s[::-1].find('1') - 1
		print(s[start:stop].count('0'))


def erasingZeros(s):
	indxs = [i for i in range(len(s)) if s[i] == '1']
	return sum([indxs[x + 1] - indxs[x] - 1 for x in range(len(indxs) - 1)])
n = int(input())
for i in range(n):
	s = input()
	print(erasingZeros(s))


t = int(input())
for l in range(t):
	f = input()
	k = 0
	while f != '' and f[0] == '0':
		f = f[1:]
	while f != '' and f[-1] == '0':
		f = f[:-1]
	for i in range(len(f)):
		if f[i] == '0':
			k += 1
	print(k)


n = int(input())
deletes = []
for i in range(n):
	bi = input()
	prev = bi.find('1') - 1
	delete = 0
	for j in range(len(bi)):
		if bi[j] == '1':
			delete = delete + j - prev - 1
			prev = j
	deletes.append(delete)
for d in deletes:
	print(d)


t = int(input())
for it in range(t):
	N = 0
	s = input()
	s = list(s)
	zero = False
	prevI = -1
	for i in range(len(s)):
		if s[i] == '1':
			prevI = i
			break
	for i in range(prevI + 1, len(s)):
		if s[i] == '1':
			if i - prevI > 1:
				N += i - prevI - 1
				prevI = i
			elif i - prevI == 1:
				prevI = i
	print(N)


for _ in range(int(input())):
	s = input()
	cnt = 0
	if '1' in s:
		k = s.index('1')
		x = s[::-1]
		k1 = len(s) - x.index('1')
		for i in s[k:k1]:
			if i == '0':
				cnt += 1
		print(cnt)
	else:
		print(0)


from math import *
from sys import stdin, stdout
import itertools
import os
import sys
import threading
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import *
from fractions import Fraction
mod = int(pow(10, 9) + 7)

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

def si():
	return str(input())

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

def li():
	return list(mi())

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

def fsi():
	return str(stdin.readline())

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

def fli():
	return list(fmi())
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

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

def ntl(n):
	return [int(i) for i in str(n)]

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
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d:
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d:
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = defaultdict(list)
	for i in range(n):
		(x, y) = mi()
		d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

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

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)

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

def dijkstra(edges, f, t):
	g = defaultdict(list)
	for (l, r, c) in edges:
		g[l].append((c, r))
	(q, seen, mins) = ([(0, f, ())], set(), {f: 0})
	while q:
		(cost, v1, path) = heappop(q)
		if v1 not in seen:
			seen.add(v1)
			path = (v1, path)
			if v1 == t:
				return (cost, path)
			for (c, v2) in g.get(v1, ()):
				if v2 in seen:
					continue
				prev = mins.get(v2, None)
				next = cost + c
				if prev is None or next < prev:
					mins[v2] = next
					heappush(q, (next, v2, path))
	return float('inf')

def binsearch(a, l, r, x):
	while l <= r:
		mid = l + (r - 1) // 2
		if a[mid]:
			return mid
		elif a[mid] > x:
			l = mid - 1
		else:
			r = mid + 1
	return -1
t = ii()
for _ in range(t):
	s = si()
	for i in range(len(s)):
		if s[i] == '1':
			s = s[i:]
			break
	s = s[::-1]
	for i in range(len(s)):
		if s[i] == '1':
			s = s[i:]
			break
	c = 0
	o = 0
	for i in range(len(s)):
		if s[i] == '0':
			c += 1
		if s[i] == '1':
			o += 1
	if o == 0:
		print(0)
	else:
		print(c)


t = int(input())
for i in range(t):
	s = input()
	f1 = 3459045873894759
	l1 = []
	saida = 0
	for j in range(len(s)):
		if s[j] == '1':
			l1.append(j)
	for j in range(len(l1)):
		try:
			if l1[j + 1] - l1[j] != 1:
				saida += l1[j + 1] - l1[j] - 1
		except:
			saida += 0
	print(saida)


t = int(input())
while t:
	t = t - 1
	a = input()
	initial = float('inf')
	final = -1 * float('inf')
	for x in range(len(a)):
		if a[x] == '1':
			initial = min(initial, x)
			final = max(final, x)
	if final == initial or initial == -1 * final:
		print(0)
	else:
		ans = 0
		for x in range(initial, final + 1):
			if a[x] == '0':
				ans += 1
		print(ans)


import sys

def rr():
	return sys.stdin.readline().rstrip()
rp = print

def print(*args, **kwargs):
	rp('DBG:# ', *args, **kwargs, file=sys.stderr)

def rri():
	return int(rr())

def rrl():
	return list(map(int, rr().split()))

def rrt():
	return tuple(map(int, rr().split()))

def rrle():
	return (line.rstrip() for line in sys.stdin.readlines())

def rrtl():
	return [tuple(map(int, l.split())) for l in rrle()]
from collections import defaultdict

def mus(d=lambda : 0):
	return defaultdict(lambda : defaultdict(d))

def dd0(d=lambda : 0):
	return defaultdict(d)

def ms(x, y, d=0):
	return [[0] * y for i in range(x)]

def ar(x, d=0):
	return [d] * x

def ppm(m, n=0, x=0, y=0):
	print('\n'.join(('\t'.join((str(m[j][i]) for j in range(y or n))) for i in range(x or n))))

def ppa(a, n):
	print('\t'.join(map(str, a[0:n])))

def ppl(a=0, x=[1]):
	x[0] = a or x[0] + 1
	print('-' + '- -' * 14 + '-# ' + str(x[0] - 2) + ' #-' + '- -' * 14 + '-')

def fltn(a):
	(i for sub in a for i in sub)

def yn(x):
	return 'YES' if x else 'NO'

def cpc(arr):
	return zip(arr, arr[1:])
from itertools import accumulate
from itertools import groupby
from itertools import permutations

def grp(x, key=None):
	return ((i, sum((1 for _ in g))) for (i, g) in groupby(x, key=key))
import math

def rnar():
	return (*rrl(), rrl())

def rn():
	return (*rrl(),)

def dpp(a, b=''):
	print('#| {} |#:^ {} ^:'.format(a, b))

def str_join(i, sep=' '):
	return sep.join(map(str, i))
MOD17 = 10 ** 9 + 7

def read():
	return (rr(),)

def solve(s):
	r = len(s) - len(s.rstrip('0'))
	l = len(s) - len(s.lstrip('0'))
	ans = max(0, s.count('0') - (r + l))
	return ans
test_count = 1
test_count = rri()
for _ in range(test_count):
	input_data = read()
	result = solve(*input_data)
	rp(result)


t = int(input())
for _ in range(t):
	n = input()
	p = len(n)
	(c, k, q) = (0, 0, 0)
	for i in range(p):
		if n[i] == '1':
			k = i
			break
	for i in range(p):
		if n[p - 1 - i] == '1':
			q = p - 1 - i
			break
	for i in range(k + 1, q):
		if n[i] == '0':
			c = c + 1
	print(c)


t = int(input())
st = []
for _ in range(t):
	st.append(input())
for s in st:
	of = False
	zf = False
	zerocount = 0
	for (k, i) in enumerate(s):
		if zf and of and (i == '1'):
			j = k - 1
			while j < len(s) and s[j] != '1':
				zerocount += 1
				j -= 1
			zf = False
		elif i == '0':
			zf = True
		elif i == '1':
			of = True
	print(zerocount)


t = int(input())
for _ in range(t):
	s = input()
	ans = 0
	skip_to = None
	for i in range(len(s)):
		if skip_to and i < skip_to:
			continue
		if s[i] == '1':
			for j in range(i + 1, len(s)):
				if s[j] == '1':
					ans += j - i - 1
					skip_to = j
					break
	print(ans)


t_c = int(input())
result = []
for v in range(t_c):
	bn = input()
	left = bn.find('1')
	right = bn.rfind('1') + 1
	result.append(str(bn[left:right].count('0')))
print('\n'.join(result))


T = int(input())
for case in range(T):
	string = input()
	i = 0
	while string[i] == '0':
		i += 1
		if i >= len(string):
			break
	string = string[i:]
	while len(string) != 0:
		if string[-1] == '0':
			string = string[:-1]
		else:
			break
	print(sum([1 for s in string if s == '0']))


t = int(input())
for _ in range(t):
	a = list(input())
	b = []
	n = len(a)
	i = 0
	flag = 0
	count = 0
	while i < n:
		if a[i] == '1':
			if flag == 1 and a[i - 1] == '0':
				b.append(count)
			flag = 1
			count = 0
		else:
			count = count + 1
		i = i + 1
	print(sum(b))


t = int(input())
l = []
for i in range(t):
	s = input()
	count1 = 0
	for j in s:
		if j == '1':
			count1 += 1
	count0 = len(s) - count1
	flag = 0
	count = 0
	gap = 0
	for k in range(len(s)):
		if s[k] == '1':
			flag = 1
			count += 1
		elif flag == 1 and count < count1:
			if s[k] == '0':
				gap += 1
	l.append(gap)
for i in l:
	print(i)


n = int(input())
q = 0
w = 0
L = []
for i in range(n):
	s = input()
	for i in range(len(s)):
		if s[i] == '1':
			s = s[i:]
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			s = s[:i + 1]
			break
	for i in range(len(s)):
		if w:
			if s[i] == '0':
				q += 1
		if s[i] == '1':
			w = 1
	L.append(q)
	q = 0
	w = 0
for i in range(len(L)):
	print(L[i])


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


for i in range(int(input())):
	a = input()
	l = []
	ct = 0
	for j in a:
		l.append(j)
	ctr = 0
	c = l.count('1')
	if c == 0:
		print(0)
	else:
		b = l.index('1')
		d = 0
		for j in range(len(l)):
			if l[j] == '1':
				ct += 1
			if ct == c:
				d = j
				break
		for j in range(b, d + 1):
			if l[j] == '0':
				ctr += 1
		print(ctr)


for _ in range(int(input())):
	s = input()
	c = 0
	if '1' in s and '0' in s:
		(x, y) = (s.index('1'), s.rfind('1'))
		for k in range(x, y + 1):
			if s[k] == '0':
				c += 1
	print(c)


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin, tan

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

def fi():
	return float(stdin.readline())

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

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline()

def sieve(x):
	a = [True] * (x + 1)
	sq = floor(sqrt(x))
	for i in range(3, sq + 1, 2):
		if a[i]:
			for j in range(i * i, x + 1, i):
				a[j] = False
	if x > 1:
		p = [2]
	else:
		p = []
	for i in range(3, x + 1, 2):
		if a[i]:
			p.append(i)
	return p

def prime_factor(x):
	c = 1
	i = 0
	while p[i] * p[i] <= x:
		if not x % p[i]:
			c += 1
			while not x % p[i]:
				x //= p[i]
		i += 1
	if x > 1:
		c += 1
	return c
res = ['YES', 'NO']
for _ in range(ii()):
	a = lsi()
	if '1' in a:
		l = a.index('1')
		r = len(a) - 1 - a[::-1].index('1')
		print(a[l:r].count('0'))
	else:
		print(0)


for i in range(int(input())):
	s = str(input())
	try:
		x = s.index('1')
		y = s[::-1].index('1')
		y = len(s) - y
		new = s[x:y]
		print(new.count('0'))
	except:
		print(0)


for _ in range(int(input())):
	string = input().strip()
	zeros = string.count('0')
	if zeros == len(string):
		print(0)
		continue
	for i in string:
		if i == '1':
			break
		zeros -= 1
	for i in string[::-1]:
		if i == '1':
			break
		zeros -= 1
	print(zeros)


t = int(input())
for i in range(t):
	s = input()
	c = 0
	while s.count('1') > 0:
		i = s.find('1')
		s1 = s[i + 1:]
		i1 = s1.find('1')
		if i1 > 0:
			c = c + i1
		s = s1
	print(c)


import sys
input = sys.stdin.readline
for _ in range(int(input().strip())):
	lis = list(input().strip())
	idx = []
	for i in range(len(lis)):
		if lis[i] == '1':
			idx.append(i)
	if len(idx) <= 1:
		print(0)
	else:
		ans = 0
		for i in range(1, len(idx)):
			ans += idx[i] - idx[i - 1] - 1
		print(ans)


for _ in range(int(input())):
	s = input()
	if len(set(s)) == 1:
		print(0)
	else:
		flag = False
		for i in range(len(s)):
			if s[i] == '1':
				if not flag:
					x = i
					flag = True
				y = i
		print(y - x + 1 - s.count('1'))


n = int(input())

def chk(k):
	if set(list(k)) == {'0'}:
		return 0
	while k[-1] == '0':
		k = k[:len(k) - 1]
	while k[0] == '0':
		k = k[1:]
	if k[0] == '0':
		return k.count('0') - 1
	return k.count('0')
a = []
for i in range(n):
	s = input()
	a.append(chk(s))
for i in a:
	print(i)