Alice and Bob play a game. They have a binary string $s$ (a string such that each character in it is either $0$ or $1$). Alice moves first, then Bob, then Alice again, and so on.

During their move, the player can choose any number (not less than one) of consecutive equal characters in $s$ and delete them.

For example, if the string is $10110$, there are $6$ possible moves (deleted characters are bold):  $\textbf{1}0110 \to 0110$;  $1\textbf{0}110 \to 1110$;  $10\textbf{1}10 \to 1010$;  $101\textbf{1}0 \to 1010$;  $10\textbf{11}0 \to 100$;  $1011\textbf{0} \to 1011$. 

After the characters are removed, the characters to the left and to the right of the removed block become adjacent. I. e. the following sequence of moves is valid: $10\textbf{11}0 \to 1\textbf{00} \to 1$.

The game ends when the string becomes empty, and the score of each player is the number of $1$-characters deleted by them.

Each player wants to maximize their score. Calculate the resulting score of Alice.


-----Input-----

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

Each test case contains exactly one line containing a binary string $s$ ($1 \le |s| \le 100$).


-----Output-----

For each test case, print one integer — the resulting score of Alice (the number of $1$-characters deleted by her).


-----Example-----
Input
5
01111001
0000
111111
101010101
011011110111

Output
4
0
6
3
6



-----Note-----

Questions about the optimal strategy will be ignored.

Difficulty: EASY

Solutions:
t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	count = [0] * n
	poss = list()
	ans = 0
	if s[0] == '0':
		count[0] = 0
	else:
		count[0] = 1
	for i in range(1, n):
		if s[i] == '1':
			count[i] = 1 + count[i - 1]
	for i in range(n - 1):
		if count[i] != count[i + 1] - 1:
			poss.append(count[i])
	if count[n - 1] != 0:
		poss.append(count[n - 1])
	poss.sort(reverse=True)
	i = 0
	while i < len(poss):
		ans += poss[i]
		i += 2
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	i = 0
	ar = []
	while i < len(s):
		j = 0
		while i + j < len(s) and s[i + j] == '1':
			j += 1
		if j != 0:
			ar.append(j)
		i = i + j + 1
	ar.sort(reverse=True)
	ans = 0
	for i in range(len(ar)):
		if i % 2 == 0:
			ans += ar[i]
	print(ans)


import sys
T = int(input())
for _ in range(T):
	s = input()
	s = s + '0'
	A = []
	f = 0
	c = 0
	for i in range(len(s)):
		if s[i] == '1' and f == 0:
			c = c + 1
			f = 1
		elif s[i] == '1' and f == 1:
			c = c + 1
		elif s[i] == '0' and f == 1:
			A.append(c)
			(c, f) = (0, 0)
		else:
			(c, f) = (0, 0)
	A.sort(reverse=True)
	ans = 0
	for i in range(0, len(A), 2):
		ans = ans + A[i]
	print(ans)


t = int(input())
for i in range(t):
	s = list(input())
	m = []
	i = 0
	while i < len(s):
		if s[i] == '1':
			j = i
			c = 0
			while j < len(s):
				if s[j] == '0':
					break
				c = c + 1
				j = j + 1
			m.append(c)
			i = j
		else:
			i = i + 1
	m.sort(reverse=True)
	if len(m) == 0:
		print(0)
	else:
		s = 0
		for j in range(len(m)):
			if j % 2 == 0:
				s = s + m[j]
		print(s)


for _ in range(int(input())):
	z = input().split('0')
	z.sort(reverse=True)
	d = 0
	for i in range(0, len(z), 2):
		d += len(z[i])
	print(d)


for i in range(int(input())):
	a = [int(x) for x in list(input())]
	pt = 0
	p = 0
	z = []
	for j in a:
		if j == 1:
			if pt == 1:
				p += 1
			else:
				pt = 1
				p = 1
		if j == 0:
			if pt == 1:
				z.append(p)
				p = 0
				pt = 0
	if a[-1] == 1:
		z.append(p)
	z.sort(reverse=True)
	s = 0
	for j in range(0, len(z), 2):
		s += z[j]
	print(s)


T = int(input())
for t in range(T):
	l = [k for k in input().split('0')]
	while True:
		if '' not in l:
			break
		else:
			l.remove('')
	a = 0
	n = len(l)
	l.sort()
	n -= 1
	while n > -1:
		a += len(l[n])
		n -= 2
	print(a)


def solution(s):
	l = list(s)
	l = [int(x) for x in l]
	arr = []
	ans = 0
	for i in range(len(l)):
		if l[i] == 0:
			arr.append(ans)
			ans = 0
		else:
			ans = ans + 1
	arr.append(ans)
	arr.sort(reverse=True)
	ans = 0
	for i in range(0, len(arr), 2):
		ans = ans + arr[i]
	return ans
for _ in range(int(input())):
	n = input()
	print(solution(n))


for i in range(int(input())):
	s = input()
	a = []
	count = 0
	for i in range(len(s)):
		if s[i] == '1':
			count = count + 1
		else:
			a.append(count)
			count = 0
	a.append(count)
	points = 0
	alice = 0
	counter = 1
	while len(a) > 0:
		maxi = max(a)
		a.remove(maxi)
		if counter % 2 == 1:
			alice = alice + maxi
		counter = counter + 1
	print(alice)


T = int(input())
for i in range(T):
	s = input()
	ones_count = []
	current_ones_count = 0
	for c in s:
		if c == '1':
			current_ones_count += 1
		else:
			if current_ones_count == 0:
				continue
			ones_count.append(current_ones_count)
			current_ones_count = 0
	if current_ones_count != 0:
		ones_count.append(current_ones_count)
	ones_count.sort(reverse=True)
	print(sum(ones_count[::2]))


t = int(input())
while t > 0:
	s = input()
	l = [int(x) for x in str(s)]
	cnt = 0
	m = []
	for i in range(0, len(l)):
		if l[i] == 1:
			cnt += 1
		else:
			m.append(cnt)
			cnt = 0
	if l[-1] == 1:
		m.append(cnt)
	m.sort()
	m.reverse()
	g = 0
	for i in range(0, len(m), 2):
		g += m[i]
	print(g)
	t -= 1


t = int(input())
for _ in range(t):
	line = str(input())
	ln = len(line)
	lst = []
	cnt = 0
	for i in range(0, ln):
		if line[i] == '1':
			cnt += 1
		else:
			if cnt:
				lst.append(cnt)
			cnt = 0
	if cnt:
		lst.append(cnt)
	lst.sort()
	tot = 0
	ln = len(lst)
	if ln % 2 == 1:
		for i in range(ln):
			if i % 2 == 0:
				tot += lst[i]
	else:
		for i in range(ln):
			if i % 2 == 1:
				tot += lst[i]
	print(tot)


def solve(s):
	res = 0
	lst = []
	for i in s:
		if i == '1':
			res += 1
		else:
			lst.append(res)
			res = 0
	lst.append(res)
	lst.sort()
	a = 0
	for i in range(len(lst) - 1, -1, -2):
		a += lst[i]
	return a
t = int(input())
for _ in range(t):
	s = input()
	print(solve(s))


print(*[sum(sorted(map(len, input().split('0')), reverse=True)[::2]) for i in range(int(input()))], sep='\n')


t = int(input())
while t:
	t = t - 1
	s = input().split('0')
	s = sorted(s)
	res = 0
	for i in range(len(s) - 1, -1, -2):
		if s[i] == '':
			break
		res += len(s[i])
	print(res)


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for j in range(int(input())):
	vals = [int(k) for k in input()]
	chain = 0
	ones = []
	for s in range(len(vals)):
		if vals[s] == 1:
			chain += 1
		else:
			if chain > 0:
				ones.append(chain)
			chain = 0
	if chain > 0:
		ones.append(chain)
	cv = 0
	ans = 0
	ones.sort()
	while len(ones) > 0:
		v0 = ones.pop()
		if cv % 2 == 0:
			ans += v0
		cv += 1
	print(ans)


for _ in range(int(input())):
	st = input()
	l = []
	cnt = 0
	if st[0] == '1':
		cnt += 1
	for i in range(1, len(st)):
		if st[i] == st[i - 1] and st[i] == '1':
			cnt += 1
		elif st[i] != st[i - 1] and st[i] == '1':
			cnt = 1
		else:
			if cnt > 0:
				l.append(cnt)
			cnt = 0
	if cnt > 0:
		l.append(cnt)
	if len(l) == 0:
		print(0)
	else:
		l.sort(reverse=True)
		ans = 0
		for i in range(len(l)):
			if i % 2 == 0:
				ans += l[i]
		print(ans)


T = int(input())
for _ in range(T):
	x = input()
	a = x.split('0')
	b = []
	for q in a:
		if len(q):
			b.append(len(q))
	b.sort()
	b = list(reversed(b))
	print(sum(b[::2]))


for z in range(int(input())):
	s = input()
	p = []
	count = 0
	for i in range(len(s)):
		if s[i] == '1':
			count += 1
		else:
			if count:
				p.append(count)
			count = 0
	if count:
		p.append(count)
	p.sort(reverse=True)
	print(sum(p[::2]))


t = int(input())
for _ in range(t):
	s = input()
	arr = []
	if s[0] == '1':
		x = 1
	else:
		x = 0
	for i in range(1, len(s)):
		if s[i] == '1':
			x += 1
		elif x != 0:
			arr.append(x)
			x = 0
	if x != 0:
		arr.append(x)
	arr = sorted(arr, reverse=True)
	ans = 0
	n = len(arr)
	for i in range(0, n, 2):
		ans += arr[i]
	print(ans)


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

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

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

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

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

def SI():
	return sys.stdin.readline()[:-1]
for _ in range(II()):
	s = '0' + SI() + '0'
	cc = []
	cnt = 0
	for c in s:
		if c == '0' and cnt:
			cc.append(cnt)
			cnt = 0
		if c == '1':
			cnt += 1
	cc.sort(reverse=True)
	print(sum(cc[::2]))


t = int(input())
for _ in range(t):
	l = []
	s = input()
	i = 0
	ans = 0
	while i < len(s):
		if s[i] == '1':
			num = 1
			if i != len(s) - 1:
				t = i
				for j in range(t + 1, len(s)):
					i = j
					if s[j] == '1':
						num += 1
					else:
						break
			l.append(num)
		i += 1
	l.sort(reverse=True)
	for i in range(len(l)):
		if i % 2 == 0:
			ans += l[i]
	print(ans)


from sys import stdin, stdout
import math
input = stdin.readline

def print(*args, end='\n'):
	s = []
	for i in args:
		s.append(str(i) + ' ')
	s = ''.join(s)
	stdout.write(s + end)

def solve():
	s = input()
	l = len(s)
	ans = []
	i = 0
	while i < l:
		if s[i] == '1':
			cnt = 1
			i += 1
			while i < l and s[i] == '1':
				i += 1
				cnt += 1
			ans.append(cnt)
		i += 1
	a = 0
	ans.sort(reverse=True)
	for i in range(len(ans)):
		if i % 2 == 0:
			a += ans[i]
	print(a)
tt = 1
tt = int(input())
for __ in range(tt):
	solve()


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

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

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write('\n'.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
from fractions import Fraction
INF = float('inf')
mod = int(1000000000.0) + 7
for t in range(int(data())):
	s = data()
	l = []
	cnt = 0
	for i in s:
		if i == '1':
			cnt += 1
		else:
			l.append(cnt)
			cnt = 0
	l.append(cnt)
	l.sort(reverse=True)
	ans = 0
	for i in range(0, len(l), 2):
		ans += l[i]
	out(ans)


def f(s):
	s = s.split('0')
	s.sort(key=lambda x: len(x), reverse=True)
	a = 0
	for i in range(0, len(s), 2):
		a = len(s[i]) + a
	return a
for _ in range(int(input())):
	s = input()
	print(f(s))


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


for _ in range(int(input())):
	s = input()
	i = 0
	l = []
	while i < len(s):
		if s[i] == '1':
			j = i
			count = 0
			while j < len(s) and s[j] == '1':
				j += 1
				count += 1
			l.append(count)
			i = j
		else:
			i += 1
	l.sort(reverse=True)
	ans = 0
	for k in range(len(l)):
		if k % 2 == 0:
			ans += l[k]
	print(ans)


def lones(A, i, T):
	if int(A[i]) == 1:
		if i not in T:
			T[i] = 1
			j = i - 1
			while j >= 0:
				ans = lones(A, j, T)
				if ans == 0:
					break
				T[i] = max(T[i], ans + 1)
				j = j - 1
		return T[i]
	else:
		return 0
for _ in range(int(input())):
	T = {}
	arr = input()
	alice = 0
	score = 0
	mx = []
	lst = [lones(arr, i, T) for i in range(len(arr))]
	for i in range(len(lst)):
		if len(lst) != 0:
			score = max(lst)
			mx.append(score)
			index = lst.index(score)
			j = index
			while j > index - score:
				lst.pop(j)
				j = j - 1
	for i in range(len(mx)):
		if mx[i] == 0:
			break
		elif i % 2 == 0:
			alice = alice + mx[i]
	print(alice)


def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = len(li) - 1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def mex(li):
	check = [0] * 1001
	for i in li:
		check[i] += 1
	for i in range(len(check)):
		if check[i] == 0:
			return i

def sumdigits(n):
	ans = 0
	while n != 0:
		ans += n % 10
		n //= 10
	return ans

def product(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def maxpower(n, k):
	cnt = 0
	while n > 1:
		cnt += 1
		n //= k
	return cnt

def knapsack(li, sumi, s, n, dp):
	if s == sumi // 2:
		return 1
	elif n == 0:
		return 0
	elif dp[n][s] != -1:
		return dp[n][s]
	else:
		if li[n - 1] <= s:
			dp[n][s] = knapsack(li, sumi, s - li[n - 1], n - 1, dp) or knapsack(li, sumi, s, n - 1, dp)
		else:
			dp[n][s] = knapsack(li, sumi, s, n - 1, dp)
		return dp[n][s]

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum
from math import *
for _ in range(int(input())):
	s = input()
	f = 0
	ans = 0
	ind0 = [-1]
	for i in range(len(s)):
		if s[i] == '0':
			ind0.append(i)
	ind0.append(len(s))
	n1 = []
	for i in range(1, len(ind0)):
		n1.append(ind0[i] - ind0[i - 1] - 1)
	n1.sort(reverse=True)
	for i in range(0, len(n1), 2):
		ans += n1[i]
	print(ans)


(z, zz) = (input, lambda : list(map(int, z().split())))
(szz, dgraphs, mod) = (lambda : sorted(zz()), {}, 10 ** 9 + 7)
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	l = z()
	ans = 0
	j = 0
	while True:
		x = l.count('1')
		if x == 0:
			break
		i = 100
		while True:
			x = l.count('1')
			if x == 0:
				break
			p = '1' * i
			if p in l:
				if j % 2 == 0:
					ans += i
				l = l.replace('1' * i, '', 1)
				break
			else:
				i -= 1
			x = l.count('1')
			if x == 0:
				break
		j += 1
		if x == 0:
			break
	print(ans)


import operator
t = int(input())
while t:
	t -= 1
	s = input()
	d = []
	i = 0
	while i < len(s):
		tmp = 0
		while i < len(s) and s[i] == '1':
			tmp += 1
			i += 1
		if tmp > 0:
			d.append(tmp)
		else:
			i += 1
	d.sort(reverse=True)
	score = 0
	for i in range(0, len(d), 2):
		score += d[i]
	print(score)


for _ in range(int(input())):
	s = input()
	l = []
	n = 0
	for i in s:
		if i == '1':
			n += 1
		elif n == 0:
			continue
		else:
			l.append(n)
			n = 0
	if n != 0:
		l.append(n)
	l = sorted(l, reverse=True)
	print(sum((l[i] for i in range(0, len(l), 2))))


import sys
import math
from math import *
from collections import Counter, defaultdict
from io import BytesIO, IOBase
from collections import deque
import bisect

def primes():
	arr = [True if i % 2 == 1 else False for i in range(100)]
	arr[0] = arr[1] = False
	arr[2] = True
	for i in range(3, 100 // 2 + 1, 2):
		if not arr[i]:
			continue
		for j in range(i * 2, 100, i):
			arr[j] = False
	print(arr)

def main():
	s = input()
	arr = []
	j = 0
	while j < len(s):
		cnt = 0
		while j < len(s):
			if s[j] == '0':
				pass
			else:
				break
			j += 1
		while j < len(s):
			if s[j] == '1':
				cnt += 1
			else:
				break
			j += 1
		arr.append(cnt)
	arr.sort(reverse=True)
	ans = 0
	for i in range(0, len(arr), 2):
		ans += arr[i]
	print(ans)
for i in range(int(input())):
	main()


for _ in range(int(input())):
	n = input()
	a = []
	t = 0
	while t < len(n):
		c = 0
		if n[t] == '1':
			while t < len(n) and n[t] == '1':
				c += 1
				t += 1
			a.append(c)
		else:
			t += 1
	a.sort(reverse=True)
	ans = 0
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)


def solve(s):
	ans = []
	count = 0
	flag = False
	if s[0] == '1':
		flag = True
	for i in s:
		if i == '1':
			count += 1
			if flag == False:
				flag = True
		else:
			if flag == True:
				ans.append(count)
				flag = False
			count = 0
	ans.append(count)
	return ans

def check(arr):
	c = 0
	arr = sorted(arr)[::-1]
	for i in range(len(arr)):
		if i % 2 == 0:
			c += arr[i]
	return c
for _ in range(int(input())):
	s = input()
	print(check(solve(s)))


def sol(s):
	dp = []
	i = 0
	j = 0
	while i < len(s):
		c = 0
		while i < len(s) and s[i] == '1':
			c += 1
			i += 1
		if c:
			dp.append(c)
		else:
			i += 1
	dp.sort()
	res = 0
	while dp:
		res += dp[-1]
		dp = dp[:len(dp) - 2]
	print(res)
k = int(input())
for i in range(k):
	s = input()
	sol(s)


import io, os
from collections import deque
import bisect
from collections import deque
RL = lambda : list(map(int, input().split(' ')))
T = int(input())
for _ in range(T):
	s = input()
	ones = 0
	arr = []
	for i in range(len(s)):
		if s[i] == '1':
			ones += 1
		elif ones != 0:
			arr.append(ones)
			ones = 0
	if ones != 0:
		arr.append(ones)
	arr.sort(reverse=True)
	ans = 0
	for i in range(0, len(arr), 2):
		ans += arr[i]
	print(ans)


for _ in ' ' * int(input()):
	s = []
	for i in input().replace('10', '1 ').replace('01', ' 1').split():
		if '1' in i:
			s += [len(i)]
	s.sort(reverse=True)
	print(sum(s[::2]))


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		s = input()
		ar = []
		ct = 0
		for i in s:
			if i == '1':
				ct += 1
			else:
				if ct > 0:
					ar.append(ct)
				ct = 0
		if ct > 0:
			ar.append(ct)
		ar.sort(reverse=True)
		ans = 0
		for i in range(0, len(ar), 2):
			ans += ar[i]
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


T = int(input())
while T > 0:
	s = input()
	a = ''
	c = []
	for i in s:
		if i == '1':
			a = a + i
		else:
			if len(a) != 0:
				c.append(len(a))
			a = ''
	c.append(len(a))
	c.sort()
	score = 0
	if len(c) % 2 == 0:
		for i in range(1, len(c), 2):
			score += c[i]
	else:
		for i in range(0, len(c), 2):
			score += c[i]
	print(score)
	T = T - 1


for i in range(int(input())):
	a = input().split('0')
	a.sort(reverse=True)
	ans = 0
	for j in range(0, len(a), 2):
		ans += len(a[j])
	print(ans)


from sys import stdin
_input = stdin.readline
(_int, _range, _str, _len, _sum) = (int, range, str, len, sum)

def solution():
	for _ in _range(_int(_input())):
		arr = [_int(i) for i in _input().rstrip('\n')]
		counter = 0
		variants = []
		for i in arr:
			if i == 1:
				counter += 1
			else:
				variants.append(counter)
				counter = 0
		if counter > 0:
			variants.append(counter)
		variants.sort(reverse=True)
		print(_sum([variants[i] for i in _range(_len(variants)) if i % 2 == 0]))
solution()


import sys
import heapq
import math
from collections import deque
from collections import defaultdict
from collections import Counter
modH = int(10 ** 9) + 7
I = lambda : list(map(int, input().split(' ')))

def PRINT(lst, sep=' '):
	print(sep.join(map(str, lst)))

def one_block(ss):
	nn = len(ss)
	ans = [ss[0]]
	for i in range(nn - 1):
		if ss[i] == '0' and ss[i + 1] == '0':
			()
		else:
			ans.append(ss[i + 1])
	if ans[0] == '0':
		ans.pop(0)
	cc = 0
	aa = []
	for i in range(len(ans)):
		if ans[i] == '1':
			cc += 1
		else:
			aa.append(cc)
			cc = 0
	if len(ans) == 0:
		return 0
	if ans[-1] == '1':
		aa.append(cc)
	aa.sort()
	aa.reverse()
	ss = 0
	for i in range(0, len(aa), 2):
		ss += aa[i]
	return ss
for _ in range(int(input())):
	ss = input()
	print(one_block(ss))


for _ in range(int(input())):
	s = list(input())
	points = 0
	s2 = []
	while len(s) > 0:
		points = 0
		while len(s) > 0 and s[0] == '1':
			s.pop(0)
			points += 1
		s2.append(points)
		while len(s) > 0 and s[0] == '0':
			s.pop(0)
	s2.sort(reverse=True)
	s2 = [s2[i] for i in range(len(s2)) if i % 2 == 0]
	print(sum(s2))


import sys
input = sys.stdin.buffer.readline
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
inst = lambda : sys.stdin.readline().rstrip('\n\r')
INF = float('inf')
_T_ = inin()
for _t_ in range(_T_):
	s = inst().split('0')
	an = 0
	a = []
	for i in s:
		a.append(len(i))
	a.sort(reverse=True)
	for i in range(len(a)):
		if i % 2 == 0:
			an += a[i]
	print(an)


import sys
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))

def main():
	for _ in range(int(input())):
		s = [len(i) for i in input().strip().split('0') if i]
		s.sort(reverse=True)
		print(sum([s[i] for i in range(0, len(s), 2)]))
main()


t = int(input())
for i in range(t):
	s = list(map(len, input().split('0')))
	s.sort(reverse=True)
	ans = 0
	for j in range(0, len(s), 2):
		ans += s[j]
	print(ans)


for _ in range(int(input())):
	s = str(input())
	List = []
	p = 0
	while p < len(s):
		if s[p] == '1':
			(sp, count) = (p + 1, 1)
			while sp < len(s):
				if s[sp] == '1':
					sp += 1
					count += 1
				else:
					break
			List.append(count)
			p = sp
		else:
			p += 1
	List.sort()
	res = 0
	for j in range(len(List) - 1, -1, -2):
		res += List[j]
	print(res)


t = int(input())
while t > 0:
	t -= 1
	line = input()
	ones = []
	i = 0
	n = len(line)
	while i < n:
		tmp = 0
		if line[i] == '1':
			while i < n and line[i] == '1':
				tmp += 1
				i += 1
			ones.append(tmp)
		else:
			i = i + 1
	a = 0
	ones = sorted(ones, reverse=True)
	while len(ones) > 0:
		a += ones.pop(0)
		if len(ones) > 0:
			ones.pop(0)
	print(a)


import collections

def solve(lst):
	cache = []
	s = 0
	for i in range(len(lst)):
		if lst[i] == '1':
			s += 1
		else:
			if s:
				cache.append(s)
			s = 0
	if s:
		cache.append(s)
	ans = 0
	cache = sorted(cache)[::-1]
	for i in range(0, len(cache), 2):
		ans += cache[i]
	return ans

def sort(key):
	return key[0]
ans = []
n = int(input())
for i in range(n):
	st = input()
	ans.append(solve(st))
for i in ans:
	print(i)


for _ in range(int(input())):
	s = input()
	k = 0
	l = []
	for i in range(len(s)):
		if s[i] == '1':
			k += 1
		else:
			l.append(k)
			k = 0
	l.append(k)
	l.sort(reverse=True)
	ans = sum(l[::2])
	print(ans)


def calc(s):
	n = len(s)
	one = 0
	zero = 0
	for i in range(n):
		if s[i] == '1':
			one += 1
		else:
			zero += 1
	if one == 0:
		return 0
	P = []
	i = 0
	while i < len(s):
		if s[i] == '1':
			count = 0
			while i < len(s) and s[i] == '1':
				count += 1
				i += 1
			P.append(count)
		else:
			i += 1
	ans = 0
	P.sort(reverse=True)
	for i in range(len(P)):
		if i % 2 == 0:
			ans += P[i]
	return ans
for _ in range(int(input())):
	s = input()
	print(calc(s))


import math
t = int(input(''))
for i in range(t):
	n = input('')
	a = []
	dem = 0
	for i in range(len(n)):
		if n[i] == '1':
			dem += 1
		else:
			if dem != 0:
				a.append(dem)
			dem = 0
	if dem > 0:
		a.append(dem)
	a.sort(reverse=True)
	dem1 = 0
	for i in range(len(a)):
		if i % 2 == 0:
			dem1 += a[i]
	print(dem1)


import sys
buf = sys.stdin.read()
nowbuf = 0
endbuf = len(buf)

def getint():
	global nowbuf
	valnow = 0
	while buf[nowbuf] < '0' or buf[nowbuf] > '9':
		nowbuf += 1
	while nowbuf < endbuf and buf[nowbuf] >= '0' and (buf[nowbuf] <= '9'):
		valnow = valnow * 10 + int(buf[nowbuf])
		nowbuf += 1
	return valnow

def getstr():
	global nowbuf
	strnow = ''
	while buf[nowbuf] == ' ' or buf[nowbuf] == '\n':
		nowbuf += 1
	while nowbuf < endbuf and buf[nowbuf] != ' ' and (buf[nowbuf] != '\n'):
		strnow += buf[nowbuf]
		nowbuf += 1
	return strnow

def solve(gamestr):
	gamestr += '0'
	a = []
	lenone = 0
	ans = 0
	i = 0
	strlen = len(gamestr)
	a.append(0)
	for i in range(0, strlen):
		if gamestr[i] == '1':
			a[lenone] += 1
		else:
			lenone += 1
			a.append(0)
	a.sort(reverse=1)
	for i in range(0, lenone):
		if i % 2 == 0:
			ans += a[i]
	print(ans)
	return
t = getint()
for i in range(0, t):
	solve(getstr())


for _ in range(int(input())):
	s = input()
	ones = []
	k = 0
	prev = 0
	flag = 0
	for i in range(len(s)):
		if s[i] == '0':
			if flag:
				ones.append(k)
			k = 0
			flag = 0
		else:
			k += 1
			flag = 1
	if ones == [] or flag:
		ones.append(k)
	ones.sort()
	ones.reverse()
	res = 0
	for i in range(0, len(ones), 2):
		res += ones[i]
	print(res)


T = int(input())
for z in range(T):
	s = input()
	onearr = list()
	if int(s) == 0:
		onearr.append(0)
	count = 0
	for e in range(len(s) - 1):
		if int(s[e]) == 1:
			count += 1
			if int(s[e + 1]) == 0:
				onearr.append(count)
				count = 0
			if e == len(s) - 2 and int(s[e + 1]) == 1:
				count += 1
				onearr.append(count)
		elif e == len(s) - 2 and int(s[e + 1]) == 1:
			onearr.append(1)
	if len(onearr) == 0:
		onearr.append(1)
	onearr.sort(reverse=True)
	i = 0
	l = len(onearr)
	ssum = 0
	while i < l:
		ssum = ssum + onearr[i]
		i += 2
	print(ssum)


for _ in range(int(input())):
	s = input()
	ans = list()
	c = 0
	if s[0] == '0':
		pivot = 0
	else:
		pivot = 1
		c = 1
	for q in s[1:]:
		if q == '1':
			if pivot == 1:
				c += 1
			else:
				pivot = 1
				c = 1
		elif pivot == 1:
			ans.append(c)
			c = 0
			pivot = 0
		else:
			pass
	if pivot == 1:
		ans.append(c)
	ans.sort(reverse=True)
	temp = 0
	for q in range(0, len(ans), 2):
		temp += ans[q]
	print(temp)


def solve(s, ans):
	ones = []
	curr = s[0]
	count = 0
	for i in s:
		if i == curr:
			count += 1
		else:
			if curr == '1':
				ones.append(count)
			curr = i
			count = 1
	if curr == '1':
		ones.append(count)
	ones.sort(reverse=True)
	alice = 0
	for i in range(len(ones)):
		if i % 2 == 0:
			alice += ones[i]
	ans.append(str(alice))

def main():
	t = int(input())
	ans = []
	for i in range(t):
		s = input()
		solve(s, ans)
	print('\n'.join(ans))
main()


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	s = sys.stdin.readline().strip()
	n = len(s)
	v = []
	curr = 0
	for i in range(n):
		if s[i] == '1':
			curr += 1
		else:
			if curr != 0:
				v.append(curr)
			curr = 0
	if curr != 0:
		v.append(curr)
	ans = 0
	v.sort(reverse=True)
	for i in range(0, len(v), 2):
		ans += v[i]
	print(ans)


for _ in range(int(input())):
	s = input()
	ones = s.split('0')
	ones = sorted([len(v) for v in ones if v], reverse=True)
	print(sum(ones[::2]))


def max_score(s):
	if set(s) == {'0'}:
		return 0
	if set(s) == {'1'}:
		return len(s)
	l = []
	count = 0
	score = 0
	for i in range(len(s)):
		if s[i] == '1':
			count += 1
			if i == len(s) - 1:
				if count:
					l.append(count)
		elif s[i] == '0':
			if count:
				l.append(count)
				count = 0
	l.sort(reverse=True)
	if l:
		for i in range(0, len(l), 2):
			score += l[i]
	return score
t = int(input())
for _ in range(t):
	s = input()
	print(max_score(s))


for t in range(int(input())):
	s = input()
	last = -1
	num = []
	n = len(s)
	for i in range(n):
		if s[i] == '0':
			if i - last - 1 > 0:
				num.append(i - last - 1)
			last = i
	if n - last - 1 > 0:
		num.append(n - last - 1)
	num = sorted(num)[::-1]
	ans = 0
	for i in range(0, len(num), 2):
		ans += num[i]
	print(ans)


import sys
import random
from fractions import Fraction
from math import *

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

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

def finput():
	return float(input())

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

def linput():
	return list(input())

def rinput():
	return map(int, tinput())

def fiinput():
	return map(float, tinput())

def flinput():
	return list(fiinput())

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

def trinput():
	return tuple(rinput())

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

def NOYES(fl):
	if fl:
		print('NO')
	else:
		print('YES')

def YESNO(fl):
	if fl:
		print('YES')
	else:
		print('NO')

def main():
	q = [int(i) for i in linput()] + [0]
	n = len(q) - 1
	w = []
	d = 0
	for i in range(n):
		if q[i] == 0:
			w.append(d)
			d = 0
		d += q[i]
	w.append(d)
	w = sorted(w, reverse=True)
	print(sum(w[::2]))
for TESTING in range(iinput()):
	main()


import sys
fin = sys.stdin
info = fin.read().split('\n')
fin.close()
t = int(info[0])
data = [sorted(list(map(len, info[i].split('0'))), reverse=True) for i in range(1, t + 1)]
for i in range(t):
	out = 0
	cnt = 0
	while True:
		try:
			out += data[i][cnt]
		except IndexError:
			break
		cnt += 2
	print(out)


t = int(input())
while t:
	t += -1
	s = input()
	ans = []
	cnt = 0
	for i in range(len(s)):
		if s[i] == '1':
			cnt -= -1
		else:
			if cnt > 0:
				ans.append(cnt)
			cnt = 0
	if cnt > 0:
		ans.append(cnt)
	ans.sort(reverse=True)
	fin = 0
	for i in range(0, len(ans), 2):
		fin += ans[i]
	print(fin)


t = int(input())
for _ in range(t):
	a = list(input())
	s = ''
	b = []
	for i in range(len(a)):
		if a[i] == '1':
			s += '1'
		else:
			if s != '':
				b.append(int(s))
			s = ''
	if s != '':
		b.append(int(s))
	if b == []:
		print('0')
	else:
		b.sort(reverse=True)
		c = 0
		for i in range(0, len(b), 2):
			c += len(str(b[i]))
		print(c)


t = int(input())
for te in range(t):
	s = input()
	a = []
	pre = 0
	for c in s:
		if c == '1':
			pre += 1
		else:
			a.append(pre)
			pre = 0
	if pre:
		a.append(pre)
	a.sort()
	print(sum(a[::-2]))


nu = int(input())
for i in range(nu):
	b = input().split('0')
	s = 0
	for i in range(len(b)):
		b[i] = len(b[i])
	b = sorted(b)
	b = b[::-1]
	for i in range(0, len(b), 2):
		s = b[i] + s
	print(s)


for t in range(int(input())):
	s = input().split('0')
	a = []
	for x in s:
		if len(x) > 0:
			a.append(len(x))
	ans = 0
	a.sort()
	a.reverse()
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)


for _ in range(int(input())):
	s = input().split('0')
	arr = []
	for x in s:
		if x != '':
			arr.append(len(x))
	arr = sorted(arr)[::-1]
	score = 0
	for i in range(0, len(arr), 2):
		score += arr[i]
	print(score)


for t in range(int(input())):
	s = input()
	l = []
	c = 0
	for i in s:
		if int(i) == 1:
			c += 1
		else:
			l.append(c)
			c = 0
	if c != 0:
		l.append(c)
	l.sort()
	s = 0
	for i in range(len(l) - 1, -1, -2):
		s += l[i]
	print(s)


def main():
	t = int(input())
	for _ in range(t):
		s = input().strip()
		a = []
		(last, cnt) = (s[0], 1)
		for i in range(1, len(s)):
			if s[i] == last:
				cnt += 1
			else:
				a.append((cnt, last))
				last = s[i]
				cnt = 1
		a.append((cnt, last))
		b = []
		for (c, ch) in a:
			if ch == '1':
				b.append(c)
		b.sort(reverse=True)
		ret = 0
		for i in range(len(b)):
			if not i & 1:
				ret += b[i]
		print(ret)
main()


t = int(input())
for i in range(t):
	s = input()
	ai = [0] * 101
	num = 0
	for i in range(len(s)):
		if s[i] == '1':
			num += 1
		else:
			ai[num] += 1
			num = 0
	ai[num] += 1
	ans = 0
	turn = 1
	for i in range(100, 0, -1):
		while ai[i] > 0:
			ai[i] -= 1
			if turn:
				ans += i
			turn ^= 1
	print(ans)


x = int(input())
for z in range(x):
	l = input()
	c = 0
	l1 = []
	for i in range(len(l)):
		if l[i] == '1':
			c += 1
		if l[i] == '0':
			l1.append(c)
			c = 0
	l1.append(c)
	l1 = list(filter(lambda a: a != 0, l1))
	l1.sort(reverse=True)
	ans = 0
	i = 0
	while i < len(l1):
		ans = ans + l1[i]
		i += 2
	print(ans)


t = int(input())
for _ in range(t):
	s = list(input())
	(a, b) = (0, 0)
	n1 = s.count('1')
	n = len(s)
	turn = 1
	while n1 != 0:
		n1 = s.count('1')
		temp = 0
		max_temp = -1
		index_temp = -1
		for i in range(n):
			if s[i] == '1':
				temp += 1
			else:
				if temp > max_temp:
					max_temp = temp
					index_temp = i - 1
				temp = 0
		if temp != 0 and s[-1] == '1':
			if temp > max_temp:
				max_temp = temp
				index_temp = n - 1
		while s[index_temp] == '1' and index_temp >= 0:
			if turn == 1:
				a += 1
				s[index_temp] = 0
			else:
				b += 1
				s[index_temp] = 0
			index_temp -= 1
		if turn == 1:
			turn = 2
		else:
			turn = 1
	print(a)


t = int(input())
for _ in range(t):
	s = input()
	ans = 0
	dop = 0
	while '1' in s:
		indmx = 0
		indnw = 0
		mx = 0
		nw = 0
		for i in range(len(s)):
			if s[i] == '1':
				if nw == 0:
					indnw = i
				nw += 1
			else:
				if nw > mx:
					mx = nw
					indmx = indnw
				nw = 0
		if nw > mx:
			mx = nw
			indmx = indnw
		if dop % 2 == 0:
			ans += mx
		s = s[:indmx] + s[indmx + mx:]
		dop += 1
	print(ans)


for y in range(int(input())):
	lst = input().split('0')
	lst.sort(reverse=True)
	count = 0
	for i in range(0, len(lst), 2):
		count += len(lst[i])
	print(count)


t = int(input())
for _ in range(t):
	s = input()
	sc = []
	c = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
		else:
			if c > 0:
				sc.append(c)
			c = 0
	if c > 0:
		sc.append(c)
	sc.sort(reverse=True)
	c = 0
	for i in range(0, len(sc), 2):
		c += sc[i]
	print(c)


for cases in range(int(input())):
	string = input()
	counts = []
	conteo = 0
	for i in range(len(string)):
		if string[i] == '1':
			conteo += 1
			if i == len(string) - 1:
				counts.append(conteo)
		elif conteo > 0:
			counts.append(conteo)
			conteo = 0
		else:
			conteo = 0
	counts.sort(reverse=True)
	print(sum((count for count in counts[::2])))


querys = int(input())
while querys != 0:
	querys -= 1
	plays = []
	entry = list(map(int, input()))
	found = False
	j = 0
	for i in range(len(entry)):
		if found and entry[i] == 0:
			found = False
			j += 1
		elif not found and entry[i] == 1:
			found = True
			plays.append(1)
		elif entry[i] == 1:
			plays[j] += 1
	plays.sort()
	plays.reverse()
	points = 0
	for k in range(0, len(plays), 2):
		points += plays[k]
	print(points)


for x in range(int(input())):
	a = input()
	arr = []
	c = 0
	d = 0
	for j in range(len(a)):
		if a[j] == '1':
			c = c + 1
			if j == len(a) - 1:
				if c != 0:
					arr.append(c)
		else:
			if c != 0:
				arr.append(c)
			c = 0
	arr = sorted(arr)
	for k in range(len(arr) - 1, -1, -2):
		d = d + arr[k]
	print(d)


from sys import stdin

def input():
	return stdin.readline().rstrip()
for _ in range(int(input())):
	s = input().split('0')
	for i in range(len(s)):
		s[i] = len(s[i])
	s = sorted(s)
	score = 0
	while len(s) > 0:
		score += s.pop(-1)
		if len(s) > 0:
			s.pop(-1)
	print(score)


def solve():
	s = input()
	siz = 0
	arr = []
	for i in s:
		if i == '1':
			siz += 1
		else:
			if siz > 0:
				arr.append(siz)
			siz = 0
	arr.append(siz)
	arr.sort(reverse=True)
	ans = 0
	for i in range(0, len(arr), 2):
		ans += arr[i]
	print(ans)
for _ in range(int(input())):
	solve()


T = int(input())
for _ in range(T):
	s = input()
	n = len(s)
	lens = []
	l = 1 if s[0] == '1' else 0
	for i in range(1, n):
		if s[i - 1] == '0' and s[i] == '1':
			l = 1
		elif s[i - 1] == '1' and s[i] == '1':
			l += 1
		elif s[i - 1] == '1' and s[i] == '0':
			lens.append(l)
			l = 0
	if s[n - 1] == '1':
		lens.append(l)
	lens = sorted(lens)[::-1]
	ans = sum(lens[::2])
	print(ans)


resultados = list()
cases = int(input())
for m in range(cases):
	lista = input()
	lista = list(lista)
	mayores = list()
	cuenta = 0
	for n in range(len(lista)):
		uno = False
		if lista[n] == '1':
			if not uno:
				cuenta += 1
				uno = True
			else:
				cuenta += 1
		elif cuenta >= 1:
			mayores.append(cuenta)
			cuenta = 0
	if cuenta >= 1:
		mayores.append(cuenta)
	mayores = sorted(mayores, reverse=True)
	mayores = mayores[::2]
	mayores = sum(mayores)
	resultados.append(mayores)
for n in range(len(resultados)):
	print(resultados[n])


def solve():
	T = int(input())
	for i in range(T):
		str = input().split('0')
		str.sort(reverse=True)
		ans = 0
		for i in range(0, len(str), 2):
			ans += len(str[i])
		print(ans)
solve()


t = int(input())
while t:
	t -= 1
	s = input()
	count = 0
	ans = []
	for item in s:
		if item == '0' and count != 0:
			ans.append(count)
			count = 0
		elif item == '1':
			count += 1
		else:
			pass
	if count != 0:
		ans.append(count)
	ans.sort(reverse=True)
	a = 0
	for i in range(0, len(ans), 2):
		a += ans[i]
	print(a)


T = int(input())
for i in range(T):
	s = input()
	l = [0]
	count = 0
	for c in s:
		if c == '0':
			if count != 0:
				l.append(count)
			count = 0
			continue
		if c == '1':
			count += 1
	if count != 0:
		l.append(count)
	res = 0
	sl = sorted(l, reverse=True)
	for i in range(0, len(sl), 2):
		res += sl[i]
	print(res)


import sys
import math
t = int(input())
while t > 0:
	t = t - 1
	strr = input()
	if len(strr) == 1:
		print(strr)
		continue
	ans = []
	count = 1
	flag = True
	size = int(len(strr))
	for i in range(1, size):
		if strr[i] == strr[i - 1]:
			count = count + 1
		else:
			if strr[i - 1] == '1':
				ans.append(count)
			count = 1
		if i == size - 1:
			if strr[i] == '1':
				ans.append(count)
	total = 0
	ans.sort(reverse=True)
	for i in range(0, len(ans), 2):
		total += ans[i]
	print(total)


t = int(input())
while t:
	t -= 1
	s = input()
	s = s.split('0')
	s = [len(si) for si in s]
	s.sort(reverse=True)
	alice = 0
	for i in range(0, len(s), 2):
		alice += s[i]
	print(alice)


from itertools import groupby
from collections import defaultdict as dd
t = int(input())

def fn():
	s = input()
	x = groupby(s)
	d = dd(list)
	for (k, g) in x:
		d[k].append(len(list(g)))
	l = d['1']
	l.sort(reverse=True)
	sm = 0
	for i in range(len(l)):
		if i % 2 == 0:
			sm += l[i]
	return sm
while t:
	print(fn())
	t -= 1


t = int(input())
for i in range(t):
	s = input()
	c = 0
	a = []
	for j in range(len(s)):
		if s[j] == '1':
			s = s[j:]
			break
	for j in range(len(s)):
		if s[j] == '0':
			a.append(c)
			c = 0
		else:
			c += 1
	if s[len(s) - 1] == '1':
		a.append(c)
	a.sort(reverse=True)
	ans = 0
	for j in range(0, len(a), 2):
		ans += a[j]
	if len(a) == 0:
		print(0)
	else:
		print(ans)


t = int(input())
for i in range(0, t):
	str1 = input()
	x = len(str1)
	j = 0
	ct = 0
	l1 = []
	while j < x:
		if str1[j] == '0':
			if ct != 0:
				l1.append(ct)
				ct = 0
			j += 1
		else:
			while j < x and str1[j] == '1':
				ct += 1
				j += 1
				if j == x and str1[j - 1] == '1':
					l1.append(ct)
	y = len(l1)
	if y == 0:
		print('0')
	else:
		ans = 0
		l1.sort(reverse=True)
		for k in range(0, y, 2):
			ans = ans + l1[k]
		print(ans)


t = int(input())
for test in range(t):
	stri = input()
	ones = []
	curr = 0
	for i in stri:
		if i == '0':
			if curr != 0:
				ones.append(curr)
				curr = 0
		else:
			curr += 1
	if curr != 0:
		ones.append(curr)
	ones.sort(reverse=True)
	count = 0
	for i in range(0, len(ones), 2):
		count += ones[i]
	print(count)


import sys
input = lambda : sys.stdin.readline().strip()
char = [chr(i) for i in range(97, 123)]
CHAR = [chr(i) for i in range(65, 91)]
mp = lambda : list(map(int, input().split()))
INT = lambda : int(input())
rn = lambda : range(INT())
from math import ceil, sqrt, factorial, gcd
for _ in rn():
	k = input().split('0')
	l = []
	c = 0
	for i in k:
		if i != '':
			l.append(len(i))
	l = sorted(l, reverse=True)
	ans = 0
	for j in range(len(l)):
		if j % 2 == 0:
			ans += l[j]
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	n = input()
	i = 0
	ll = []
	while i < len(n):
		count = 0
		while i < len(n) and n[i] == '1':
			i += 1
			count += 1
		i += 1
		ll.append(count)
	ll.sort(reverse=True)
	s = 0
	for j in range(len(ll)):
		if j % 2 == 0:
			s += ll[j]
	print(s)


from itertools import groupby
for _ in range(int(input())):
	x = [(k, len(list(g))) for (k, g) in groupby(input())]
	y = []
	for k in x:
		if k[0] == '1':
			y.append(k[1])
	f = sorted(y, reverse=True)[0::2]
	print(sum(f))


t = int(input())
for _ in range(t):
	s = input().split('0')
	c = []
	for i in s:
		c.append(len(i.strip('0')))
	c = sorted(c, reverse=True)
	ans = 0
	for i in range(0, len(c), 2):
		ans += c[i]
	print(ans)


for _ in range(int(input())):
	arr = list(input())
	count = 0
	st = []
	for i in range(len(arr)):
		if arr[i] == '1':
			count += 1
		elif count != 0:
			st.append(count)
			count = 0
	if count != 0:
		st.append(count)
		count = 0
	st = sorted(st, reverse=True)
	ans = 0
	for i in range(len(st)):
		if i % 2 == 0:
			ans += st[i]
	print(ans)


def pontuacao(palavra):
	pontos = [0]
	indice = 0
	streak = False
	pontos_de_alice = 0
	for letra in palavra:
		if letra == '1':
			pontos[indice] += 1
			streak = True
		elif streak == True:
			indice += 1
			pontos.append(0)
			streak = False
	pontos.sort(reverse=True)
	for n in range(0, len(pontos), 2):
		pontos_de_alice += pontos[n]
	return pontos_de_alice
numero_casos_de_teste = int(input())
casos = []
for i in range(numero_casos_de_teste):
	casos.append(input())
for caso in casos:
	print(pontuacao(caso))


a = int(input())
lst = []
d = 0
lst2 = []
for i in range(a):
	b = input()
	d = 0
	e = 0
	for j in range(0, len(b)):
		if b[j] == '1':
			d += 1
		else:
			lst.append(d)
			d = 0
	lst.append(d)
	lst.sort(reverse=True)
	j = 0
	while j < len(lst):
		e = lst[j] + e
		j += 2
	lst2.append(e)
	lst = []
for i in lst2:
	print(i)


for _ in range(int(input())):
	a = input()
	n = len(a)
	h = 1
	cnt = [0] * (10 ** 3 + 1)
	cur = 0
	for x in a:
		if x == '1':
			cur += 1
		else:
			cnt[cur] += 1
			cur = 0
	if cur > 0:
		cnt[cur] += 1
	ans = 0
	for i in range(n):
		j = n - i
		if cnt[j] > 0:
			ans += j * ((h + cnt[j]) // 2)
		if cnt[j] % 2 == 1:
			h ^= 1
	print(ans)


for _ in range(int(input())):
	s = input()
	p = 0
	s1 = list()
	for i in s:
		if i == '1':
			p += 1
		else:
			if p > 0:
				s1.append(p)
			p = 0
	s1.append(p)
	s1.sort(reverse=True)
	(a, b) = (0, 0)
	for i in range(len(s1)):
		if i & 1:
			b += s1[i]
		else:
			a += s1[i]
	print(a)


n = int(input())
for i in range(n):
	string = input()
	mylist = []
	counter = 0
	for element in string:
		if element == '1':
			counter += 1
		elif counter != 0:
			mylist.append(counter)
			counter = 0
	if counter == 3:
		pass
	mylist.append(counter)
	mylist = sorted(mylist)
	sum2 = 0
	length = len(mylist) - 1
	for j in range(length, -1, -2):
		sum2 += mylist[j]
	print(sum2)


for _ in range(int(input())):
	s = list(input().split('0'))
	n = len(s)
	a = []
	for i in s:
		if len(i) > 0 and i[0] == '1':
			a.append(len(i))
	a.sort()
	res = 0
	i = len(a) - 1
	while i >= 0:
		res += a[i]
		i -= 2
	print(res)


t = int(input())
for you in range(t):
	s = input()
	l = []
	counter = 0
	for i in range(len(s)):
		if s[i] == '1':
			counter += 1
		else:
			l.append(counter)
			counter = 0
	l.append(counter)
	l.sort()
	l.reverse()
	n = len(l)
	sumi = 0
	for i in range(0, n, 2):
		sumi += l[i]
	print(sumi)


import re
ls = lambda : list(map(int, input().split()))
ip = lambda : int(input())
sip = lambda : input()
r = lambda a: range(a)
lcm = lambda a, b: abs(a * b) // math.gcd(a, b)
t = ip()
for _ in r(t):
	s = sip()
	ones = {}
	m = 0
	for i in s:
		if i == '0' and m != 0:
			if m in ones:
				ones[m] += 1
			else:
				ones[m] = 1
			m = 0
		if i == '1':
			m += 1
	if m != 0:
		if m in ones:
			ones[m] += 1
		else:
			ones[m] = 1
	alice = 0
	turn = 0
	for i in sorted(ones.keys(), reverse=True):
		if ones[i] % 2 == 0 and turn == 0:
			alice += i * (ones[i] // 2)
			turn = 0
		elif ones[i] % 2 == 0 and turn == 1:
			alice += i * (ones[i] // 2)
			turn = 1
		elif ones[i] % 2 != 0 and turn == 0:
			alice += i * (ones[i] // 2 + 1)
			turn = 1
		else:
			alice += i * (ones[i] // 2)
			turn = 0
	print(alice)


import math
from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for i in range(I()):
	s = input()
	a = list(s.split('0'))
	a.sort(reverse=True)
	ans = 0
	for i in range(len(a)):
		if i % 2 == 0:
			ans += len(a[i])
	print(ans)


from itertools import groupby
t = int(input())
for _ in range(t):
	s = input()
	a = [[x, len(list(y))] for (x, y) in groupby(s)]
	pp = []
	for x in a:
		if x[0] == '1':
			pp.append(x[1])
	pp.sort(reverse=True)
	ans = 0
	for x in range(len(pp)):
		if x % 2 == 0:
			ans = ans + pp[x]
	print(ans)


t = int(input())
while t:
	t -= 1
	b = input()
	from itertools import groupby
	groups = groupby(b)
	result = [(label, sum((1 for _ in group))) for (label, group) in groups]
	x = []
	for i in result:
		if i[0] == '1':
			x.append(int(i[1]))
	x.sort()
	k = 0
	al = 0
	for i in range(len(x) - 1, -1, -1):
		if k == 0:
			al += x[i]
			k = 1
		elif k == 1:
			k = 0
	print(al)


test = int(input())
for _t in range(test):
	s = input()
	l = s.split('0')
	n = len(l)
	arr = []
	for i in range(n):
		if len(l[i]) > 0:
			arr.append(l[i])
	arr = sorted(arr, reverse=True)
	ans = 0
	for i in range(len(arr)):
		if i % 2 == 0:
			ans += len(arr[i])
	print(ans)


import math
T = int(input())
lets = 'abcdefghijklmnopqrstuvwxyz'
key = {lets[i]: i for i in range(26)}
for i in range(T):
	a = input()
	os = []
	if a[0] == '1':
		o = 0
	else:
		o = False
	for i in a:
		if o and i == '0':
			os.append(o)
			o = False
		elif i == '1':
			o += 1
	if o:
		os.append(o)
	os.sort(reverse=True)
	ans = 0
	for j in range(len(os)):
		if j % 2 == 0:
			ans += os[j]
	print(ans)


for _ in range(int(input())):
	N = list(input())
	Z = len(N)
	counter = 0
	array = []
	for i in range(Z):
		if N[i] == '1':
			counter += 1
		elif counter != 0:
			array.append(counter)
			counter = 0
	array.append(counter)
	counter = 0
	array = sorted(array, reverse=True)
	X = len(array)
	total = 0
	for i in range(0, X, 2):
		total += array[i]
	print(total)


t = int(input())
for tt in range(t):
	ans = [len(s) for s in input().split('0') if len(s) > 0]
	ans.sort(reverse=True)
	print(sum(ans[::2]))


for __ in range(int(input())):
	S = input()
	L = sorted(S.split('0'), reverse=True)
	a = 0
	for i in range(len(L)):
		if i % 2 == 0:
			a += len(L[i])
	print(a)


import sys
import math
from sys import stdin, stdout

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

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

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

def main():
	for t in range(int(input())):
		s = input()
		n = len(s)
		l = []
		c = 0
		for i in range(0, n):
			if s[i] == '1':
				c = c + 1
			else:
				l.append(c)
				c = 0
		if s[-1] == '1':
			l.append(c)
		l.sort(reverse=True)
		z = 0
		for i in range(0, len(l), 2):
			z = z + l[i]
		print(z)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

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


t = int(input())
cnt = 0
while cnt < t:
	cnt += 1
	s = input()
	res = []
	tmp = 0
	for i in range(len(s)):
		if s[i] == '1':
			tmp += 1
		elif tmp > 0:
			res.append(tmp)
			tmp = 0
	if tmp > 0:
		res.append(tmp)
	res.sort()
	total = 0
	for i in range(len(res) - 1, -1, -2):
		total += res[i]
	print(total)


for _ in range(int(input())):
	lengths = list(map(len, input().split('0')))
	lengths.sort(reverse=True)
	print(sum(lengths[::2]))


t = int(input())
for _ in range(t):
	s = input()
	array = []
	count = 0
	for i in range(len(s)):
		if s[i] == '1':
			count += 1
		else:
			array.append(count)
			count = 0
		if count and i == len(s) - 1:
			array.append(count)
	array.sort(reverse=True)
	total = 0
	for i in range(0, len(array), 2):
		total += array[i]
	print(total)


t = int(input())
for _ in range(t):
	s = input()
	s += '0'
	a = []
	count = 0
	for x in s:
		if x == '1':
			count += 1
		elif count:
			a.append(count)
			count = 0
	a.sort(reverse=True)
	print(sum(a[::2]))


import itertools

def countstrs(s):
	return [(k, len(list(g))) for (k, g) in itertools.groupby(s)]
q = int(input())
for _ in range(q):
	s = input()
	l = countstrs(s)
	dat = []
	for i in range(len(l)):
		(a, cnt) = l[i]
		if a == '1':
			dat.append(cnt)
	dat.sort(reverse=True)
	res = 0
	for i in range(len(dat)):
		if i & 1 == 0:
			res += dat[i]
	print(res)


import math
for _ in range(int(input())):
	s = input()
	l = s.split('0')
	l.sort()
	c = 0
	n = len(l)
	for i in range(0, n, 2):
		if l[n - 1 - i] == '':
			break
		else:
			temp = l[n - 1 - i]
			c = c + len(temp)
	print(c)


t = int(input())
for i in range(t):
	st = input()
	j = 0
	alice = 0
	maxcnt = float('-inf')
	while st.count('1') > 0:
		cnt = 0
		maxcnt = 0
		for i in range(len(st)):
			if st[i] == '1':
				cnt += 1
			else:
				cnt = 0
			maxcnt = max(maxcnt, cnt)
		st = st.replace('1' * maxcnt, '', 1)
		if j % 2 == 0:
			alice += maxcnt
		j = j + 1
	print(alice)


def checker(s):
	s = s.split('0')
	lst = []
	for elem in s:
		if elem != '':
			lst.append(len(elem))
	a = sorted(lst, reverse=True)
	result = 0
	for i in range(0, len(a), 2):
		result += a[i]
	return result
for _ in range(int(input())):
	t = input()
	print(checker(t))


T = int(input())
while T:
	num = input()
	ones = []
	count = 0
	for i in num:
		if i == '1':
			count += 1
		elif i == '0' and count:
			ones.append(count)
			count = 0
	if count:
		ones.append(count)
	ones.sort(reverse=True)
	print(sum([ones[i] for i in range(0, len(ones), 2)]))
	T -= 1


t = int(input())
for _ in range(t):
	s = input()
	arr = [0] * len(s)
	vis = [False] * len(s)
	for i in range(0, len(s)):
		temp = 0
		zero = False
		for j in range(i, len(s)):
			if s[j] == '1' and (not vis[j]):
				temp += 1
				vis[j] = True
			else:
				zero = True
				break
		arr[i] += temp
		temp = 0
	sarr = sorted(arr, reverse=True)
	ans = 0
	for i in range(0, len(sarr), 2):
		ans += sarr[i]
	print(ans)


for _ in range(int(input())):
	s = str(input())
	cList = []
	i = -1
	while i < len(s) - 1:
		i += 1
		if s[i] == '1':
			c = 1
			if i < len(s) - 1:
				i += 1
				while s[i] == '1' and i < len(s) - 1:
					i += 1
					c += 1
				if i == len(s) - 1 and s[len(s) - 1] == '1' and (s[len(s) - 2] == '1'):
					c += 1
				elif i == len(s) - 1 and s[len(s) - 1] == '1' and (s[len(s) - 2] == '0'):
					c = 1
			cList.append(c)
	cList.sort(reverse=True)
	cList = cList[::2]
	print(sum(cList))


t = int(input())
for o in range(0, t):
	str = input()
	l = []
	i = 0
	n = len(str)
	while i < n:
		if str[i] == '1':
			val = str[i]
			count = 1
			i += 1
			while i < n and val == str[i]:
				count += 1
				i += 1
			l.append(count)
		else:
			i += 1
	l.sort(reverse=True)
	k = len(l)
	score = 0
	for i in range(0, k, 2):
		score += l[i]
	print(score)


for t in range(int(input())):
	s = list(filter(lambda x: x > 0, list(map(len, input().split('0')))))
	s = sorted(s, reverse=True)
	ans = 0
	for (i, v) in enumerate(s):
		if i % 2 == 0:
			ans = ans + v
	print(ans)


t = int(input())
for _ in range(t):
	string = list(input())
	ones = []
	count = 0
	for i in range(0, len(string)):
		if string[i] == '1':
			count += 1
		elif string[i] == '0':
			count = 0
		try:
			if string[i] == '1' and string[i + 1] == '1' or string[i] == '0':
				ones.append(0)
			if string[i] == '1' and string[i + 1] == '0':
				ones.append(count)
		except:
			if string[i] == '1':
				ones.append(count)
			if string[i] == '0':
				ones.append(0)
	ones.sort(reverse=True)
	print(sum(ones[::2]))


t = int(input())
while t:
	t -= 1
	s = input()
	l = []
	c = 0
	for i in s:
		if i == '1':
			c += 1
		elif i == '0' and c != 0:
			l.append(c)
			c = 0
	l.append(c)
	l.sort(reverse=True)
	alice = 0
	for i in range(len(l)):
		if i % 2 == 0:
			alice += l[i]
	print(alice)


for i in range(int(input())):
	a = list(input())
	d = []
	c = 0
	for b in range(len(a)):
		if a[b] == '1':
			c += 1
		else:
			if c > 0:
				d.append(c)
			c = 0
	if c > 0:
		d.append(c)
	d = sorted(d, reverse=True)
	e = d[::2]
	print(sum(e))


for _ in range(int(input())):
	s = input()
	(ans, c) = (0, 0)
	l = []
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
		else:
			l.append(c)
			c = 0
	l.append(c)
	l.sort()
	for j in range(len(l) - 1, -1, -2):
		ans += l[j]
	print(ans)


for _ in range(int(input())):
	s = input()
	L = []
	count = 0
	if '1' in s:
		for ch in s[s.index('1'):]:
			if ch == '1':
				count += 1
			else:
				L.append(count)
				count = 0
		L.append(count)
		L.sort(reverse=True)
		ans = 0
		for i in L[::2]:
			ans += i
		print(ans)
	else:
		print(0)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
for _ in range(L()[0]):
	s = input()
	A = s.split('0')
	ans = []
	for ele in A:
		if '1' in ele:
			ans.append(ele)
	a = 0
	b = 0
	ans.sort(reverse=True)
	i = 0
	while ans:
		if i % 2 == 0:
			a += len(ans[0])
		else:
			b += len(ans[0])
		del ans[0]
		i += 1
	print(a)


import sys
from sys import stdin
import math

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

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

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

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

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

def flinput():
	return list(map(int, stdin.readline().strip().split()))
for _ in range(iinput()):
	s = input()
	ll = []
	c = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
		elif c > 0:
			ll.append(c)
			c = 0
		else:
			c = 0
	if c > 0:
		ll.append(c)
	ss = 0
	ll.sort(reverse=True)
	for i in range(len(ll)):
		if i % 2 == 0:
			ss += ll[i]
	print(ss)


T = int(input())
for cas in range(T):
	s = [len(e) for e in input().split('0')]
	s.sort(reverse=True)
	ans = 0
	for i in range(0, len(s), 2):
		ans += s[i]
	print(ans)


def max_cos(array):
	max_streak = 0
	streak = 0
	for current in array:
		if current == '1':
			streak += 1
		else:
			max_streak = max(max_streak, streak)
			streak = 0
	max_streak = max(max_streak, streak)
	return max_streak
for _ in range(int(input())):
	inarray = input()
	alice = 0
	alice_turn = True
	max1 = max_cos(inarray)
	while max1 != 0:
		if alice_turn:
			alice += max1
			alice_turn = False
		else:
			alice_turn = True
		inarray = inarray.replace('1' * max1, '', 1)
		max1 = max_cos(inarray)
	print(alice)


t = int(input())
for i in range(0, t):
	l = list(input())
	s = 0
	p = []
	m = 0
	for i in l:
		if i == '1':
			s = s + 1
		elif s > 0:
			p.append(s)
			s = 0
	if s > 0:
		p.append(s)
	p.sort(reverse=True)
	for i in range(0, len(p), 2):
		m = m + p[i]
	print(m)


t = int(input())
for _ in range(t):
	s = input()
	ct = []
	i = 0
	while i < len(s):
		if s[i] == '1':
			c = 0
			while s[i] == '1':
				c = c + 1
				i = i + 1
				if i == len(s):
					break
			ct.append(c)
		else:
			i = i + 1
	ct.sort()
	i = len(ct) - 1
	ans = 0
	while i >= 0:
		ans = ans + ct[i]
		i = i - 2
	print(ans)


t = int(input())
while t > 0:
	lst = []
	s = input()
	i = 0
	while i < len(s):
		if s[i] == '1':
			j = i
			while j < len(s) and s[j] == '1':
				j += 1
			lst.append(j - i)
			i = j
		else:
			i += 1
	lst = sorted(lst, reverse=True)
	ans = 0
	for i in range(len(lst)):
		if i % 2 == 0:
			ans += lst[i]
	print(ans)
	t -= 1


for i in range(int(input())):
	a = input()
	(c, f, ans) = (0, 0, 0)
	l = []
	for i in a:
		if f == 0 and i == '1':
			f = 1
		elif f == 1 and i == '0':
			l.append(c)
			c = 0
			f = 0
		if f:
			c += 1
	if c != 0:
		l.append(c)
	l.sort(reverse=1)
	j = 0
	while j < len(l):
		if j % 2 == 0:
			ans += l[j]
		j += 1
	print(ans)


T = int(input())
for t in range(T):
	s = input()
	ctr = 0
	track = []
	for i in s:
		if i == '0':
			track.append(ctr)
			ctr = 0
		else:
			ctr += 1
	track.append(ctr)
	count = 0
	track.sort()
	for i in range(len(track) - 1, -1, -2):
		count += track[i]
	print(count)


import sys
input = sys.stdin.readline

def inInt():
	return int(input())

def inStr():
	return input().strip('\n')

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

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

def solve(nums):
	ones = nums.split('0')
	res = [i for i in ones if i != '']
	lens = [len(i) for i in res]
	a = 0
	turn = True
	while lens:
		if turn:
			a += max(lens)
			lens.remove(max(lens))
			turn = False
		else:
			lens.remove(max(lens))
			turn = True
	print(a)
t = inInt()
for case in range(t):
	nums = inStr()
	solve(nums)


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

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

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 10 ** 7 + 1
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

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
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

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

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

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

def string_list():
	return list(input())

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

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

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def solve():
	s = input()
	n = len(s)
	count = []
	i = 0
	while i < n:
		if s[i] == '0':
			i += 1
			continue
		c = 1
		j = i + 1
		while j < n and s[j] == '1':
			c += 1
			j += 1
		i = j
		count.append(c)
	count.sort(reverse=True)
	ans = 0
	for i in range(0, len(count), 2):
		ans += count[i]
	print(ans)
t = 1
t = int(input())
for _ in range(t):
	solve()


from collections import deque
from math import *
import heapq
from random import *
import sys
from copy import deepcopy
t = int(input())
for i in range(t):
	l = list(input())
	c = 0
	L = []
	for j in range(len(l)):
		if l[j] == '1':
			c += 1
		elif c != 0 and l[j] == '0':
			L.append(c)
			c = 0
	if c != 0:
		L.append(c)
	L = sorted(L, reverse=True)
	SUM = 0
	for j in range(0, len(L), 2):
		SUM += L[j]
	print(SUM)


t = int(input())
while t > 0:
	t -= 1
	s = input()
	n = len(s)
	l = list(s)
	l2 = []
	cnt = 0
	prev = 0
	for i in range(n):
		prev = cnt
		if i == 0:
			if l[i] == '1':
				cnt += 1
			else:
				cnt = 0
		elif l[i] == '1' and l[i - 1] == '0' and (cnt == 0):
			cnt += 1
		elif l[i] == '1' and l[i - 1] == '1':
			cnt += 1
		else:
			cnt = 0
		if cnt == 0 and prev > 0:
			l2.append(prev)
	if cnt > 0:
		l2.append(cnt)
	ans = 0
	if len(l2) > 0:
		l2.sort(reverse=True)
		for i in range(0, len(l2), 2):
			ans += l2[i]
	else:
		ans = 0
	print(ans)


for t in range(int(input())):
	s = [len(i) for i in input().split('0')]
	s.sort()
	print(sum(s[-1::-2]))


t = int(input())
for x in range(t):
	s = input()
	score = 0
	move = 1
	while s.count('1') > 0:
		max_streak = 0
		if move % 2 == 1:
			temp = ''
			streak = 0
			for x in s:
				if x == '1':
					streak += 1
					if streak > max_streak:
						temp += x
						max_streak = streak
				else:
					streak = 0
			score += len(temp)
			s = s.replace(temp, '', 1)
		else:
			temp = ''
			streak = 0
			for x in s:
				if x == '1':
					streak += 1
					if streak > max_streak:
						temp += x
						max_streak = streak
				else:
					streak = 0
			s = s.replace(temp, '', 1)
		move += 1
	print(score)


def main():
	t = int(input())
	for case in range(t):
		s = input()
		scores = []
		score = 0
		for char in s:
			if char == '1':
				score += 1
			if char == '0':
				if score != 0:
					scores.append(score)
					score = 0
		scores.append(score)
		alice = 0
		for score in sorted(scores, reverse=True)[::2]:
			alice += score
		print(alice)
	return
main()


for _ in range(int(input())):
	s = input()
	alice = 0
	arr = s.split('0')
	arr.sort(key=lambda x: len(x), reverse=True)
	for i in range(len(arr)):
		if i % 2 == 0:
			alice += len(arr[i])
	print(alice)


for _ in range(int(input())):
	s = input()
	count = 0
	A = []
	for i in range(0, len(s)):
		if s[i] == '1':
			count = count + 1
		else:
			if count > 0:
				A.append(count)
			count = 0
	if s[len(s) - 1] == '1' and count != 0:
		A.append(count)
	A = sorted(A, reverse=True)
	summ = 0
	for i in range(0, len(A), 2):
		summ = summ + A[i]
	print(summ)


for _ in range(int(input())):
	stk = list()
	counts = list()
	s = list(input().strip())
	for i in range(len(s)):
		if s[i] == '1':
			stk.append(1)
		if s[i] == '0' and len(stk) != 0 or i == len(s) - 1:
			counts.append(sum(stk))
			stk.clear()
	print(sum(sorted(counts, reverse=True)[::2]))


n = int(input())
for i in range(n):
	s = input()
	me = True
	res = 0
	while True:
		beg = 0
		plus = 0
		max_plus = 0
		mbeg = 0
		mend = 0
		for j in range(len(s)):
			if s[j] == '1':
				plus += 1
				if plus == 1:
					beg = j
			else:
				if max_plus < plus:
					max_plus = plus
					mend = j
					mbeg = beg
				plus = 0
		if max_plus < plus:
			max_plus = plus
			if s[j] == '1':
				mend = j + 1
			else:
				mend = j
			mbeg = beg
		s = s[:mbeg] + s[mend:]
		if me:
			res += max_plus
		me = me ^ True
		if max_plus == 0 or len(s) == 0:
			break
	print(res)


import sys
from os import path
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def runLengthEncode(message):
	count = 0
	previous_char = message[0]
	result = ''
	char_count_dict = {}
	for i in range(len(message)):
		character = message[i]
		if previous_char == character:
			count = count + 1
		else:
			if previous_char in char_count_dict:
				char_count_dict[previous_char].append(count)
			else:
				char_count_dict[previous_char] = [count]
			result = result + str(count) + previous_char
			count = 1
		previous_char = character
	if previous_char in char_count_dict:
		char_count_dict[previous_char].append(count)
	else:
		char_count_dict[previous_char] = [count]
	result = result + str(count) + str(previous_char)
	return (result, char_count_dict)

def solve():
	s = input()
	(msg, counts) = runLengthEncode(s)
	if '1' in counts:
		a = sorted(counts['1'], reverse=True)
		print(sum(a[::2]))
	else:
		print(0)

def main():
	tc = int(input().strip())
	for case in range(tc):
		solve()
main()


for _ in range(int(input())):
	a = input()
	b = []
	c = 0
	for i in a:
		if i == '1':
			c += 1
		else:
			b.append(c)
			c = 0
	b.append(c)
	b = sorted(b, reverse=True)
	s = 0
	for i in range(0, len(b), 2):
		s += b[i]
	print(s)


t = int(input())
for _ in range(t):
	s = input()
	A = []
	count = 0
	for x in s:
		if x == '1':
			count += 1
		else:
			if count > 0:
				A.append(count)
			count = 0
	if count > 0:
		A.append(count)
	A.sort()
	ans = 0
	for (i, x) in enumerate(A[::-1]):
		if i % 2 == 0:
			ans += x
	print(ans)


def cout(arr):
	t = []
	i = 0
	while i < len(arr):
		k = 0
		if arr[i] == '1':
			while arr[i] == '1':
				k += 1
				i += 1
				if i >= len(arr):
					break
		t.append(k)
		i = i + 1
	return t

def klm(arr):
	if len(arr) == 0:
		return 0
	else:
		arr = sorted(arr, reverse=True)
		t = 0
		for i in range(0, len(arr), 2):
			t = t + arr[i]
		return t
t = int(input())
for i in range(t):
	k = input()
	t = cout(k)
	print(klm(t))


def run():
	mystr = list(input())
	flag = 1
	score = 0
	cont = mystr.count('1')
	if not cont:
		print(0)
		return
	while cont > 0:
		n = len(mystr)
		ret = [0, -1, -1]
		ans = [0, -1, -1]
		for i in range(n):
			if mystr[i] == '1':
				ret[0] += 1
				if ret[1] == -1:
					ret[1] = i
					ret[-1] = i
				if ret[1] != -1:
					ret[-1] = i
			else:
				if ans[0] < ret[0]:
					ans = ret[:]
				ret = [0, -1, -1]
		if ans[0] < ret[0]:
			ans = ret[:]
		if ans[1] == 0:
			mystr = mystr[ans[-1] + 1:]
		elif ans[-1] == n - 1:
			mystr = mystr[:ans[1]]
		else:
			mystr = mystr[:ans[1]] + mystr[ans[-1] + 1:]
		cont -= ans[0]
		if flag == 1:
			score += ans[0]
			flag = 0
		else:
			flag = 1
	print(score)
n = int(input())
for i in range(n):
	run()


for _ in range(int(input())):
	s = input()
	ar = []
	cur = 0
	for c in s:
		if c == '1':
			cur += 1
		else:
			ar.append(cur)
			cur = 0
	if cur != 0:
		ar.append(cur)
	ar.sort()
	ar.reverse()
	print(sum(ar[::2]))


import sys

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	intStr = input()
	nums = [0]
	for char in intStr:
		if char == '1':
			nums[-1] += 1
		elif char == '0' and nums[-1] > 0:
			nums.append(0)
	nums.sort()
	print(sum(nums[-1::-2]))


import heapq

def solve(s):
	count = 0
	heap = []
	for c in s:
		if c == '0':
			if count > 0:
				heap.append(count)
			count = 0
		else:
			count += 1
	if count > 0:
		heap.append(count)
	ans = 0
	heap.sort(reverse=True)
	for i in range(len(heap)):
		if i % 2 == 0:
			ans += heap[i]
	return ans
t = int(input())
while t:
	s = input()
	print(solve(s))
	t -= 1


mod = 10 ** 9 + 7

def solve():
	s = input() + '0'
	ret = []
	tmp = 0
	for i in range(len(s)):
		if s[i] == '1':
			tmp += 1
		else:
			if tmp > 0:
				ret.append(tmp)
			tmp = 0
	ret.sort(reverse=True)
	ans = 0
	for i in range(0, len(ret), 2):
		ans += ret[i]
	print(ans)
t = 1
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	s = input()
	l = []
	i = 0
	while i < len(s):
		f = 0
		if s[i] == '1':
			c = 0
			while i < len(s) and s[i] == '1':
				c += 1
				i += 1
				f = 1
			l.append(c)
		if f == 0:
			i += 1
	l.sort(reverse=True)
	n = len(l)
	k = len(l)
	if n == 0:
		print(0)
	else:
		if n % 2 == 0:
			n = n // 2
		else:
			n = n // 2 + 1
		c = 0
		z = 0
		for i in range(k):
			if i % 2 == 0:
				c += l[i]
				z += 1
			if z == n:
				break
		print(c)


for t in range(int(input())):
	s = input()
	a = []
	k = 0
	for i in range(len(s)):
		if s[i] == '1':
			k += 1
			if i == len(s) - 1:
				if k != 0:
					a.append(k)
		else:
			if k != 0:
				a.append(k)
			k = 0
	a.sort()
	ans = 0
	for i in range(len(a) - 1, -1, -2):
		ans += a[i]
	print(ans)


for i in range(int(input())):
	s = input()
	arr = []
	temp_count = 0
	for i in range(len(s)):
		if s[i] == '1':
			temp_count += 1
		elif temp_count:
			arr.append(temp_count)
			temp_count = 0
	if temp_count:
		arr.append(temp_count)
		temp_count = 0
	arr.sort()
	print(sum([arr[i] for i in range(len(arr) - 1, -1, -2)]))


for _ in ' ' * int(input()):
	print(sum(map(len, sorted(input().split('0'))[::-2])))


import itertools

def check(s):
	a = []
	c = 0
	for i in s:
		if i == '1':
			c += 1
		else:
			if c != 0:
				a.append(c)
			c = 0
	if c != 0:
		a.append(c)
	(x, y) = (0, 0)
	a.sort()
	while len(a) > 0:
		x += a[-1]
		a.pop(-1)
		if len(a) == 0:
			break
		y += a[-1]
		a.pop(-1)
	print(x)
for _ in range(int(input())):
	string = input()
	check(string)


t = int(input())
for _ in range(t):
	arr = input().split('0')
	ans = [len(i) for i in arr]
	ans.sort(reverse=True)
	count = 0
	n = len(ans)
	for i in range(0, n, 2):
		count += ans[i]
	print(count)


from collections import defaultdict as dd
from sys import stdin, stdout
for t in range(int(stdin.readline().strip())):
	s = input()
	a = []
	if s[0] == '1':
		a.append(1)
	n = len(s)
	for i in range(1, n):
		if s[i] == '1':
			if s[i - 1] == '1':
				a[-1] += 1
			else:
				a.append(1)
	a.sort(reverse=True)
	n = len(a)
	c = 0
	for i in range(0, n, 2):
		c += a[i]
	print(c)


import sys

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

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

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

def ws(s):
	sys.stdout.write(s)
	sys.stdout.write('\n')

def wi(n):
	sys.stdout.write(str(n))
	sys.stdout.write('\n')

def wia(a, sep=' '):
	sys.stdout.write(sep.join([str(x) for x in a]))
	sys.stdout.write('\n')

def solve(s):
	n = len(s)
	g = []
	i = 0
	while i < n:
		if s[i] == '0':
			i += 1
		else:
			j = i
			while j < n and s[j] == '1':
				j += 1
			g.append(j - i)
			i = j + 1
	g.sort(reverse=True)
	return sum(g[::2])

def main():
	for _ in range(ri()):
		s = rs()
		wi(solve(s))
main()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	a = input()
	c = []
	b = 0
	for i in range(len(a)):
		if a[i] == '1':
			b += 1
		else:
			if b != 0:
				c.append(b)
			b = 0
	if b != 0:
		c.append(b)
	c.sort(reverse=True)
	print(sum(c[::2]))


def alice(s):
	if s.count('1') == 0:
		return 0
	s = s.split('0')
	s.sort(reverse=True)
	cnt = 0
	for i in range(0, len(s), 2):
		if len(s[i]) > 0:
			cnt += len(s[i])
		else:
			break
	return cnt
t = int(input())
for _ in range(t):
	result = alice(input())
	print(result)


for t in range(int(input())):
	a = int(input())
	A = list(str(a))
	b = []
	while len(A) > 0:
		ali = 0
		for i in range(len(A)):
			if A[0] == '0':
				A.pop(0)
				break
			elif A[0] == '1':
				ali += 1
				A.pop(0)
		b.append(ali)
	b.sort()
	b.reverse()
	c = b[::2]
	print(sum(c))


import heapq
for _ in range(int(input())):
	s = input()
	n = len(s)
	i = 0
	q = []
	while i < n:
		cnt = 0
		while i + cnt < n and s[i + cnt] == s[i]:
			cnt += 1
		if s[i] == '1':
			heapq.heappush(q, -cnt)
		i += cnt
	i = 0
	ans = 0
	while len(q) > 0:
		t = heapq.heappop(q)
		if i % 2 == 0:
			ans -= t
		i += 1
	print(ans)


import sys, math, heapq, collections, itertools, bisect
sys.setrecursionlimit(101000)

def solve(s):
	(prev, cnt) = (False, 0)
	s += '0'
	groups = []
	for c in s:
		if c == '1':
			cnt += 1
		else:
			if cnt:
				groups.append(cnt)
			cnt = 0
	groups.sort()
	take = True
	sol = 0
	while groups:
		x = groups.pop()
		if take:
			sol += x
		take = not take
	return sol
t = int(input())
for _ in range(t):
	s = input()
	print(solve(s))


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	l = list(map(int, input().strip()))
	n = len(l)
	ll = []
	lol = 1
	su = 1
	if l[0] == 0:
		lol = 0
		su = 0
	for i in range(1, n):
		if l[i] == l[i - 1] and lol == 1:
			su += 1
		elif l[i] == 1:
			lol = 1
			su = 1
		elif lol == 1:
			ll.append(su)
			lol = 0
			su = 0
	if lol:
		ll.append(su)
	ll.sort(reverse=True)
	ans = 0
	for i in range(0, len(ll), 2):
		ans += ll[i]
	print(ans)
	t -= 1


for _ in range(int(input())):
	s = input()
	cnt = 1
	total = []
	s += '-1'
	for i in range(len(s) - 1):
		if s[i] == '1' and s[i + 1] == '1':
			cnt += 1
		else:
			if cnt != 1:
				total.append(cnt)
			elif s[i] == '1':
				total.append(cnt)
			cnt = 1
	total.sort(reverse=True)
	ans = 0
	for i in range(len(total)):
		if i % 2 == 0:
			ans += total[i]
	print(ans)


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	s = input()
	blocks = []
	c = 0
	for i in s:
		if i == '1':
			c += 1
		elif c:
			blocks += [c]
			c = 0
	if c:
		blocks += [c]
	sb = sorted(blocks, reverse=True)
	ans = 0
	for i in range(len(sb)):
		if i % 2 == 0:
			ans += sb[i]
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	ls = s.split('0')
	l = [len(i) for i in ls]
	sl = sorted(l)
	rsl = reversed(sl)
	ans = 0
	for (i, length) in enumerate(rsl):
		if i % 2 == 0:
			ans += length
	print(ans)


test_cases = int(input())
for test_case in range(test_cases):
	s = input()
	ans = 0
	max = 0
	count = 0
	one = []
	for i in range(len(s) - 1):
		if s[i] == '1':
			if count == 0:
				count = 1
			if s[i] == s[i + 1]:
				count += 1
		else:
			one.append(count)
			count = 0
	if count == 0 and s[-1] == '1':
		one.append(1)
	else:
		one.append(count)
	one.sort(reverse=True)
	for i in range(len(one)):
		if one[i] == 0:
			break
		if i % 2 == 0:
			ans += one[i]
	print(ans)


def funcao(lista):
	maior = (-1, -1)
	i = 0
	j = 0
	while j < len(lista):
		if lista[j] == '0':
			if i != j:
				if maior[1] - maior[0] < j - i:
					maior = (i, j)
			j += 1
			i = j
		else:
			if j == len(lista) - 1:
				if maior[1] - maior[0] < j + 1 - i:
					maior = (i, j + 1)
			j += 1
	return maior
t = int(input())
res = []
k = 0
while k < t:
	lista = list(input())
	cont = 0
	flag = 'a'
	while True:
		maior = funcao(lista)
		if maior[1] - maior[0] == 0:
			break
		else:
			del lista[maior[0]:maior[1]]
			if flag == 'a':
				cont += maior[1] - maior[0]
				flag = 'b'
			else:
				flag = 'a'
	res.append(cont)
	k += 1
for e in res:
	print(e)


def longest1(arr):
	brr = arr[:]
	brr.append('0')
	c = 0
	maxx = 0
	start = 0
	for i in range(len(brr)):
		if brr[i] == '1':
			c += 1
		else:
			if maxx < c:
				maxx = c
				start = i - c
			c = 0
	if maxx != 0:
		return [start, start + maxx]
	else:
		return -1

def solve(l):
	x = longest1(l)
	f = []
	while x != -1 and len(l) != 0:
		(start, end) = (x[0], x[1])
		f.append(end - start)
		l = l[0:start] + l[end:]
		x = longest1(l)
	alice = sum(f[0:len(f):2])
	print(alice)
for _ in range(int(input())):
	s = input()
	l = list(s)
	solve(l)


inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
inst = lambda : input().decode().rstrip('\n\r')
INF = float('inf')
_T_ = inin()
for _t_ in range(_T_):
	s = input().split('0')
	an = 0
	a = []
	for i in s:
		a.append(len(i))
	a.sort(reverse=True)
	for i in range(len(a)):
		if i % 2 == 0:
			an += a[i]
	print(an)


t = int(input())
for _ in range(t):
	s = input()
	flag = '2'
	count = {'0': {}, '1': {}}
	ptr = 0
	ones = 0
	for (i, c) in enumerate(s):
		if c != flag:
			flag = c
			ptr = i
			count[flag][ptr] = 1
		else:
			count[flag][ptr] += 1
		if flag == '1':
			ones += 1
	alice = True
	score = 0
	while ones > 0:
		m = list(dict.keys(count['1']))[0]
		for key in count['1']:
			if count['1'][key] > count['1'][m]:
				m = key
		if alice:
			score = score + count['1'][m]
		ones = ones - count['1'][m]
		del count['1'][m]
		alice = not alice
	print(score)


for _ in range(int(input())):
	s = str(input())
	l = []
	c = 0
	for i in s:
		if i == '1':
			c += 1
		else:
			if c != 0:
				l.append(c)
			c = 0
	if c != 0:
		l.append(c)
	c = 0
	n = len(l)
	l.sort()
	for i in range(1, n, 2):
		c += l[i]
	ans = c
	c = 0
	for i in range(0, n, 2):
		c += l[i]
	print(max(c, ans))


t = int(input())
for _ in range(t):
	s = input()
	l = []
	prev = '0'
	ct = 0
	for i in range(len(s)):
		if s[i] == '1':
			ct += 1
		else:
			if ct != 0:
				l.append(ct)
			ct = 0
	if s[-1] == '1':
		l.append(ct)
	l.sort(reverse=True)
	score = 0
	for i in range(0, len(l), 2):
		score += l[i]
	print(score)


import re
for _ in range(int(input())):
	s = input()
	ls = re.findall('1+', s)
	if len(ls) == 0:
		print(0)
		continue
	count = 0
	a = sorted(ls, key=lambda x: len(x), reverse=True)
	for i in range(0, len(a), 2):
		count += len(a[i])
	print(count)


t = int(input())
for i in range(t):
	s = input()
	sd = s.split('0')
	for j in range(len(sd)):
		sd[j] = len(sd[j])
	sd.sort(reverse=True)
	sda = sd[::2]
	print(sum(sda))


T = int(input())
for t in range(T):
	s = '0' + input() + '0'
	A = []
	tmp = 0
	n = len(s)
	for i in range(n):
		if s[i] == '1':
			tmp += 1
		elif tmp > 0:
			A.append(tmp)
			tmp = 0
	A = sorted(A, reverse=True)
	ans = 0
	m = len(A)
	for i in range(0, m, 2):
		ans += A[i]
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	reading_1 = False
	count = 0
	subs = []
	for c in s:
		if c == '0':
			if not reading_1:
				continue
			if reading_1:
				reading_1 = False
				subs.append(count)
				count = 0
		if c == '1':
			if not reading_1:
				reading_1 = True
			count += 1
	if reading_1:
		subs.append(count)
	subs.sort(reverse=True)
	print(sum(subs[::2]))


import math
t = int(input())
for i in range(t):
	num = input()
	arr = num.strip('0').split('0')
	arr = sorted([int(math.log10(int(n))) + 1 for n in arr if n != ''], reverse=True)
	s = 0
	i = 0
	while i < len(arr):
		s += arr[i]
		i += 2
	print(s)


from sys import stdin
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()
for _ in range(t):
	a = gbs()
	for i in range(1, len(a)):
		if a[i]:
			a[i] += a[i - 1]
			a[i - 1] = 0
	a.sort(reverse=True)
	ans = 0
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)


from sys import stdin, stdout
from collections import Counter
from math import ceil
from bisect import bisect_left
from bisect import bisect_right
import math
ai = lambda : list(map(int, stdin.readline().split()))
ei = lambda : map(int, stdin.readline().split())
ip = lambda : int(stdin.readline().strip())
for i in range(ip()):
	s = input().split('0')
	ans = []
	for i in s:
		if i != '':
			ans.append(i)
	final = []
	for i in range(len(ans)):
		final.append(ans[i].count('1'))
	final = sorted(final, reverse=True)
	x = len(final)
	y = 0
	for i in range(0, x, 2):
		y += final[i]
	print(y)


t = int(input())
for case in range(t):
	s = input()
	score = 0
	is_turn = True
	while s and '1' in s:
		turn_score = 0
		for i in range(len(s), 0, -1):
			tmp = '1' * i
			if tmp in s:
				turn_score = i
				s = s.replace(tmp, '', 1)
				break
		if is_turn:
			score += turn_score
		is_turn = not is_turn
	print(score)


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import defaultdict
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

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

def IO():
	return stdin.readline()

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

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

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

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

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

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return
mod = 10 ** 9 + 7

def solve():
	s = input()
	arr = []
	n = len(s)
	i = 0
	while i < n:
		if s[i] == '1':
			cnt = 0
			j = i
			while j < n and s[j] == '1':
				cnt += 1
				j += 1
			arr.append(cnt)
			i = j
		else:
			i += 1
	arr.sort(reverse=True)
	ans = 0
	for i in range(0, len(arr), 2):
		ans += arr[i]
	P(ans)
	return
t = II()
for i in range(t):
	solve()


t = int(input())
for aaa in range(t):
	s = input()
	n = len(s)
	a = []
	r = 0
	e = 0
	y = 0
	for i in range(n):
		k = s[i]
		if k == '1':
			e += 1
		else:
			y += 1
			a.append(e)
			e = 0
	if e > 0:
		y += 1
		a.append(e)
	a.sort(reverse=True)
	for i in range(y):
		if i % 2 == 0:
			r += a[i]
	print(r)


try:
	for i1 in range(int(input())):
		s = '0' + input() + '0'
		c = 0
		ans = []
		start = 0
		k = 0
		i = 0
		for i in range(len(s)):
			if s[i] == '0':
				start = i
				if c > 0:
					ans.append(c)
				c = 0
			else:
				c = i - start
		answer = 0
		ans.sort()
		ans.reverse()
		for i in range(len(ans)):
			if i % 2 == 0:
				answer += ans[i]
		print(answer)
except:
	pass


import sys

def inp():
	inp = input().split()
	if len(inp) == 1:
		return int(inp[0])
	else:
		return (int(i) for i in inp)

def inpl():
	inp = input().split()
	for i in range(len(inp)):
		inp[i] = int(inp[i])
	return inp
testcases = inp()
for testcase in range(testcases):
	s = input().split('0')
	for i in range(len(s)):
		s[i] = len(s[i])
	s.sort(reverse=True)
	turn = True
	ans = 0
	for i in s:
		if turn:
			ans += i
		turn = not turn
	print(ans)


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(inp()):
	s = input().strip()
	prev = -1
	x = []
	for i in range(len(s)):
		if s[i] == '1' and prev != '1':
			x.append(1)
		elif s[i] == '1':
			x[-1] += 1
		prev = s[i]
	x.sort(reverse=True)
	ans = 0
	for i in range(0, len(x), 2):
		ans += x[i]
	print(ans)


from math import *
from collections import *
from random import *
from decimal import Decimal
from heapq import *
from bisect import *
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 5)

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

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

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

def st1():
	return input().rstrip('\n')
t = inp()
while t:
	t -= 1
	a = st1()
	oe = []
	c = 0
	for i in a:
		if i == '1':
			c += 1
		elif c != 0:
			oe.append(c)
			c = 0
	if c:
		oe.append(c)
	s = 0
	oe.sort(reverse=True)
	for i in range(len(oe)):
		if i % 2 == 0:
			s += oe[i]
	print(s)


t = int(input())
for i in range(0, t):
	s = input()
	scores = []
	score = 0
	for j in range(0, len(s)):
		if not int(s[j]):
			if score:
				scores.append(score)
				score = 0
			continue
		else:
			score += 1
	if score:
		scores.append(score)
	players = [0, 0]
	p = 0
	while scores:
		players[p] += max(scores)
		scores.remove(max(scores))
		p = (p + 1) % 2
	print(max(players))


t = int(input())
for _ in range(t):
	s = input()
	s = s.split('0')
	a = []
	for i in s:
		a.append(len(i))
	a.sort()
	a.reverse()
	ret = 0
	turn = 0
	for i in a:
		if turn % 2 == 0:
			ret += i
		turn += 1
	print(ret)


t = int(input())
while t:
	s = input()
	l = []
	i = 0
	n = len(s)
	while i < n:
		count = 0
		while i < n and s[i] == '1':
			count += 1
			i += 1
		l.append(count)
		i += 1
	l.sort(reverse=True)
	n = len(l)
	ans = 0
	for i in range(0, n, 2):
		ans += l[i]
	print(ans)
	t -= 1


t = int(input())
for tt in range(t):
	s = input()
	tamanhos = []
	i = 0
	while i < len(s):
		if s[i] == '1':
			point1 = i
			point2 = point1
			j = i + 1
			while j < len(s):
				if s[j] == '1':
					point2 = j
					j += 1
				else:
					break
			i = j
			tamanhos.append(point2 - point1 + 1)
		else:
			i += 1
	tamanhos.sort(reverse=True)
	s = 0
	for i in range(0, len(tamanhos)):
		if i % 2 == 0:
			s += tamanhos[i]
	print(s)


def score(s):
	r = 0
	m = 0
	for i in range(0, len(s)):
		if s[i] == '1':
			r += 1
		else:
			m = max(r, m)
			r = 0
	m = max(m, r)
	p = s.index('1' * m)
	s = s[:p] + s[p + m + 1:]
	return (s, m)
for _ in range(int(input())):
	a = 0
	b = 0
	s = input()
	n = len(s)
	while '1' in s:
		(s, at) = score(s)
		a += at
		(s, bt) = score(s)
	print(a)


T = int(input())
for i in range(T):
	arr = list(input())
	Ones = []
	(curr, prev, total) = (0, 0, 0)
	for i in range(len(arr)):
		curr = arr[i]
		if curr == '1':
			if prev == '1':
				total += 1
			else:
				Ones.append(total)
				total = 1
		prev = curr
	Ones.append(total)
	Ones = sorted(Ones, reverse=True)
	Alice = 0
	for i in range(len(Ones)):
		if i % 2 == 0:
			Alice += Ones[i]
	print(Alice)


N = int(input())
s = []
for _ in range(N):
	s.append(input())
for n in range(N):
	ones = []
	count = 0
	for c in s[n]:
		if c == '1':
			count += 1
		elif count:
			ones.append(count)
			count = 0
	if count:
		ones.append(count)
	movessorted = sorted(ones, reverse=True)
	print(sum(movessorted[0::2]))


import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def inc(d, c):
	d[c] = d[c] + 1 if c in d else 1

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

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

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

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < n

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
while t > 0:
	t -= 1
	s = si()
	n = len(s)
	i = 0
	d = []
	while i < n:
		j = i
		while j < n and s[j] == '1':
			j += 1
		d.append(j - i)
		i = j + 1
	n = len(d)
	a = b = 0
	d.sort(reverse=True)
	for i in range(n):
		if i % 2 == 0:
			a += d[i]
		else:
			b += d[i]
	print(a)


for _ in range(int(input())):
	sring = input()
	arr = []
	cnt = 0
	for c in sring:
		if c == '1':
			cnt += 1
		elif cnt != 0:
			arr.append(cnt)
			cnt = 0
	if cnt:
		arr.append(cnt)
	arr.sort(reverse=True)
	alice = 0
	for i in range(0, len(arr), 2):
		alice += arr[i]
	print(alice)


import re
for _ in range(int(input())):
	s = input()
	lst = []
	for m in re.finditer('(1)\\1*', s):
		lst.append(m.end() - m.start())
	lst.sort()
	lst.reverse()
	res = 0
	for i in range(0, len(lst), 2):
		res += lst[i]
	print(res)


for _ in range(int(input())):
	s = input()
	s += '@'
	c = 1
	n = len(s)
	a = []
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			c += 1
		else:
			if s[i] == '1':
				a.append(c)
			c = 1
	a.sort()
	m = len(a)
	ans = 0
	for i in range(m - 1, -1, -2):
		ans += a[i]
	print(ans)


t = int(input())
for j in range(t):
	list1 = list(input())
	list2 = []
	ct = 0
	for j in list1:
		if j == '1':
			ct += 1
		else:
			list2.append(ct)
			ct = 0
	list2.append(ct)
	ct = 0
	sum1 = 0
	list2 = sorted(list2, reverse=True)
	for k in list2:
		if ct & 1 == 0:
			sum1 += k
		if not k:
			break
		ct += 1
	print(sum1)


import math
import sys
from collections import Counter
from math import factorial as fact
from collections import defaultdict

def inpint():
	return int(input())

def inpstr():
	return str(input())

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

def inptup():
	return map(int, input().strip().split())
for _ in range(int(input())):
	s = str(input())
	flag = False
	a = 0
	b = 0
	arr = []
	for i in s:
		if i == '1':
			a += 1
		else:
			arr.append(a)
			a = 0
	arr.append(a)
	if len(arr):
		arr.sort()
	for i in range(len(arr) - 1, -1, -2):
		b += arr[i]
	print(b)


def fun(s):
	n = s.count('1')
	if n == 1:
		return [1]
	elif n == 0:
		return []
	i = 1
	result = []
	flag = 0
	if s[0] == '1':
		flag = 1
		start = 0
	while i < len(s):
		if s[i] == '1' and s[i - 1] == '0':
			start = i
			flag = 1
		if s[i] == '0' and s[i - 1] == '1' and (flag == 1):
			result.append(i - start)
			flag = 0
		i += 1
	if flag == 1:
		result.append(len(s) - start)
	return result
for _ in range(int(input())):
	s = input()
	l = fun(s)
	if l == []:
		print(0)
	else:
		su = 0
		l.sort(reverse=True)
		for i in range(len(l)):
			if i % 2 == 0:
				su += l[i]
		print(su)


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


def bins(s):
	x = s.split('0')
	A = []
	for i in x:
		if i:
			A.append(i)
	A.sort(key=lambda s: len(s))
	sum = 0
	while A:
		sum += len(A.pop())
		if A:
			A.pop()
	return sum
t = int(input())
for i in range(t):
	s = input()
	print(bins(s))


for i in range(int(input())):
	s = str(input())
	n = '0' + s + '0'
	a = []
	c = []
	ans = 0
	for i in range(len(n)):
		if n[i] == '0':
			a.append(i)
	for i in range(len(a) - 1):
		if a[i + 1] - a[i] > 1:
			c.append(a[i + 1] - a[i] - 1)
	c.sort()
	for i in range(len(c) - 1, -1, -2):
		ans += c[i]
	print(ans)


te = int(input())
for t in range(te):
	s = input()
	z = []
	if set(s) == {'1'}:
		print(len(s))
	else:
		for i in range(len(s)):
			if s[i] == '0':
				z.append(i)
		a = []
		a.append(z[0])
		for i in range(1, len(z)):
			a.append(z[i] - z[i - 1] - 1)
		a.append(len(s) - z[len(z) - 1] - 1)
		a.sort()
		c = 0
		for i in range(len(a) - 1, -1, -2):
			c += a[i]
		print(c)


ts = int(input())
strs = [input() for t in range(ts)]
strs = [s.split('0') for s in strs]
strs = [sorted([len(s1) for s1 in s if len(s1) > 0], reverse=True) for s in strs]
scores = [sum([s[i] for i in range(0, len(s), 2)]) for s in strs]
list(map(print, scores))


def func():
	s = input()
	s = str('0' + s + '0')
	count_ones = []
	alice_score = 0
	end = 0
	start = 0
	ctr = 0
	while end > -1 and start > -1 and (ctr < 10):
		start = s.find('1', end + 1)
		end = s.find('0', start) - 1
		if end > -1 and start > -1:
			count_ones.append(end - start + 1)
	count_ones.sort(reverse=True)
	for i in range(0, len(count_ones), 2):
		alice_score += count_ones[i]
	print(alice_score)
T = int(input())
for _ in range(T):
	func()


for i in range(int(input())):
	a = sum(sorted([len(i) for i in input().split('0')], reverse=True)[::2])
	print(a)


for _ in range(int(input())):
	s = input()
	i = 0
	v = []
	while i < len(s):
		if s[i] == '1':
			j = i
			cnt = 0
			while j < len(s) and s[j] == '1':
				cnt += 1
				j += 1
			i = j
			v.append(cnt)
		i += 1
	v.sort(reverse=True)
	summ = 0
	for i in range(0, len(v), 2):
		summ += v[i]
	print(summ)


t = int(input())
for _ in range(t):
	l = input().split('0')
	l.sort(reverse=True)
	ans = 0
	for i in range(0, len(l), 2):
		ans += len(l[i])
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	cur = 0
	l = []
	for i in range(len(s)):
		if s[i] == '1':
			cur += 1
		else:
			l.append(cur)
			cur = 0
	l.append(cur)
	l.sort(reverse=True)
	print(sum(l[::2]))


t = int(input())
for i in range(t):
	s = input()
	past = s[0]
	count = []
	pile = []
	for j in s:
		if j == past:
			pile.append(j)
		else:
			count.append([past, len(pile)])
			pile = []
			pile.append(j)
			past = j
	count.append([past, len(pile)])
	alice = 0
	one = []
	for y in count:
		if y[0] == '1':
			one.append(int(y[1]))
	one.sort(reverse=True)
	alice = sum(one[0::2])
	print(alice)


t = int(input())
for i in range(t):
	l = input().split('0')
	l1 = []
	for i in l:
		if len(i):
			l1.append(len(i))
	l1.sort(reverse=True)
	ans = 0
	for j in range(0, len(l1), 2):
		ans += l1[j]
	print(ans)


def solve(s):
	n = len(s)
	ones = []
	seq = 0
	for i in range(n):
		if s[i] == '1':
			seq += 1
			if i == n - 1 or s[i + 1] == '0':
				ones.append(seq)
				seq = 0
	ones.sort(reverse=True)
	turn = 0
	score = 0
	for i in ones:
		if turn % 2 == 0:
			score += i
		turn += 1
	return score
T = int(input())
for _ in range(T):
	s = input()
	ans = solve(s)
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	a = 0
	b = 0
	s = s.split('0')
	s.sort(reverse=True)
	for i in range(len(s)):
		if i % 2 == 0:
			a += len(s[i])
	print(a)


t = int(input())
while t:
	l = input().split('0')
	l.sort()
	l.reverse()
	count = 0
	for i in range(len(l)):
		if i % 2 == 0:
			count += l[i].count('1')
	print(count)
	t -= 1


for _ in ' ' * int(input()):
	s = 0
	for x in sorted(input().split('0'))[::-1][::2]:
		s += len(x)
	print(s)


def maxones(s):
	st = -1
	end = -1
	score = 0
	i = 0
	mlen = -1
	while i < len(s):
		if s[i] == '1':
			curst = i
			curlen = 1
			i += 1
			while i < len(s) and s[i] == s[i - 1]:
				i += 1
				curlen += 1
			if curlen > mlen:
				mlen = curlen
				st = curst
				end = i
		else:
			i += 1
	score = mlen
	return (st, end, score)

def checkone(s):
	for i in range(len(s)):
		if s[i] == '1':
			return True
	return False
n = int(input())
for i in range(n):
	s = input()
	k = 0
	alscore = 0
	while checkone(s):
		k += 1
		(stpnt, endpnt, sc) = maxones(s)
		if k % 2 != 0:
			alscore += sc
		if endpnt != len(s) - 1:
			s = s[:stpnt] + s[endpnt + 1:]
		else:
			s = s[:stpnt]
	print(alscore)


for i in range(int(input())):
	s = input()
	(l, p, c) = ([], 0, 0)
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
		else:
			l.append(c)
			c = 0
	if c > 0:
		l.append(c)
	l.sort(reverse=True)
	for i in range(0, len(l), 2):
		p = p + l[i]
	print(p)


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	s = inp()
	a = list(s)
	ones = []
	longest = 0
	for i in range(len(a)):
		if a[i] == '1':
			longest += 1
		elif a[i] == '0' and longest > 0:
			ones.append(longest)
			longest = 0
	ones.append(longest)
	ones.sort(reverse=True)
	tmp = [int(ones[i]) for i in range(len(ones)) if i % 2 == 0]
	print(sum(tmp))


t = int(input())
for i in range(0, t):
	s = list(input().split('0'))
	s.sort(reverse=True)
	a = s[0::2]
	p = ''.join(a)
	print(len(p))


for _ in range(int(input())):
	s = input() + '#'
	c = 1
	ans = []
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			c += 1
		else:
			if s[i - 1] == '1':
				ans.append(c)
			c = 1
	ans.sort(reverse=True)
	c = 1
	fin = 0
	for i in ans:
		if c:
			fin += i
		c ^= 1
	print(fin)


T = int(input())
for t in range(T):
	s = input()
	(l, i) = ([], 0)
	while i < len(s):
		if s[i] == '1':
			j = i + 1
			while j < len(s):
				if s[j] == '1':
					j += 1
				else:
					break
			l.append(j - i)
			i = j
		else:
			i += 1
	if len(l) == 0:
		print(0)
	else:
		l.sort(reverse=True)
		sc = 0
		for i in range(0, len(l), 2):
			sc += l[i]
		print(sc)


import sys
input = sys.stdin.readline
from collections import deque
from heapq import *
t = int(input())
for _ in range(t):
	s = list(map(int, input().strip()))
	a = deque(s)
	ans = []
	i = 0
	while i < len(s):
		if s[i] == 1:
			h = i
			while i < len(s) and s[i] == 1:
				i += 1
			hh = i - 1
			ans.append(hh - h + 1)
		i += 1
	ans.sort(reverse=True)
	print(sum(ans[::2]))


for t in range(int(input())):
	nstr = input()
	l1 = []
	n1 = 0
	count = 0
	ans1 = 0
	for i in range(len(nstr)):
		if nstr[i] == '1':
			count += 1
		else:
			l1.append(count)
			n1 += 1
			count = 0
	l1.append(count)
	l1 = sorted(l1, reverse=True)
	for i in range(len(l1)):
		if i % 2 == 0:
			n1 = 4 + 2
			ans1 += l1[i]
	print(ans1)


t = int(input())
for _ in range(t):
	a = list(input())
	n = len(a)
	d = []
	i = 0
	while i < n:
		j = i
		if a[i] == '1':
			count = 0
			if i == n - 1:
				d.append(1)
				break
			while j < n:
				if a[j] == '1':
					count += 1
				else:
					break
				j += 1
			d.append(count)
		i = j + 1
	d.sort(reverse=True)
	ans = 0
	for i in range(0, len(d), 2):
		ans += d[i]
	print(ans)


import sys
import math
import time
from functools import lru_cache
from collections import Counter
import heapq

def pw(a, b, m):
	a %= m
	ans = 1
	if a == 0:
		return 0
	while b > 0:
		if b & 1:
			ans = ans * a % m
		b = b // 2
		a = a * a % m
	return ans
try:
	for _ in range(int(input())):
		s = input()
		n = len(s)
		ptr = 0
		ans = []
		while ptr < n:
			if s[ptr] == '1':
				tem = 0
				while ptr < n and s[ptr] == '1':
					tem += 1
					ptr += 1
				ans.append(tem)
			ptr += 1
		ans.sort(reverse=True)
		sm = 0
		for i in range(len(ans)):
			if i % 2 == 0:
				sm += ans[i]
		print(sm)
except EOFError as e:
	print(e)


T = int(input())
for t in range(T):
	S = input()
	i = 0
	arr = []
	while i < len(S):
		if S[i] == '1':
			cnt = 0
			while i < len(S) and S[i] == '1':
				cnt += 1
				i += 1
			arr.append(cnt)
		else:
			i += 1
	arr = sorted(arr)
	arr.reverse()
	ans = 0
	for i in range(0, len(arr), 2):
		ans += arr[i]
	print(ans)


import sys
T = int(sys.stdin.readline().strip())
for t in range(0, T):
	s = sys.stdin.readline().strip()
	l = len(s)
	a = []
	c = 0
	for i in range(0, l):
		if s[i] == '1':
			c = c + 1
		else:
			a.append(c)
			c = 0
	a.append(c)
	a.sort()
	a.reverse()
	ans = 0
	for i in range(0, len(a)):
		if i % 2 == 0:
			ans = ans + a[i]
	print(ans)


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	s = stdin.readline().split('0')
	s.sort(key=lambda x: -x.count('1'))
	alice = 0
	for i in range(len(s)):
		if i % 2 == 0:
			alice += s[i].count('1')
	print(alice)


for t in range(int(input())):
	s = input().strip()
	c = 0
	a = []
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
		else:
			a.append(c)
			c = 0
	if c > 0:
		a.append(c)
	a.sort(reverse=1)
	ans = 0
	for i in range(len(a)):
		if i % 2 == 0:
			ans += a[i]
	print(ans)


cases = int(input())
for i in range(cases):
	s = input()
	turn = 0
	alice = 0
	ls = list(s)
	while '1' in ls:
		if turn % 2 == 0:
			if '0' not in ls:
				alice += len(ls)
				break
			count = 0
			temp = []
			index = []
			ind = []
			for j in range(len(ls)):
				c = ls[j]
				if c == '1':
					count += 1
					index.append(j)
				elif c == '0':
					if count == 0:
						continue
					else:
						temp.append(count)
						ind.append(index)
						count = 0
						index = []
			if count > 0:
				temp.append(count)
				ind.append(index)
			alice += max(temp)
			for k in ind:
				if len(k) == max(temp):
					for kk in k:
						ls[kk] = '0'
					break
			turn += 1
		elif turn % 2 == 1:
			if '0' not in ls:
				break
			count = 0
			temp = []
			index = []
			ind = []
			for j in range(len(ls)):
				c = ls[j]
				if c == '1':
					count += 1
					index.append(j)
				elif c == '0':
					if count == 0:
						continue
					else:
						temp.append(count)
						ind.append(index)
						count = 0
						index = []
			if count > 0:
				temp.append(count)
				ind.append(index)
			for k in ind:
				if len(k) == max(temp):
					for kk in k:
						ls[kk] = '0'
					break
			turn += 1
	print(alice)


import itertools
t = int(input())
for _ in range(t):
	s = input()
	cnt = []
	for (ch, g) in itertools.groupby(s):
		if ch == '1':
			cnt.append(len(list(g)))
	a = 0
	for (i, c) in enumerate(sorted(cnt, reverse=True)):
		if i % 2 == 0:
			a += c
	print(a)


for _ in range(int(input())):
	C = []
	S = input()
	s = 0
	for c in S:
		if c == '0':
			if s:
				C.append(s)
				s = 0
		else:
			s += 1
	if s:
		C.append(s)
	C.sort(reverse=True)
	print(sum(C[::2]))


t = int(input())
for i in range(t):
	d = input()
	l = len(d)
	alice = 0
	bob = 0
	c = 1
	while '1' in d:
		for i in range(l):
			if (l - i) * '1' in d:
				while (l - i) * '1' in d:
					if c % 2 == 1:
						alice += l - i
						c += 1
					else:
						bob += l - i
						c += 1
					p = d.index((l - i) * '1')
					d = d[0:p] + d[p + l - i:]
	print(alice)


t = int(input())
for i in range(t):
	string = input()
	cont = 0
	resp = []
	for j in string:
		if j == '1':
			cont += 1
		elif j == '0' and cont > 0:
			resp.append(cont)
			cont = 0
	if cont > 0:
		resp.append(cont)
	resp.sort()
	resp.reverse()
	soma = 0
	for j in range(0, len(resp), 2):
		soma += resp[j]
	print(soma)


import sys, heapq
tc = int(sys.stdin.readline())
for _ in range(tc):
	a = sys.stdin.readline().rstrip()
	st = list(a)
	size = 0
	poss = []
	while st:
		if st[-1] == '1':
			size += 1
		else:
			heapq.heappush(poss, (-size, size))
			size = 0
		st.pop()
	if size > 0:
		heapq.heappush(poss, (-size, size))
	turn = 1
	ans = 0
	while poss:
		temp = heapq.heappop(poss)[1]
		if turn % 2 == 1:
			ans += temp
		turn += 1
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	b = []
	for j in s:
		b.append(int(j))
	c = []
	n = len(b)
	j = 0
	cn = 0
	while j < n:
		if b[j] == 0:
			c.append(cn)
			cn = 0
		else:
			cn += 1
		j += 1
	c.append(cn)
	c.sort(reverse=True)
	j = 0
	ans = 0
	while j < len(c):
		if j % 2 == 0:
			ans += c[j]
		j += 1
	print(ans)


import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
	return int(input())

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

def rl():
	return list(map(int, input().split()))
for _ in range(r()):
	a = input()
	b = []
	if a[0] == '1':
		b.append(1)
	stop = False
	for i in range(1, len(a)):
		if a[i] == '1':
			if a[i] == a[i - 1]:
				b[-1] += 1
			else:
				b.append(1)
	b.sort(reverse=True)
	cnt = 0
	go = True
	for i in b:
		if go:
			cnt += i
		go = not go
	print(cnt)


def substring(a):
	c = []
	count = 0
	for i in range(len(a)):
		if i == '0' and a[i] == '1':
			count = 1
			continue
		elif a[i] == '1' and a[i - 1] == '1':
			count += 1
		elif a[i] == '1' and a[i - 1] == '0':
			count = 1
		elif a[i] == '0' and count > 0:
			c.append(count)
			count = 0
	if count != 0:
		c.append(count)
	c.sort(reverse=True)
	ans = 0
	for i in range(0, len(c), 2):
		ans += c[i]
	return ans
test = int(input())
for i in range(test):
	s = input()
	print(substring(s))


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

def array_print(arr):
	print(' '.join(map(str, arr)))
import sys
INF = sys.maxsize
for t in range(int(input())):
	s = list(input())
	ascore = 0
	n = len(s)
	alice = 1
	while True:
		max_count = 0
		count = 0
		index = 0
		for i in range(n):
			if s[i] == '1' and (count == 0 or s[i - 1] == '0'):
				count = 1
			elif s[i] == '1':
				count += 1
			else:
				if count > max_count:
					index = i
					max_count = count
				count = 0
		if count > max_count:
			max_count = count
			index = n
		if max_count == 0:
			break
		if alice & 1 == 1:
			ascore += max_count
		alice += 1
		if max_count < n:
			for i in range(max_count):
				s.pop(index - max_count)
			n -= max_count
		else:
			break
	print(ascore)


for _ in range(int(input())):
	s = input()
	(A, c) = ([], 0)
	for i in s:
		if i == '1':
			c += 1
		else:
			if c:
				A.append(c)
			c = 0
	if c:
		A.append(c)
	A.sort()
	A.reverse()
	S = 0
	for i in range(len(A)):
		if i % 2 == 0:
			S += A[i]
	print(S)


for _ in range(int(input())):
	n = input()
	con = []
	count = 0
	for i in range(0, len(n)):
		if n[i] == '0':
			con.append(count)
			count = 0
		else:
			count += 1
	con.append(count)
	con.sort(reverse=True)
	alice = 0
	bob = 0
	for i in range(len(con)):
		if i % 2 == 0:
			alice += con[i]
		else:
			bob += con[i]
	print(alice)


import sys
input = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	s = input()
	lens = []
	run_type = ''
	run = 0
	for c in s:
		if c == run_type:
			run += 1
		else:
			if run_type == '1':
				lens.append(run)
			run = 1
			run_type = c
	if run_type == '1':
		lens.append(run)
	lens.sort(reverse=True)
	print(sum((lens[i] for i in range(0, len(lens), 2))))


for _ in range(int(input())):
	s = input()
	l = s.split('0')
	a = []
	for i in range(len(l)):
		if l[i].count('1') > 0:
			a.append(l[i].count('1'))
	a.sort(reverse=True)
	i = 0
	ans = 0
	while i < len(a):
		ans += a[i]
		i += 2
	print(ans)


for _ in range(int(input())):
	s = input()
	l = []
	x = 0
	n = len(s)
	for i in range(n):
		if s[i] == '1':
			x += 1
		else:
			l.append(x)
			x = 0
	if s[-1] == '1':
		l.append(x)
	l.sort(reverse=True)
	print(sum(l[::2]))


for _ in range(int(input())):
	arr = list(input())
	(alice, bob) = (1, 0)
	ans = 0
	i = 0
	while i < len(arr):
		l_max = 0
		s_indx = -1
		if arr[i] == '0':
			i += 1
		else:
			q = i
			m_ind = i
			while q < len(arr):
				j = q
				while j < len(arr) and arr[j] == '1':
					j += 1
				if j - q > l_max:
					l_max = j - q
					m_ind = q
				q = max(q + 1, j)
			if l_max == 0:
				break
			else:
				if alice == 1:
					ans += l_max
				alice = 1 - alice
				arr = arr[:m_ind] + arr[m_ind + l_max:]
				i = 0
	print(ans)


t = int(input())
for x in range(t):
	s = input()
	n = len(s)
	l = []
	i = 0
	while i < n:
		if s[i] == '1':
			j = i
			while j < n and s[j] == '1':
				j += 1
			l.append(j - i)
			i = j
		else:
			i += 1
	l.sort(reverse=True)
	out = 0
	for i in range(0, len(l), 2):
		out += l[i]
	print(out)


def findConsecutive(s, N):
	blocks = []
	c = 0
	flag = False
	for i in range(0, N):
		if flag and s[i] == '0':
			blocks.append(c)
			c = 0
			flag = False
		elif flag and s[i] == '1':
			c += 1
		elif flag == False and s[i] == '1':
			c = 1
			flag = True
	if c > 0:
		blocks.append(c)
	return blocks

def Run():
	s = input()
	N = len(s)
	blocks = sorted(findConsecutive(s, N), reverse=True)
	m = len(blocks)
	ans = 0
	for i in range(0, m, 2):
		ans += blocks[i]
	print(ans)
T = int(input())
for x in range(0, T):
	Run()


t = int(input())
for i in range(t):
	s = input()
	arr = []
	count = 0
	for i in s:
		if i == '1':
			count = count + 1
		if i == '0':
			if count != 0:
				arr.append(count)
			count = 0
	if count:
		arr.append(count)
	arr.sort()
	arr.reverse()
	sumi = 0
	for i in range(0, len(arr), 2):
		sumi = sumi + arr[i]
	print(sumi)


for _ in range(int(input())):
	a = input()
	if '0' in set(a) and '1' not in set(a):
		print(0)
	elif '1' in set(a) and '0' not in set(a):
		print(len(a))
	else:
		i = 0
		alice = 0
		bob = 0
		while '0' in set(a) and '1' in set(a):
			if i % 2 == 0:
				s = a.split('0')
				e = len(max(s))
				a = a.replace(max(s), '', 1)
				alice += e
				i += 1
			else:
				s = a.split('0')
				e = len(max(s))
				a = a.replace(max(s), '', 1)
				bob += e
				i += 1
		print(alice)


t = int(input())
for _ in range(t):
	s = input()
	l = []
	c = 0
	sum = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
		elif c > 0:
			l.append(c)
			c = 0
	if c != 0:
		l.append(c)
	l.sort(reverse=True)
	for i in range(0, len(l), 2):
		sum += l[i]
	print(sum)


for _ in range(int(input())):
	s = input()
	s = list(s)
	count = 0
	ar = []
	for i in range(len(s)):
		if s[i] == '0' and i > 0 and (s[i - 1] == '1'):
			ar.append(count)
			count = 0
		elif s[i] == '1':
			count += 1
	if count != 0:
		ar.append(count)
	ar.sort(reverse=True)
	a = ar[::2]
	sum = 0
	for i in a:
		sum += i
	print(sum)


for _ in range(int(input())):
	s = list(map(str, input().split('0')))
	try:
		while True:
			s.remove('')
	except:
		pass
	s = sorted(s, reverse=True)
	lst = [len(v) for (i, v) in enumerate(s) if i % 2 == 0]
	print(sum(lst))


n = int(input())
for _ in range(n):
	s = input()
	cnt = 0
	a = []
	for i in range(len(s)):
		if s[i] == '1':
			cnt += 1
		else:
			a.append(cnt)
			cnt = 0
	if cnt != 0:
		a.append(cnt)
		cnt = 0
	a.sort(reverse=True)
	print(sum([a[i] for i in range(0, len(a), 2)]))


n = int(input())
for i in range(n):
	s = input()
	m = 0
	a = []
	for j in range(len(s)):
		if s[j] == '1':
			m += 1
			if j == len(s) - 1:
				a.append(m)
			continue
		if m != 0:
			a.append(m)
		m = 0
	a.sort(reverse=True)
	ans = 0
	for j in range(0, len(a), 2):
		ans += a[j]
	print(ans)


for i in range(int(input())):
	insert = input().split('0')
	lenArray = [len(_) for _ in insert]
	lenArray = sorted(lenArray, reverse=True)
	sum = 0
	for i in range(len(lenArray)):
		if i % 2 == 0:
			sum += lenArray[i]
	print(sum)


t = int(input())
for i in range(t):
	s = input()
	n = len(s)
	arr = []
	i = 0
	while i < n:
		if s[i] == '0':
			i = i + 1
		else:
			j = i
			count = 0
			while j < n and s[j] == '1':
				count = count + 1
				j = j + 1
			arr.append(count)
			i = j
	arr = sorted(arr)
	arr = arr[::-1]
	l = len(arr)
	count = 0
	for i in range(0, l, 2):
		count = count + arr[i]
	print(count)


T = int(input())
for t in range(T):
	A = input()
	con = False
	B = []
	for a in A:
		if a == '1':
			if con:
				B[-1] += 1
			else:
				B.append(1)
				con = True
		else:
			con = False
	B.sort(reverse=True)
	c = 0
	for i in range(len(B)):
		if i % 2 == 0:
			c += B[i]
	print(c)


for _ in range(int(input())):
	s = input()
	z = []
	c = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
		else:
			if c:
				z.append(c)
			c = 0
	if c:
		z.append(c)
	z.sort(reverse=True)
	su = 0
	if z:
		for i in range(0, len(z), 2):
			su += z[i]
	print(su)


T = int(input())
while T > 0:
	arr = input()
	part = []
	count = 0
	for i in range(len(arr)):
		if arr[i] == '0':
			if count != 0:
				part.append(count)
				count = 0
		else:
			count += 1
	if count > 0:
		part.append(count)
	part.sort(reverse=True)
	res = 0
	while len(part) > 0:
		res += part.pop(0)
		if len(part) > 0:
			part.pop(0)
	print(res)
	T -= 1


t = int(input())
while t:
	a = input()
	a = a + '0'
	l = []
	c = 0
	for ch in a:
		if ch == '1':
			c += 1
		else:
			l.append(c)
			c = 0
	l.sort(reverse=True)
	s = 0
	for i in range(0, len(l), 2):
		s += l[i]
	print(s)
	t -= 1


t = int(input())
for _ in range(t):
	s = input()
	s = s + '0'
	l = []
	x = 0
	for i in range(len(s)):
		if s[i] == '1':
			x += 1
		if s[i] == '0':
			l.append(x)
			x = 0
	l.sort(reverse=True)
	ans = 0
	for i in range(0, len(l), 2):
		ans += l[i]
	print(ans)


def maxOfAlice(s):
	lst = s.split('0')
	a = []
	for i in lst:
		if i != '':
			a.append(len(i))
	res = 0
	a.sort()
	for i in range(len(a) - 1, -1, -2):
		res += a[i]
	return res
t = int(input())
for i in range(t):
	s = input()
	print(maxOfAlice(s))


import math
for _ in range(int(input())):
	n = list(input())
	i = 0
	ans = []
	while i < len(n):
		c = 0
		while i < len(n) and n[i] == '1':
			c += 1
			i += 1
		if c == 0:
			i += 1
		else:
			ans.append(c)
	ans.sort(reverse=True)
	c = 0
	for i in range(len(ans)):
		if i % 2 == 0:
			c += ans[i]
	print(c)


n = int(input())
for k in range(n):
	s = input()
	nested_s = []
	s = list(map(lambda x: int(x), list(s)))
	lis_sep = []
	lis_com = []
	if sum(s) == len(s) or sum(s) == 0:
		des_lis = [s]
	else:
		for i in range(len(s) - 1):
			a = s[i]
			b = s[i + 1]
			if a != b and len(lis_com) == 0:
				lis_sep.append(a)
				nested_s.append(lis_sep)
				lis_sep = []
			elif a != b and len(lis_com) > 0:
				lis_com.append(a)
				nested_s.append(lis_com)
				lis_com = []
			elif a == b:
				lis_com.append(a)
		if len(lis_com) > 0 and s[-1] == lis_com[-1]:
			lis_com.append(s[-1])
			nested_s.append(lis_com)
		else:
			nested_s.append([s[-1]])
		des_lis = sorted(nested_s)[::-1]
	summation = 0
	for item in des_lis[::2]:
		summation += sum(item)
	print(summation)


for _ in range(int(input())):
	s = input() + '0'
	ans = []
	count = 1
	for i in range(len(s)):
		if s[i] == '1' and s[i + 1] == '1':
			count += 1
		elif s[i] == '1' and s[i + 1] == '0':
			ans.append(count)
		else:
			count = 1
	ans.sort(reverse=True)
	res = 0
	for i in range(0, len(ans), 2):
		res += ans[i]
	print(res)


import sys
import math
import collections
import heapq
import queue
import itertools
import functools
import operator
import time
readline = sys.stdin.readline
IPS = lambda : readline().rstrip()
IP = lambda : int(readline().rstrip())
MP = lambda : map(int, readline().split())
LS = lambda : list(map(int, readline().split()))

def solve():
	for _ in range(IP()):
		s = IPS()
		(arr, cnt) = ([], 0)
		for el in s:
			if el == '1':
				cnt += 1
			else:
				if cnt > 0:
					arr.append(cnt)
				cnt = 0
		if cnt > 0:
			arr.append(cnt)
		arr.sort(key=lambda x: -x)
		ans = 0
		for i in range(0, len(arr), 2):
			ans += arr[i]
		print(ans)
solve()


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 *
from copy 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))
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 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(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

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

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	s = list(inp())
	n = len(s)
	arr = []
	ind = -1
	for i in range(n):
		if i == n - 1:
			if s[i] == '0':
				if ind == -1:
					continue
				else:
					arr.append(i - ind)
			elif ind == -1:
				arr.append(1)
			else:
				arr.append(i - ind + 1)
			continue
		if s[i] == '1':
			if ind == -1:
				ind = i
			continue
		elif ind == -1:
			continue
		else:
			arr.append(i - ind)
			ind = -1
	arr = sorted(arr)[::-1]
	a = 0
	for i in range(0, len(arr), 2):
		a += arr[i]
	print(a)
testcase(int(inp()))


for _ in range(int(input())):
	s = input()
	a = []
	low_zero = -1
	h = False
	ans = 0
	for i in range(len(s)):
		if s[i] == '1':
			ans += 1
		else:
			a.append(ans)
			ans = 0
	a.append(ans)
	ans = 0
	k = len(a) - 1
	a.sort()
	if len(a) == 0:
		print(len(s))
	if len(a) >= 1:
		for k in range(0, len(a)):
			if len(a) > 0:
				eh = max(a)
				ans += eh
				a.remove(eh)
				if len(a) > 0:
					a.remove(max(a))
					continue
		print(ans)


t = int(input())
for g in range(t):
	s = input()
	c = d = 0
	l = []
	for i in s:
		if i == '0':
			if c > 0:
				l.append(c)
				c = 0
		else:
			c += 1
	if c > 0:
		l.append(c)
	l.sort()
	l.reverse()
	for j in range(0, len(l), 2):
		d += l[j]
	print(d)


for i in range(int(input())):
	s = sorted(input().split('0'))[::-1]
	cont = 0
	for j in range(len(s)):
		if j % 2 == 0:
			cont += len(s[j])
	print(cont)


t = int(input())
for i in range(t):
	s = [int(x) for x in str(input())]
	n = 1
	a = 0
	while n != 0:
		m = 0
		n = 0
		for j in range(len(s)):
			if s[j] == 1:
				m += 1
			else:
				if m > n:
					n = m
					o = j - m
				m = 0
		if m != 0:
			if m > n:
				n = m
				o = j - m + 1
		for j in range(n):
			s[o + j] = 0
			a += 1
		p = 0
		q = 0
		for j in range(len(s)):
			if s[j] == 1:
				p += 1
			else:
				if p > q:
					q = p
					o = j - p
				p = 0
		if p != 0:
			if p > q:
				q = p
				o = j - p + 1
		for j in range(q):
			s[o + j] = 0
	print(a)


import sys

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

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

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

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

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

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math
from collections import defaultdict
for _ in range(ri()):
	s = rs()
	a = b = 0
	x = 1
	l = []
	for i in range(len(s)):
		if s[i] == '1':
			a += 1
		else:
			l.append(a)
			a = 0
	l.append(a)
	a = b = 0
	l.sort(reverse=True)
	for i in l:
		if x % 2:
			a += i
		else:
			b += i
		x += 1
	print(a)


T = int(input())
for _ in range(T):
	S = input()
	N = len(S)
	ct = 0
	i = 0
	j = 0
	arr = []
	while i < N:
		ct = 0
		if S[i] == '1':
			ct += 1
			j = i + 1
			while j < N:
				if S[j] == '1':
					ct += 1
				else:
					break
				j += 1
			arr.append(ct)
			i = j
		else:
			i += 1
	arr.sort(reverse=True)
	ans = 0
	l = len(arr)
	for j in range(l):
		if j & 1 == 0:
			ans += arr[j]
	print(ans)


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


for tset in range(int(input())):
	l = input()
	p = []
	c = 0
	for i in l:
		if i == '0':
			p.append(c)
			c = 0
			continue
		else:
			c = c + 1
	if l[-1] == '1':
		p.append(c)
	p.sort()
	p = p[::-1]
	s = 0
	for i in range(0, len(p), 2):
		s = s + p[i]
	print(s)


import os
import sys
from collections import Counter
from io import BytesIO, IOBase

def main():
	for t in range(int(input())):
		s = input().rstrip()
		i = 0
		n = len(s)
		b = []
		while i < n:
			if s[i] == '1':
				l = 0
				j = i
				while s[j] == '1':
					l += 1
					j += 1
					if j >= n:
						break
				b.append(l)
				i = j - 1
			i += 1
		su = 0
		b.sort(reverse=True)
		for i in range(0, len(b), 2):
			su += b[i]
		print(su)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


for _ in range(int(input())):
	l = input()
	s = []
	c = 0
	for i in l:
		if i == '0':
			s.append(c)
			c = 0
		else:
			c += 1
	if l[-1] == '1':
		s.append(c)
	s.sort(reverse=True)
	print(sum(s[0::2]))


t = int(input())
for _ in range(t):
	s = input()
	one = list()
	cnt = 0
	for i in range(len(s)):
		if s[i] == '1':
			cnt += 1
		else:
			if cnt != 0:
				one.append(cnt)
			cnt = 0
	if cnt != 0:
		one.append(cnt)
	one.sort(reverse=True)
	cnt = 0
	for i in range(0, len(one), 2):
		cnt += one[i]
	print(cnt)


for _ in range(int(input())):
	s = input()
	ones = 0
	arr = []
	for i in s:
		if i == '0' and ones != 0:
			arr.append(ones)
			ones = 0
		elif i == '1':
			ones += 1
	if ones != 0:
		arr.append(ones)
	arr.sort(reverse=True)
	score = 0
	for i in range(len(arr)):
		if i % 2 == 0:
			score += arr[i]
	print(score)


for _ in range(int(input())):
	s = input()
	ans = []
	k = 0
	for i in range(len(s)):
		if s[i] == '1':
			k += 1
		else:
			ans.append(k)
			k = 0
	ans.append(k)
	ans = sorted(ans)
	f = 0
	for i in range(len(ans) - 1, -1, -2):
		f += ans[i]
	print(f)


for _ in range(int(input())):
	s = input()
	l = s.split('0')
	l = list(filter(lambda a: a != '', l))
	l = [len(i) for i in l]
	ans = 0
	l.sort(reverse=True)
	for i in range(0, len(l), 2):
		ans += l[i]
	print(ans)


for _ in range(int(input())):
	s = input()
	scores = []
	temp = 1 if s[0] == '1' else 0
	n = 0
	for i in range(1, len(s)):
		if s[i] == '1':
			temp += 1
		elif s[i - 1] == '1':
			scores.append(temp)
			n += 1
			temp = 0
	if s[-1] == '1':
		scores.append(temp)
		n += 1
	ans = 0
	scores.sort()
	for i in range(n - 1, -1, -2):
		ans += scores[i]
	print(ans)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

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

def si():
	return input()

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

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
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 ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

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()
		l = []
		c = 0
		for i in range(len(s)):
			if s[i] == '0':
				if c != 0:
					l.append(c)
					c = 0
			else:
				c += 1
		if c != 0:
			l.append(c)
		l.sort(reverse=True)
		ans = 0
		for i in range(0, len(l), 2):
			ans += l[i]
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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


t = int(input())
for _ in range(t):
	s = input()
	groupones = []
	count = 0
	firstone = s.find('1')
	n = len(s)
	for i in range(max(firstone, 0), n):
		if s[i] == '1':
			count += 1
			if i == n - 1:
				groupones.append(count)
		else:
			groupones.append(count)
			count = 0
	groupones = sorted(groupones, reverse=True)
	sum1 = 0
	for i in range(0, len(groupones), 2):
		sum1 += groupones[i]
	print(sum1)


from itertools import groupby
t = int(input())
for _ in range(t):
	s = input()
	l = []
	for (k, v) in groupby(s):
		if k == '1':
			l.append(len(list(v)))
	l.sort(reverse=True)
	n = len(l)
	res = 0
	for i in range(0, n, 2):
		res += l[i]
	print(res)


for _ in range(int(input())):
	s = input()
	a = s.split('0')
	a.sort(reverse=True)
	su = 0
	for i in range(0, len(a), 2):
		su += len(a[i])
	print(su)


for t in range(int(input())):
	s = input()
	cnt = 0
	res = []
	for i in range(len(s)):
		if s[i] == '1':
			cnt += 1
		else:
			res.append(cnt)
			cnt = 0
	res.append(cnt)
	res1 = []
	for i in res:
		if i != 0:
			res1.append(i)
	res1.sort()
	res1 = res1[::-1]
	ans = 0
	for i in range(len(res1)):
		if i % 2 == 0:
			ans += res1[i]
	print(ans)


o = int(input())
for i in range(o):
	a = input()
	a = list(a)
	freq1 = []
	ctr = 0
	for i in range(len(a)):
		a[i] = int(a[i])
	for i in range(len(a)):
		if a[i] != 0:
			ctr += 1
		else:
			if ctr != 0:
				freq1.append(ctr)
			ctr = 0
		if i == len(a) - 1:
			freq1.append(ctr)
	if len(freq1) == 1 and freq1[0] == 0:
		alice = 0
	else:
		freq1.sort(reverse=True)
		alice = 0
		for i in range(0, len(freq1), 2):
			alice += freq1[i]
	print(alice)


t = int(input())
while t > 0:
	s = input()
	ar = []
	c = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
		else:
			if c != 0:
				ar.append(c)
			c = 0
	if c != 0:
		ar.append(c)
	ar.sort(reverse=True)
	s = 0
	for i in range(0, len(ar), 2):
		s += ar[i]
	print(s)
	t -= 1


def tc():
	s = input()
	segs = []
	cur = 0
	s += '0'
	for ch in s:
		if ch == '1':
			cur += 1
		elif cur != 0:
			segs.append(cur)
			cur = 0
	segs.sort()
	(a, b) = (0, 0)
	alice_turn = True
	while segs:
		val = segs.pop()
		if alice_turn:
			a += val
		else:
			b += val
		alice_turn = not alice_turn
	print(a)
T = int(input())
for _ in range(T):
	tc()


t = int(input())
a = []
for i in range(t):
	a.append(input())
	b = []
	for j in range(len(a[i])):
		if a[i][j] == '0':
			b.append(0)
		else:
			b.append(1)
	b.append('a')
	j = 0
	while b[j + 1] != 'a':
		if b[j] != 0 and b[j + 1] == 1:
			b[j + 1] = b[j] + 1
			b[j] = 0
			j = j + 1
		else:
			j = j + 1
	del b[len(b) - 1]
	b.sort(key=None, reverse=True)
	asum = 0
	bsum = 0
	for k in range(len(b)):
		if k % 2 == 0:
			asum = asum + b[k]
		else:
			bsum = bsum + b[k]
	print(asum)


import sys
t = int(input())
while t:
	t -= 1
	s = list(input())
	n = len(s)
	l = []
	i = 0
	while i < n:
		c = 0
		if s[i] == '1':
			for j in range(i, n):
				if s[j] == '1':
					c += 1
				else:
					break
			l.append(c)
			i += c
		else:
			i += 1
	l.sort(reverse=True)
	k = len(l)
	s = 0
	for i in range(0, k, 2):
		s += l[i]
	print(s)


from collections import defaultdict
import copy

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

def si():
	return input()

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

def mi():
	return map(int, input().split())
t = ii()
for _ in range(t):
	n = si()
	arr = []
	count = 0
	for i in n:
		if i == '1':
			count += 1
		elif count != 0:
			arr.append(count)
			count = 0
	if i == '1':
		arr.append(count)
	arr.sort()
	ans = 0
	for j in range(len(arr)):
		if j % 2 == 0:
			ans += arr[len(arr) - 1 - j]
	print(ans)


for _ in range(int(input())):
	n = input()
	count = 0
	ans = []
	for i in range(len(n)):
		if n[i] == '1':
			count += 1
		elif count == 0:
			continue
		else:
			ans.append(count)
			count = 0
	if count != 0:
		ans.append(count)
	ans.sort()
	sm = 0
	for i in range(len(ans) - 1, -1, -2):
		sm += ans[i]
	print(sm)


from sys import stdin, stdout

def fn(s):
	con = 0
	n = len(s)
	s1 = ''
	l = s.split('0')
	con = max((len(wrd) for wrd in l))
	for i in range(n - con + 1):
		new = s[i:i + con]
		if new.count('0') == 0:
			s1 = s[:i] + s[i + con:]
			break
	return (con, s1)
for _ in range(int(stdin.readline())):
	s = input()
	alice = 0
	while s:
		(c, s) = fn(s)
		if c == 0:
			break
		alice += c
		(c, s) = fn(s)
		if c == 0:
			break
	print(alice)


def solve():
	c = 0
	a = list()
	for i in input() + '0':
		if i == '1':
			c += 1
		elif c > 0:
			a.append(c)
			c = 0
	a.sort(reverse=True)
	ans = 0
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)
for t in range(int(input())):
	solve()


from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	T = int(input())
	for _ in [0] * T:
		S = input() + '_'
		bin_s = {'0': [], '1': []}
		n = 0
		prev = S[0]
		for s in S:
			if s != prev:
				bin_s[prev].append(n)
				n = 1
			else:
				n += 1
			prev = s
		bin_s['1'].sort(reverse=1)
		alice = 0
		for (i, j) in enumerate(bin_s['1']):
			if not i % 2:
				alice += j
		print(alice)
main()


t = int(input())
for i in range(t):
	s = input()
	string = []
	alice = 0
	first = 0
	for i in range(1, len(s)):
		if s[i] != s[i - 1] and s[i - 1] == '1':
			string.append(len(s[first:i]))
		elif s[i] != s[i - 1] and s[i - 1] != '1':
			first = i
	if s[-1] == '1':
		string.append(len(s[first:]))
	string.sort(reverse=True)
	for i in range(0, len(string), 2):
		alice += string[i]
	print(alice)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	l = input().strip()
	x = []
	ct = 1
	l += 'p'
	for i in range(1, len(l)):
		if l[i] == l[i - 1]:
			ct += 1
		else:
			if l[i - 1] == '1':
				x.append(ct)
			ct = 1
	x.sort(reverse=True)
	an = 0
	for i in range(0, len(x), 2):
		an += x[i]
	print(an)


ll = lambda : list(map(int, input().split()))
lls = lambda : list(map(str, input().split()))
st = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
from math import *
from sys import *
from datetime import datetime
from sys import stdin, stdout
import sys
from collections import *
for _ in range(ii()):
	n = st()
	l = []
	c = 0
	for i in range(len(n)):
		if n[i] == '1':
			c += 1
		else:
			l.append(c)
			c = 0
	l.append(c)
	l.sort(reverse=True)
	ans = 0
	for i in range(len(l)):
		if i % 2 == 0:
			ans += l[i]
	print(ans)


t = int(input())
for i in range(t):
	st = input()
	lis = list(st)
	sek = 0
	found = 0
	lik = []
	for j in range(len(lis)):
		if lis[j] == '1' and found == 0:
			lik.append(1)
			found = 1
		elif lis[j] == '1' and found == 1:
			lik[len(lik) - 1] = lik[len(lik) - 1] + 1
		else:
			found = 0
	lik.sort()
	a = 0
	for k in range(len(lik) - 1, -1, -2):
		a = a + lik[k]
	print(a)


for i in range(int(input())):
	s = str(input())
	a = s.split('0')
	A = 0
	if '' in a:
		a.remove('')
	for i in range(len(a)):
		if i % 2 == 0:
			A += len(max(a))
		a.remove(max(a))
	print(A)


import sys, math, cmath, time
start_time = time.time()

def solve():
	s = '0' + insr() + '0'
	c = 0
	q = []
	for i in range(len(s)):
		if s[i] == '1':
			c = c + 1
		elif c != 0:
			q.append(c)
			c = 0
	q.sort(reverse=True)
	print(sum([q[i] for i in range(0, len(q), 2)]))

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

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

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

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

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

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

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

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


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

def intArr():
	arr = input().split(' ')
	return [int(x) for x in arr]
t = nextInt()
ans = []
for tt in range(t):
	s = input()
	b = []
	a = []
	for x in s:
		b.append(int(x))
	c = 0
	start = False
	i = 0
	for x in b:
		if x == 1:
			start = True
			c += 1
			if i == len(b) - 1:
				a.append(c)
		elif x == 0 and start == True:
			start = False
			a.append(c)
			c = 0
		i += 1
	a.sort(reverse=True)
	score = 0
	for x in range(len(a)):
		if (x + 1) % 2 != 0:
			score += a[x]
	ans.append(score)
for x in ans:
	print(x)


ans = 0
for i in range(int(input())):
	s = 0
	ans = [len(s) for s in input().split('0')]
	ans.sort(reverse=True)
	for k in range(0, len(ans), 2):
		s += ans[k]
	print(s)


cases = int(input())
answers = [0] * cases

def run(scoring, string):
	scoreChange = 0
	scoreIndex = 0
	for j in range(len(string)):
		if string[j] > scoreChange:
			scoreChange = string[j]
			scoreIndex = j
	string.pop(scoreIndex)
	if scoring:
		answers[i] += scoreChange
for i in range(cases):
	string = input().split('0')
	while '' in string:
		string.remove('')
	for k in range(len(string)):
		string[k] = len(string[k])
	for k in range(len(string)):
		if string != []:
			run(True, string)
		if string != []:
			run(False, string)
for i in range(cases):
	print(answers[i])


T = int(input())
for _ in range(T):
	s = input()
	s = s.split('0')
	ans = []
	for x in s:
		if len(x) > 0:
			ans.append(len(x))
	ans.sort(reverse=True)
	rs = 0
	for i in range(0, len(ans), 2):
		rs += ans[i]
	print(rs)


for _ in range(int(input())):
	s = input()
	l = s.split('0')
	l2 = s.split('1')
	l.extend(l2)
	l.sort(reverse=True)
	l = [i for i in l if i != '']
	alice = 0
	bob = 0
	for i in range(len(l)):
		if i % 2 == 0:
			alice += l[i].count('1')
		else:
			bob += l[i].count('1')
	print(alice)


t = int(input())
for i in range(t):
	s = input()
	l = []
	c = 0
	b = False
	for i in s:
		if i == '1':
			c += 1
			b = False
		else:
			l.append(c)
			b = True
			c = 0
	if not b:
		l.append(c)
	l.sort()
	s = 0
	i = len(l) - 1
	while i >= 0:
		s += l[i]
		i -= 2
	print(s)


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
for ii in range(int(input())):
	s = input().split('0')
	arr = []
	for i in s:
		if len(i) != 0:
			arr.append(len(i))
	arr.sort(reverse=True)
	ans = 0
	for i in range(len(arr)):
		if not i & 1:
			ans += arr[i]
	print(ans)


for _ in range(int(input())):
	s = input().split('0')
	sz = [len(i) for i in s if len(i) != 0]
	sz.sort(reverse=True)
	ans = 0
	for i in range(0, len(sz), 2):
		ans += sz[i]
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	ar = input().rstrip()
	ct = 0
	fd = []
	for i in range(len(ar)):
		if ar[i] == '0':
			if ct != 0:
				fd.append(ct)
				ct = 0
		else:
			ct += 1
	fd.append(ct)
	fd.sort()
	fd.reverse()
	ans = 0
	for i in range(len(fd)):
		if i % 2 == 0:
			ans += fd[i]
	print(ans)


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

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

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations

def solve():
	a = input()
	val = []
	seq = 0
	if a[0] == '1':
		seq = 1
	for i in range(len(a) - 1):
		if a[i + 1] == '1':
			seq += 1
		else:
			if seq > 0:
				val.append(seq)
			seq = 0
	val = sorted(val, reverse=True)
	ans = 0
	for i in range(len(val)):
		if i % 2 == 0:
			ans += val[i]
	print(ans)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	s = input()
	c1 = []
	o = 0
	for c in s:
		if c == '1':
			o += 1
		if c == '0' and o > 0:
			c1.append(o)
			o = 0
	if o > 0:
		c1.append(o)
	c1 = sorted(c1, reverse=True)
	print(sum(c1[::2]))


t = int(input())
for i in range(t):
	s = input()
	s = list(s)
	s_sum = []
	count_1 = 0
	for j in range(len(s)):
		if int(s[j]) == 1:
			count_1 += 1
		elif int(s[j]) == 0:
			s_sum.append(count_1)
			count_1 = 0
		if j == len(s) - 1:
			s_sum.append(count_1)
	s_sum.sort(reverse=True)
	result = 0
	for j in range(0, len(s_sum), 2):
		result += s_sum[j]
	print(result)


seq_1 = []
for _ in range(int(input())):
	s = list(input())
	seq_1.clear()
	count = 0
	for i in s:
		if i == '1':
			count += 1
		elif count > 0:
			seq_1.append(count)
			count = 0
	if count > 0:
		seq_1.append(count)
	seq_1.sort(reverse=True)
	try:
		alice = seq_1[0]
		n = len(seq_1)
		for i in range(2, n, 2):
			alice += seq_1[i]
		print(alice)
	except:
		print(0)


t = int(input())
for z in range(t):
	s = input()
	n = len(s)
	arr = list(s)
	arrcount = []
	i = 0
	while i < n:
		if arr[i] == '1' and i < n:
			count = 0
			while arr[i] != '0' and i < n - 1:
				count = count + 1
				i = i + 1
			arrcount.append(count)
		i = i + 1
	if arr[n - 1] == '1' and arr[n - 2] == '1':
		arrcount[len(arrcount) - 1] += 1
	elif arr[n - 1] == '1' and arr[n - 2] == '0':
		arrcount.append(int(1))
	if arrcount == None:
		print('0')
		continue
	arrcount.sort(reverse=True)
	ansf = 0
	for i in range(len(arrcount)):
		if i % 2 == 0:
			ansf = ansf + arrcount[i]
	print(ansf)


t = int(input())
for i in range(t):
	s = str(input())
	p = 0
	ans = 0
	lis = []
	for j in s:
		if j == '1':
			p += 1
		else:
			lis.append(p)
			p = 0
	if p != 0:
		lis.append(p)
	lis.sort()
	a = len(lis)
	for j in range(1, a + 1):
		if j % 2 == 1:
			ans += lis[-j]
	print(ans)


t = int(input())
for i in range(t):
	n = input().split('0')
	n.sort(reverse=True)
	cnt = 0
	for i in range(0, len(n), 2):
		cnt += len(n[i])
	print(cnt)


from math import ceil
for _ in range(int(input())):
	n = input()
	l = []
	a = ''
	for i in range(len(n)):
		if n[i] == '1':
			a += '1'
		else:
			if a != '':
				l.append(a)
			a = ''
	if a != '':
		l.append(a)
	l.sort()
	l.reverse()
	count = 0
	for i in range(ceil(len(l) / 2)):
		count += len(l[2 * i])
	print(count)


for _ in range(int(input())):
	s = input()
	ar = []
	g = 0
	for i in range(len(s)):
		if s[i] == '1' and i == len(s) - 1:
			g += 1
			ar.append(g)
		elif s[i] == '1':
			g += 1
		elif s[i] == '0' and g != 0:
			ar.append(g)
			g = 0
	count = 0
	ar.sort(reverse=True)
	for d in range(len(ar)):
		if d % 2 == 0:
			count += ar[d]
	print(count)


t = int(input())
for _ in range(t):
	s = input()
	a = []
	if s[0] == '1':
		a = [1]
	for i in range(1, len(s)):
		if s[i] != s[i - 1] and s[i] == '1':
			a.append(1)
		elif s[i] == '1':
			a[-1] += 1
	a.sort(reverse=True)
	print(sum(a[::2]))


n = int(input())
uns = []
cont = 1
ind = 0
ans = 0
for i in range(n):
	x = input()
	x += 'f'
	for j in range(len(x)):
		if x[j] == '1':
			if x[j + 1] == '1':
				cont += 1
			elif x[j + 1] == '0' or x[j + 1] == 'f':
				uns.append(cont)
				cont = 1
	uns.sort(key=int, reverse=True)
	for t in range(len(uns)):
		if t % 2 == 0:
			ans += uns[t]
	print(ans)
	uns = []
	ans = 0


def bingame(bit):
	soma = 0
	saida = 0
	tam = []
	e = -1
	while True:
		e += 1
		if e == len(bit) and len(tam) == 0:
			tam.append(soma)
		if e == len(bit):
			break
		if bit[e] == '1':
			soma += 1
			if e == len(bit) - 1:
				tam.append(soma)
		else:
			tam.append(soma)
			soma = 0
	if len(tam) % 2 == 0:
		ntam = sorted(tam)
		for i in range(len(ntam) - 1, -1, -1):
			if i % 2 != 0:
				saida += ntam[i]
	else:
		tam.append(0)
		ntam = sorted(tam)
		for j in range(len(ntam) - 1, -1, -1):
			if j % 2 != 0:
				saida += ntam[j]
	return saida
n = int(input())
for e in range(n):
	bit = input()
	print(bingame(bit))


t = int(input())
for i in range(t):
	s = input()
	ar = s.split('0')
	ar.sort()
	str = ''
	for i in range(len(ar) - 1, -1, -2):
		str += ar[i]
	print(len(str))


def compute_lcm(num1, num2):
	if num1 > num2:
		num = num1
		den = num2
	else:
		num = num2
		den = num1
	rem = num % den
	while rem != 0:
		num = den
		den = rem
		rem = num % den
	gcd = den
	lcm = int(int(num1 * num2) / int(gcd))
	return lcm
t = int(input())
import math
import collections
for i in range(t):
	s = input()
	c = 0
	ss = []
	s1 = []
	for i in s:
		s1.append(i)
	s1.append('0')
	for i in range(len(s1)):
		if s1[i] == '1':
			c += 1
		else:
			if c != 0:
				ss.append(c)
			c = 0
	ss.sort(reverse=True)
	f = 1
	al = 0
	for i in ss:
		if f:
			al += i
			f ^= 1
		else:
			f ^= 1
			continue
	print(al)


import sys, os, io

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

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

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

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

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

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions
from collections import deque, defaultdict, OrderedDict
from fractions import Fraction
from decimal import Decimal

def yetohanswerhai(k, a, b):
	c = True
	for i in a:
		t = 0
		for j in b:
			if i & j | k == k:
				t += 1
				break
		if t == 0:
			c = False
			break
	return c

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		s = rs()
		s += '0'
		l1 = 0
		l2 = 0
		z = []
		for i in s:
			if i == '1':
				if l2 > 0:
					l2 = 0
				l1 += 1
			if i == '0':
				l2 += 1
				if l1 > 0:
					z.append(l1)
					l1 = 0
		z = sorted(z)
		z = z[::-1]
		a = 0
		for i in range(0, len(z), 2):
			a += z[i]
		print(a)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

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

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

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


def div(s):
	ar = []
	i = 1
	c = s[0]
	coun = 1
	while i < len(s):
		if s[i] == c:
			coun += 1
		else:
			ar.append([int(c), coun])
			c = s[i]
			coun = 1
		i += 1
	ar.append([int(c), coun])
	return ar

def helper(ar):
	if ar == []:
		return (0, 0, 0)
	c = 0
	m = 0
	ind = -1
	for i in range(len(ar)):
		if ar[i][0] == 1:
			c += 1
			if m < ar[i][1]:
				m = ar[i][1]
				ind = i
	if c == 0:
		return (0, 0, 0)
	else:
		ans = []
		i = 0
		while i < len(ar):
			if i == ind:
				if i == len(ar) - 1:
					break
				elif ans != []:
					ans[-1][1] += ar[i + 1][1]
					i += 2
				elif ans == []:
					ans.append(ar[i + 1])
					i += 2
				else:
					i += 1
			else:
				ans.append(ar[i])
				i += 1
		return (m, ind, ans)
t = int(input())
for l in range(t):
	s = input().strip()
	ar = div(s)
	ans = 0
	res = -1
	while res != 0:
		(res, _, ar) = helper(ar)
		if res == 0:
			break
		ans += res
		(res, _, ar) = helper(ar)
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	base = -1
	points = []
	for i in range(len(s)):
		if s[i] == '1' and base == -1:
			base = i
		elif s[i] == '0' and base != -1:
			points.append(i - base)
			base = -1
	if base != -1:
		points.append(len(s) - base)
	points.sort()
	a_score = 0
	for j in range(len(points)):
		if j % 2 == 0:
			a_score += points[len(points) - 1 - j]
	print(a_score)


for _ in range(int(input())):
	s = input()
	l = []
	(ans, e) = (0, 0)
	for i in range(len(s)):
		if s[i] == '1':
			e += 1
		elif s[i] == '0' and e != 0:
			l.append(e)
			e = 0
		if i == len(s) - 1:
			l.append(e)
	l.sort(reverse=True)
	for _ in range(len(l)):
		if _ % 2 == 0:
			ans += l[_]
	print(ans)


for i in [*open(0)][1:]:
	(l, k) = ([], 0)
	for j in i:
		if j == '1':
			k += 1
		else:
			l += [k]
			k = 0
	print(sum((i for i in sorted(l, reverse=1)[::2])))


t = int(input())
for ii in range(t):
	a = str(input())
	b = []
	c = []
	count = 0
	for i in range(len(a)):
		b.append(a[i])
	b.append('0')
	for i in range(len(b)):
		if b[i] == '0':
			c.append(count)
			count = 0
		elif b[i] == '1':
			count += 1
	c.sort()
	c = c[::-1]
	alice = 0
	for i in range(len(c)):
		if i % 2 == 0:
			alice += c[i]
	print(alice)


for t in range(int(input())):
	s = input()
	rama = []
	(add, sum) = (0, 0)
	for i in s:
		if i == '1':
			add += 1
		else:
			if add > 0:
				rama.append(add)
				sum += 1
			add = 0
	if add != 0:
		sum += 1
		rama.append(add)
	rama.sort()
	rama = rama[::-1]
	p = 0
	a = sum - sum // 2
	i = 0
	while i < sum:
		p += rama[i]
		i += 2
	print(p)


for i in range(int(input())):
	arr = list(input())
	a = []
	c = 0
	for i in arr:
		if i == '1':
			c += 1
		else:
			if c != 0:
				a.append(c)
			c = 0
	if c != 0:
		a.append(c)
	a.sort()
	a = a[::-1]
	ans = 0
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)


import math
test = int(input())
for t in range(test):
	s = input()
	n = len(s)
	A = []
	o = 0
	for i in range(n):
		if s[i] == '1':
			o += 1
		else:
			A.append(o)
			o = 0
	if s[n - 1] == '1':
		A.append(o)
	A.sort(reverse=True)
	ans = 0
	for i in range(0, len(A), 2):
		ans += A[i]
	print(ans)


from collections import Counter
import string
import math
import sys

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

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

def makedict(var):
	return dict(Counter(var))
mod = 1000000007
for _ in range(vary(1)):
	s = input()
	alice = 0
	bob = 0
	tt = []
	count = 0
	flag = 0
	ind = 0
	for i in range(len(s)):
		if s[i] == '1':
			ind = i
			count += 1
			continue
		elif s[i] != '1':
			tt.append(count)
			count = 0
	if ind == len(s) - 1:
		tt.append(count)
	tt.sort(reverse=True)
	for i in range(len(tt)):
		if i % 2 == 0:
			alice += tt[i]
		else:
			bob += tt[i]
	print(alice)


t = int(input())
for i in range(t):
	s = input().split('0')
	f = [len(x) for x in s]
	a = 0
	while True:
		if len(f) == 0:
			break
		a += max(f)
		f.remove(max(f))
		if len(f) == 0:
			break
		f.remove(max(f))
	print(a)


for _ in range(int(input())):
	data = list(map(int, list(input())))
	fl = False
	data.append('&')
	l = 0
	st = []
	for i in range(len(data)):
		if fl and data[i] == 1:
			l += 1
			continue
		if fl and data[i] != 1:
			st.append(l)
			l = 0
			fl = False
			continue
		if not fl and data[i] == 1:
			l = 1
			fl = True
	st.sort(reverse=True)
	c1 = 0
	for i in range(0, len(st), 2):
		c1 += st[i]
	print(c1)


import itertools
T = int(input())
for _ in range(T):
	S = input()
	result = 0
	ones = sorted([len(list(v)) for (k, v) in itertools.groupby(S) if k == '1'], reverse=True)
	for (i, num) in enumerate(ones):
		if i % 2 == 0:
			result += num
	print(result)


for t in range(int(input())):
	s = input() + '2'
	arr = []
	cnt = int(s[0] == '1')
	for i in range(1, len(s)):
		if s[i] == '1':
			cnt += 1
		elif cnt > 0:
			arr.append(cnt)
			cnt = 0
	arr = sorted(arr, reverse=True)
	cnt = 0
	for i in range(0, len(arr), 2):
		cnt += arr[i]
	print(cnt)


t = int(input())
i = 0
while i < t:
	s = list(input())
	k = []
	j = 0
	if len(s) == 1 and s[0] == '1':
		k.append(1)
	while j < len(s) - 1:
		if s[j] == s[j + 1] and s[j] == '1':
			l = j
			v = 1
			while l < len(s) - 1:
				if s[l] == s[l + 1] and s[l] == '1':
					pass
				else:
					break
				v += 1
				l += 1
			j = l
			k.append(v)
		j += 1
	h = 1
	s.append(0)
	if s[0] == '1' and s[1] == '0':
		k.append(1)
	while h < len(s) - 1:
		if s[h - 1] != s[h] != s[h + 1] and s[h] == '1':
			k.append(1)
		h += 1
	k.sort()
	k.reverse()
	u = 0
	y = 0
	while u < len(k):
		y = y + k[u]
		u += 2
	print(y)
	i += 1
k.sort()
u = 0


t = int(input())
for _ in range(t):
	s = input().split('0')
	s.sort(reverse=True)
	steps = list(map(len, filter(None, s)))
	print(sum(steps[::2]))


for _ in range(int(input())):
	s = str(input())
	l = s.split('0')
	l1 = []
	for i in range(len(l)):
		l1.append(len(l[i]))
	l1.sort(reverse=True)
	res = 0
	for i in range(len(l1)):
		if i & 1 ^ 1:
			res += l1[i]
	print(res)


from itertools import groupby

def game(x):
	a = [int(v) for v in str(x)]
	sre = 0
	ans = [list(j) for (i, j) in groupby(a)]
	ali = 1
	while len(ans) >= 1:
		lar = {'val': 0, 'ind': 0}
		for (idx, x) in enumerate(ans):
			if x[0] == 1:
				if lar['val'] < len(x):
					lar['val'] = len(x)
					lar['ind'] = idx
		ans.pop(lar['ind'])
		ans = [y for x in ans for y in x]
		ans = [list(y) for (x, y) in groupby(ans)]
		if ali == 1:
			ali = 0
			sre += lar['val']
		else:
			ali = 1
	print(sre)
t = int(input())
l = []
for i in range(t):
	v = int(input())
	l.append(v)
for ele in l:
	game(ele)


import sys
import math
import heapq
import collections
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

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

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')

def printspace(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer(' ')

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 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()
	ones = []
	cur = 0
	for i in range(len(s)):
		if s[i] == '1':
			cur += 1
		else:
			ones.append(cur)
			cur = 0
	ones.append(cur)
	ones.sort(reverse=True)
	ans = 0
	for i in range(len(ones)):
		if i % 2 == 0:
			ans += ones[i]
	print(ans)


from sys import stdin
input = lambda : stdin.readline().strip()
from collections import deque as d
for _ in range(int(input())):
	s = d(input())
	one = s.count('1')
	z = s.count('0')
	if '0' not in s:
		print(len(s))
	elif '1' not in s:
		print(0)
	else:
		b = d([])
		consec = 0
		for i in range(len(s)):
			if s[i] == '1' and i != len(s) - 1:
				consec += 1
			elif s[i] == '1' and i == len(s) - 1:
				b.append(consec + 1)
			elif (s[i] == '0' or i == len(s) - 1) and consec > 0:
				b.append(consec)
				consec = 0
		ans = 0
		b = list(b)
		b.sort(reverse=True)
		for i in range(len(b)):
			if i % 2 == 0:
				ans += b[i]
		print(ans)


from sys import stdin, stdout
import bisect
n = int(stdin.readline())
for i in range(n):
	lst = [0]
	ans = 0
	a = stdin.readline()
	x = 0
	for i in a:
		if i == '1':
			lst[x] += 1
		else:
			lst += [0]
			x += 1
	lst.sort()
	lst.reverse()
	for i in range(0, len(lst), 2):
		ans += lst[i]
	stdout.write(str(ans) + '\n')


t = int(input(''))
for i in range(t):
	s = input('')
	c = 0
	l = []
	for j in s:
		if j == '1':
			c += 1
		elif c != 0:
			l.append(c)
			c = 0
	l.append(c)
	l.sort()
	l = l[::-1]
	cc = 0
	for i in range(0, len(l), 2):
		cc += l[i]
	print(cc)


for _ in range(int(input())):
	s = input()
	n = len(s)
	ans = [0]
	for i in range(n):
		if s[i] == '1':
			ans[-1] += 1
		elif ans[-1] != 0:
			ans.append(0)
	ans.sort(reverse=True)
	print(sum(ans[::2]))


import sys
I = lambda : int(input())
RL = readline = lambda : sys.stdin.readline().strip('\n')
RM = readmap = lambda x=int: map(x, readline().split(' '))
for _ in range(I()):
	s = RL()
	l = [0]
	for i in s + '0':
		if i == '1':
			l[-1] += 1
		else:
			l.append(0)
	l.sort(reverse=True)
	print(sum(l[::2]))
quit()
for _ in range(I()):
	(n, l) = (I(), [*RM()])
	if l[0] + l[1] <= l[-1]:
		print(1, 2, n)
	else:
		print(-1)


T = int(input())
for i in range(T):
	N = input()
	flag = 0
	ans = []
	count = 0
	for i in N:
		if i == '1':
			if flag == 0:
				count += 1
			if flag == 1:
				flag = 0
				count += 1
		if i == '0':
			ans.append(count)
			count = 0
			flag = 1
	ans.append(count)
	ans.sort(reverse=True)
	res = 0
	flag = 0
	for i in ans:
		if flag == 0:
			res += i
			flag = 1
		else:
			flag = 0
	print(res)


import math, sys, itertools
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
for t in wtf[1:]:
	ones = ''
	A = []
	for ch in t:
		if ch == '0':
			if ones != '':
				A.append(ones)
				ones = ''
		if ch == '1':
			ones = ones + '1'
	if ones != '':
		A.append(ones)
	A = sorted(A, reverse=True)
	ans = 0
	for (i, a) in enumerate(A):
		if i % 2 == 0:
			ans += len(a)
	print(ans)


from math import *
a = int(input())
for x in range(a):
	b = input()
	l = len(b)
	j = [0 for y in range(l + 1)]
	p = 0
	for y in range(l):
		if b[y] == '1':
			p += 1
		else:
			j[p] += 1
			p = 0
	j[p] += 1
	n = 0
	d = 0
	h = 0
	for y in range(l, 0, -1):
		if j[y] > 0:
			while j[y]:
				if h == 0:
					n += y
					h = 1
				else:
					d += 1
					h = 0
				j[y] -= 1
	print(max(n, d))


for _ in range(int(input())):
	s = input()
	c = 0
	a = [0] * 50
	t = 0
	k = 0
	sum = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
			t = 2
		if s[i] == '0' and c > 0:
			a[k] = c
			k += 1
			c = 0
			t = 1
	if t == 2:
		a[k] = c
	ar = a.sort(reverse=True)
	for i in range(len(a)):
		if i % 2 == 0:
			sum += a[i]
	print(sum)


tc = int(input())
for _ in range(tc):
	s = input()
	n = len(s)
	(curr, alice) = (0, 0)
	while n > 0:
		L = R = 0
		best = [0, 0, 0]
		none = 1
		while R < n and L < n:
			if s[L] == '1':
				none = 0
				R += 1
				while R < n and s[R] == '1':
					R += 1
				if abs(R - L) > best[0]:
					best[0] = abs(R - L)
					best[1] = R
					best[2] = L
			L += 1
			R = L
		if none == 1:
			break
		if curr == 0:
			alice += best[0]
			s = s[:best[2]] + s[best[1]:]
			n -= best[0]
			curr = 1
			continue
		if curr == 1:
			s = s[:best[2]] + s[best[1]:]
			n -= best[0]
			curr = 0
			continue
	print(alice)


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi
import heapq

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

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

	def In():
		return map(int, input().split())
else:

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

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

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_right(a, x)
	if i != len(a):
		return i
	else:
		return -1

def find_ge(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		l = list(input())
		dp = []
		if l[-1] == '0':
			l.append('1')
		else:
			l.append('0')
		count = 0
		for x in range(len(l) - 1):
			if l[x] != l[x + 1]:
				count += 1
				if l[x] == '1':
					dp.append(count)
				count = 0
			else:
				count += 1
		dp.sort(reverse=True)
		ans = 0
		for x in range(len(dp)):
			if x % 2 == 0:
				ans += dp[x]
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().split())
inl = lambda : list(map(int, input().split()))
ans = []
t = ini()
for _ in range(t):
	s = sorted(ins().split('0'), reverse=True)
	count = 0
	for i in range(len(s)):
		if i % 2 == 0:
			count += len(s[i])
	ans.append(count)
print('\n'.join(map(str, ans)))


for test_i in range(int(input())):
	s = input()
	arr = []
	con = 0
	for el in list(s):
		if el == '1':
			con += 1
		elif con:
			arr.append(con)
			con = 0
	arr.append(con)
	arr.sort(reverse=True)
	print(sum(arr[::2]))


t = int(input())
for _ in range(t):
	s = input()
	i = 0
	count = []
	while i < len(s):
		if s[i] == '1':
			cnt = 0
			while i < len(s) and s[i] == '1':
				cnt += 1
				i += 1
			count.append(cnt)
		else:
			i += 1
	if len(count) == 0:
		print(0)
	else:
		count.sort(reverse=True)
		ans = 0
		for i in range(0, len(count), 2):
			ans += count[i]
		print(ans)


import math
m = 1000000007

def fact(n):
	ans = 1
	for i in range(1, n + 1):
		ans = ans % m * (i % m) % m
	return ans

def power_2(n):
	ans = 1
	for i in range(n):
		ans = ans % m * 2 % m
	return ans
for z in range(int(input())):
	s = input()
	n = len(s)
	a = []
	i = 0
	while i < n:
		cnt = 0
		while i < n and s[i] == '1':
			cnt += 1
			i += 1
		i += 1
		a.append(cnt)
	a.sort(reverse=True)
	ans = 0
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)


import math
t = int(input())
for _ in range(t):
	s = str(input())
	a = []
	now = 0
	alice = 0
	for i in range(len(s)):
		if s[i] == '1':
			now += 1
		else:
			if now != 0:
				a.append(now)
			now = 0
	a.append(now)
	a.sort(reverse=True)
	for i in range(0, len(a), 2):
		alice += a[i]
	print(alice)


for _ in range(int(input())):
	arr = [int(x) for x in input()]
	arr.append(0)
	mx = 0
	cnt = 0
	on = False
	res = []
	for i in range(len(arr)):
		if arr[i] == 1 and on == False:
			on = True
			cnt += 1
		elif arr[i] == 1 and on == True:
			cnt += 1
		elif arr[i] == 0 and on == True:
			on = False
			res.append(cnt)
			cnt = 0
	res = sorted(res, reverse=True)
	ans = 0
	for i in range(0, len(res), 2):
		ans += res[i]
	print(ans)


for ikjk in range(int(input())):
	s = input()
	n = len(s)
	q = []
	x = 0
	for i in range(n):
		if s[i] == '1':
			x += 1
			if i == n - 1:
				q.append(x)
		else:
			q.append(x)
			x = 0
	q.sort()
	q.reverse()
	n = len(q)
	m = 0
	for i in range(n):
		if i % 2 == 0:
			m += q[i]
	print(m)


for _ in range(int(input())):
	s = input()
	a = []
	j = 0
	while j < len(s):
		if s[j] == '1':
			t = 0
			for k in range(j, len(s)):
				if s[k] == '1':
					j += 1
					t += 1
				else:
					break
			a.append(t)
		else:
			j += 1
	a = sorted(a, reverse=True)
	cnt = 0
	for j in range(len(a)):
		if j % 2 == 0:
			cnt += a[j]
	print(cnt)


def solution():
	s = list(input())
	n = len(s)
	ans = []
	i = 0
	while i < len(s):
		x = i
		while i < n and s[i] == '1':
			i += 1
		ans.append(i - x)
		i += 1
	ans.sort(reverse=True)
	x = 0
	for i in range(0, len(ans), 2):
		x += ans[i]
	print(x)
t = int(input())
for _ in range(t):
	solution()


import sys

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

def print(*argv):
	n = len(argv)
	for i in range(n):
		if i == n - 1:
			sys.stdout.write(str(argv[i]) + '\n')
		else:
			sys.stdout.write(str(argv[i]) + ' ')

def lcm(x, y):
	from math import gcd
	return x * y / gcd(x, y)

def solve(s):
	s += '2'
	lst = []
	(summ, dupl) = (0, 1)
	for i in range(len(s) - 1):
		if s[i] == '1':
			if s[i] == s[i + 1]:
				dupl += 1
			else:
				lst.append(dupl)
				dupl = 1
		else:
			dupl = 1
	lst = sorted(lst, reverse=True)
	for i in range(0, len(lst), 2):
		summ += lst[i]
	return summ
for _ in range(int(input())):
	s = input()
	print(solve(s))


from sys import stdin
input = stdin.readline

def A():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		a.sort()
		found = False
		if a[0] + a[1] <= a[n - 1]:
			print(1, 2, n)
		else:
			print(-1)

def B():
	from collections import deque
	t = int(input())
	for _ in range(t):
		s = [int(x) for x in input().rstrip()]
		d = deque()
		curr = s[0]
		streak = s[0]
		for i in range(1, len(s)):
			if s[i] != curr:
				if curr == 1:
					d.append(streak)
				curr = s[i]
				streak = 1
			elif curr == 1:
				streak += 1
		if curr == 1:
			d.append(streak)
		d = list(d)
		d.sort(reverse=True)
		tot = 0
		for i in range(0, len(d), 2):
			tot += d[i]
		print(tot)

def C():
	t = int(input())
	for _ in range(t):
		print(0)

def D():
	t = int(input())
	for _ in range(t):
		print(0)
B()


for i1 in range(int(input())):
	s = input()
	s = s.replace('\r', '')
	s = s + '0'
	s = '0' + s
	alice = 0
	bob = 0
	ans = []
	c = 0
	for i in s:
		if i == '0':
			ans.append(c)
			c = 0
		else:
			c += 1
	ans.sort(reverse=True)
	for i in range(len(ans)):
		if i % 2 == 0:
			alice += ans[i]
	print(alice)


for _ in range(int(input())):
	s = input()
	if int(s, base=2) == 0:
		print(0)
	else:
		l = []
		c = 0
		(s1, s2) = (0, 0)
		for i in range(len(s)):
			if s[i] == '1':
				c += 1
			else:
				l.append(c)
				c = 0
		if c != 0:
			l.append(c)
		l.sort(reverse=True)
		for i in range(len(l)):
			if i & 1:
				s2 += l[i]
			else:
				s1 += l[i]
		print(max(s1, s2))


for i in range(int(input())):
	l = [i for i in input()]
	c = 0
	a = []
	ans = 0
	for i in l:
		if int(i) & 1:
			c += 1
		else:
			a.append(c)
			c = 0
	a.append(c)
	a.sort(reverse=True)
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)


for _ in range(int(input())):
	s = list([[c, 1] for c in input()])
	i = 0
	while i < len(s) - 1:
		if s[i][0] == s[i + 1][0]:
			s[i][1] += 1
			s.pop(i + 1)
		else:
			i += 1
	l = [intv[1] for intv in s if intv[0] == '1']
	l.sort()
	l.reverse()
	ans = 0
	for i in range(0, len(l), 2):
		ans += l[i]
	print(ans)


a = int(input())
for i in range(0, a):
	s = input()
	arr = []
	for i in s:
		arr.append(int(i))
	ans = []
	count = 0
	for i in range(0, len(arr)):
		if arr[i] == 0:
			ans.append(count)
			count = 0
		if arr[i] == 1:
			count = count + 1
	ans.append(count)
	ans.sort()
	brr = arr[::-1]
	eve = 0
	odd = 0
	for i in range(0, len(ans)):
		if i % 2 == 0:
			eve = eve + ans[i]
		else:
			odd = odd + ans[i]
	print(max(eve, odd))


import sys

def main():
	tn = int(sys.stdin.readline())
	for ti in range(tn):
		s = sys.stdin.readline().strip()
		a = 0
		r = []
		for c in s:
			if c == '1':
				a += 1
			else:
				r.append(a)
				a = 0
		r.append(a)
		r.sort(reverse=True)
		print(sum(r[::2]))
main()


import sys
import os
from math import sqrt, log, log2, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial
from copy import copy, deepcopy
import bisect
from sys import exit, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
mod = 1000000007
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : stdout.flush()

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	p = int(sqrt(n))
	for i in range(5, p + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def solve():
	s = inp()
	n = len(s)
	start = 0
	end = 0
	i = 0
	j = 0
	turn = 1
	ans = []
	while i < n:
		j = i + 1
		if s[i] == '1':
			if i == n - 1:
				ans.append(s[i])
			else:
				while j < n and s[j] == '1':
					j += 1
				ans.append(s[i:j])
				i = j
		i += 1
	if ans == []:
		print(0)
	else:
		ans.sort(key=lambda x: -len(x))
		a = 0
		for i in range(0, len(ans), 2):
			a += len(ans[i])
		print(a)
for _ in range(iinp()):
	solve()


t = int(input())
for task in range(t):
	ones = []
	s = input().split('0')
	for i in s:
		if i != '':
			ones.append(len(i))
	ones.sort()
	ones = ones[::-1]
	res = 0
	for i in range(len(ones)):
		if i % 2 == 0:
			res += ones[i]
	print(res)


import re
for _ in range(int(input())):
	a = input()
	i = 0
	mo = re.findall('1+', a)
	mo = [len(x) for x in mo]
	mo.sort(reverse=True)
	print(sum(mo[::2]))


q = int(input())
for _ in range(q):
	A = [x for x in input().split('0')]
	points = []
	for a in A:
		points.append(len(a))
	points.sort(reverse=True)
	print(sum(points[::2]))


for i in range(int(input())):
	n = input()
	c = 0
	c1 = 0
	c2 = 0
	lst = list()
	lst1 = list()
	for i in range(len(n)):
		if int(n[i]) == 1:
			c = c + 1
		else:
			lst.append(c)
			lst1.append(i)
			c = 0
	if len(lst1) == 0:
		print(len(n))
		continue
	if len(lst1) != 0 and lst1[-1] != len(n) - 1:
		y1 = n[lst1[-1]:]
		for i in range(len(y1)):
			c2 = c2 + int(y1[i])
	lst.append(c2)
	lst.sort(reverse=True)
	for i in range(len(lst)):
		if i % 2 == 0:
			c1 = c1 + lst[i]
	print(c1)


def f():
	s = input('')
	s = s + '0' + '0'
	l = []
	i = 0
	k = 0
	j = 0
	while i < len(s) - 1:
		if s[i] == '1':
			k = k + 1
			i = i + 1
		elif s[i] == '0':
			if k != 0:
				l.append(k)
			k = 0
			i = i + 1
		else:
			i = i + 1
	if len(l) == 0:
		print(0)
	else:
		l.sort()
		for i in range(len(l) - 1, -1, -2):
			j = j + l[i]
		print(j)
n = int(input(''))
for i in range(n):
	f()


T = int(input())
for _ in range(T):
	s = input()
	n = len(s)
	(pre, cur, nums) = (-1, 0, [])
	while cur < n:
		if s[cur] == '1' and (cur + 1 == n or s[cur + 1] == '0'):
			nums.append(cur - pre)
		if s[cur] == '0' and cur + 1 < n and (s[cur + 1] == '1'):
			pre = cur
		cur += 1
	nums = sorted(nums, reverse=True)
	(i, ans) = (0, 0)
	while i < len(nums):
		ans += nums[i]
		i += 2
	print(ans)


import copy
import math
r = int(input())
for l in range(r):
	arr = [d for d in input().split('0')]
	arr1 = [len(i) for i in arr]
	arr1.sort(reverse=True)
	s = 0
	for i in range(0, len(arr1), 2):
		s += arr1[i]
	print(s)


test_cnt = int(input())
for tn in range(test_cnt):
	raw = '0' + input()
	cnts = []
	for i in range(1, len(raw)):
		if raw[i] == '1' and raw[i - 1] == '0':
			cnts += [1]
		elif raw[i] == '1' and raw[i - 1] == '1':
			cnts[-1] += 1
	srt = sorted(cnts)
	rez = sum(srt[::-2])
	print(rez)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	x = input().rstrip()
	arr = []
	c = 0
	for char in x:
		if char == '1':
			c += 1
		else:
			arr.append(c)
			c = 0
	arr.append(c)
	arr.sort()
	arr.reverse()
	ans = 0
	for i in range(0, len(arr), 2):
		ans += arr[i]
	print(ans)


for _ in range(int(input())):
	s = input()
	res = s.split('0')
	res.sort(reverse=True)
	ans = 0
	for i in range(0, len(res), 2):
		if not res[i]:
			break
		ans += len(res[i])
	print(ans)


for fi in range(int(input())):
	x = input() + '0'
	y = []
	s = 0
	for ifi in x:
		if ifi == '1':
			s = s + 1
		elif s != 0:
			y.append(s)
			s = 0
	s = 0
	y.sort()
	k = len(y) - 1
	while k >= 0:
		s = s + y[k]
		k = k - 2
	print(s)


def solve():
	s = input()
	score = 0
	(ti, i, tn, n) = (0, 0, 0, 0)
	last = '0'
	round = True
	while s.find('1') != -1:
		j = 0
		while j < len(s):
			if s[j] == '1' and last == '0':
				ti = s.index(s[j])
				tn = 1
				last = '1'
			elif s[j] == '1' and last == '1':
				tn += 1
				last = '1'
			elif s[j] == '0' and last == '1':
				if tn > n:
					(n, i) = (tn, ti)
				last = '0'
			j += 1
		if tn > n:
			(n, i) = (tn, ti)
		if round:
			score += n
		s = s.replace('1' * n, '', 1)
		(ti, i, tn, n) = (0, 0, 0, 0)
		round = not round
	return score
n = int(input())
for _ in range(n):
	print(solve())


for _ in range(int(input())):
	s = input()
	a = [int(i) for i in s]
	a.append(0)
	tmp = 0
	ls = []
	for i in a:
		if i:
			tmp += 1
		else:
			ls.append(tmp)
			tmp = 0
	ls.sort(reverse=True)
	out = 0
	for i in range(len(ls)):
		if i % 2:
			continue
		out += ls[i]
	print(out)


import math
t = int(input())
for w in range(t):
	s = sorted(input().split('0'), reverse=True)
	c = 0
	for i in range(0, len(s), 2):
		c += len(s[i])
	print(c)


for I in range(int(input())):
	s = input()
	ones = []
	one = 0
	for char in s:
		if char == '1':
			one += 1
		else:
			ones.append(one)
			one = 0
	if one > 0:
		ones.append(one)
	if len(ones) > 0:
		ones.sort(reverse=True)
		res = 0
		for i in range(0, len(ones), 2):
			res += ones[i]
		print(res)
	else:
		print(0)


for t in range(int(input())):
	vs = [c == '1' for c in input()]
	seqs = []
	cur = 0
	for v in vs:
		if v:
			cur += 1
		else:
			if cur > 0:
				seqs += [cur]
			cur = 0
	if cur > 0:
		seqs += [cur]
	seqs.sort(reverse=True)
	score = sum(seqs[::2])
	print(score)


from math import *
t = int(input())
while t:
	t = t - 1
	s = input()
	l = list()
	out = 0
	cnt = 0
	for i in s:
		if i == '1':
			cnt += 1
		else:
			l.append(cnt)
			cnt = 0
	l.append(cnt)
	l.sort(reverse=True)
	j = 1
	for i in l:
		if j == 1:
			out += i
		j *= -1
	print(out)


t = int(input())
for _ in range(t):
	s = input()
	counter = 0
	turn = True
	for i in range(len(s), 0, -1):
		i_ = '1' * i
		while i_ in s:
			if turn:
				counter += i
			ind = s.index(i_)
			s = s[:ind] + s[ind + i:]
			turn = not turn
	print(counter)


import math
t = int(input())
for t1 in range(t):
	s = input()
	x = sorted([i for i in s.split('0') if i != ''])
	res = x[::-1]
	count = 0
	for i in range(0, len(res), 2):
		count += len(res[i])
	print(count)


T = int(input())
for case in range(T):
	s = input()
	ls = s.split('0')
	ls = sorted([len(c) for c in ls if c != ''], reverse=True)
	ls = [e for (n, e) in enumerate(ls) if n % 2 == 0]
	print(sum(ls))


for _ in range(int(input())):
	ones = sorted(map(len, input().split('0')), reverse=True)
	print(sum(ones[::2]))


import sys
import re
s = sys.stdin.read().strip().split('\n')[1:]
o = []
for i in s:
	l = sorted((len(j) for j in re.split('0+', i.strip('0'))), reverse=True)
	o.append(sum(l[::2]))
print(*o, sep='\n')


n = int(input())
l = []
for i in range(n):
	l.append(input())
for str in l:
	ns = ''
	for i in str:
		if len(ns) < 1:
			ns += i
		elif ns[-1] == i:
			ns += i
		else:
			ns += '.' + i
	p = ns.split('.')
	vec = []
	for t in p:
		if '0' in t:
			continue
		else:
			vec.append(len(t))
	vec.sort(reverse=True)
	score = 0
	for q in range(len(vec)):
		if q % 2 == 0:
			score += vec[q]
	print(score)


t = int(input(''))
arr = []
for i in range(t):
	arr.append(input(''))
for i in arr:
	cnt = 0
	n = len(i)
	fcnt = []
	for j in range(len(i)):
		if i[j] == '1':
			cnt += 1
			if j == n - 1:
				fcnt.append(cnt)
		else:
			if cnt != 0:
				fcnt.append(cnt)
			cnt = 0
	fcnt.sort(reverse=True)
	sol = 0
	for j in range(len(fcnt)):
		if j % 2 == 0:
			sol += fcnt[j]
	print(sol)


n = int(input())
for _ in range(n):
	s = input()
	cnt = 1
	l = []
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			cnt = cnt + 1
		else:
			if s[i - 1] == '1':
				l.append(cnt)
			cnt = 1
	if s[-1] == '1':
		l.append(cnt)
	l.sort()
	ans = 0
	for i in range(len(l) - 1, -1, -2):
		ans += l[i]
	print(ans)


for _ in range(int(input())):
	s = list(input())
	a = []
	count = 0
	for i in range(0, len(s)):
		if s[i] == '1':
			count += 1
		else:
			a.append(count)
			count = 0
	if count > 0:
		a.append(count)
	a.sort(reverse=True)
	ans = 0
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)


for _ in range(int(input())):
	s = [len(i) for i in input().split('0')]
	s.sort(reverse=True)
	print(sum(s[::2]))


t = int(input())
while t != 0:
	grid = list(input().replace('0', ' ').split())
	i = 1
	s = 0
	while len(grid) != 0:
		if i % 2 != 0:
			x = grid.index(max(grid))
			y = grid.pop(x)
			z = len(y)
			s += len(y)
		else:
			grid.pop(grid.index(max(grid)))
		i += 1
	print(s)
	t -= 1


t = int(input())
for _ in range(t):
	s = input()
	conseq1 = []
	count = 0
	for i in range(len(s)):
		if s[i] == '1':
			count += 1
		elif count:
			conseq1.append(count)
			count = 0
		if i == len(s) - 1 and count:
			conseq1.append(count)
	conseq1.sort(reverse=True)
	if not conseq1:
		print(0)
		continue
	total = 0
	for j in range(0, len(conseq1), 2):
		total += conseq1[j]
	print(total)


def solve(s):
	i = 0
	one_list = []
	while i < len(s):
		if s[i] == '1':
			c = 0
			while s[i] == '1':
				c += 1
				i += 1
				if i == len(s):
					break
			one_list.append(c)
		i += 1
	one_list.sort(reverse=True)
	ans = 0
	for i in range(len(one_list)):
		if i % 2 == 0:
			ans += one_list[i]
	print(ans)
t = int(input())
for test in range(t):
	s = list(input())
	solve(s)


for _ in range(int(input())):
	s = input().strip()
	a = []
	cnt = 1
	for i in range(len(s) - 1):
		if s[i] == s[i + 1]:
			cnt += 1
		else:
			if s[i] == '1':
				a.append(cnt)
			cnt = 1
	if s[-1] == '1':
		a.append(cnt)
	a.sort(reverse=True)
	ans = 0
	for i in range(len(a)):
		if i & 1 == 0:
			ans += a[i]
	print(ans)


for i in range(int(input())):
	s = input()
	print(sum(sorted(map(len, s.split('0')))[::-2]))


def pontos(s):
	return len(s)
t = int(input())
jogos = []
for x in range(t):
	jogos.append(input().split('0'))
for x in range(t):
	s = jogos[x]
	s.sort(key=pontos, reverse=True)
	alice = 0
	for y in range(0, len(s), 2):
		alice += len(s[y])
	print(alice)


t = int(input())
for _ in range(t):
	s = input() + '0'
	seg_lens = []
	temp = 0 if s[0] == '0' else 1
	for i in range(1, len(s)):
		if s[i] == '1':
			temp += 1
		else:
			if temp != 0:
				seg_lens.append(temp)
			temp = 0
	seg_lens = sorted(seg_lens, reverse=True)
	print(sum([seg_lens[i] for i in range(0, len(seg_lens), 2)]))


for _ in range(int(input())):
	n = input()
	l = []
	cnt = 0
	for i in range(0, len(n)):
		if n[i] == '1':
			cnt += 1
		else:
			l.append(cnt)
			cnt = 0
	l.append(cnt)
	l.sort()
	l = l[::-1]
	a = 0
	b = 0
	for i in range(len(l)):
		if i % 2 == 0:
			a += l[i]
		else:
			b += l[i]
	print(a)


from sys import stdin, stdout

def main():
	n = int(input())
	for _ in range(n):
		s = stdin.readline()
		prev = 0
		ans = list()
		for c in s:
			if c == '1':
				prev += 1
			elif prev != 0:
				ans.append(prev)
				prev = 0
		if prev != 0:
			ans.append(prev)
		ans.sort(reverse=True)
		ans = [val for (i, val) in enumerate(ans) if i % 2 == 0]
		print(sum(ans))
main()


cases = int(input())
for t in range(cases):
	s = input() + '0'
	a = []
	p = s[0]
	c = 0
	if p == '1':
		c += 1
	for i in s[1:]:
		if i == '0':
			if p == '1':
				a.append(c)
				c = 0
		elif p == i:
			c += 1
		else:
			c = 1
		p = i
	a = sorted(a)[::-1]
	print(sum(a[::2]))


def solve():
	S = list(map(int, list(input())))
	S.append(0)
	now = 0
	ONE = []
	for s in S:
		if s == 1:
			now += 1
		else:
			if now > 0:
				ONE.append(now)
			now = 0
	ONE.sort(reverse=True)
	return sum(ONE[::2])

def main():
	t = int(input())
	ANS = [solve() for _ in range(t)]
	print('\n'.join(map(str, ANS)))
main()


t = int(input())
for _ in range(t):
	s = list(input())
	n = len(s)
	lens = []
	if s[0] == '1':
		lens.append(1)
	for i in range(1, n):
		if s[i] == s[i - 1] == '1':
			lens[-1] += 1
		elif s[i] == '1':
			lens.append(1)
	lens.sort(reverse=True)
	ans = 0
	i = 0
	while i < len(lens):
		ans += lens[i]
		i += 2
	print(ans)


for i in range(int(input())):
	s = input().split('0')
	u = [int(i) for i in s if i != '']
	a = 0
	if len(u) > 0:
		for i in range(len(u)):
			if i % 2 == 0:
				m = max(u)
				a += len(str(m))
				u.remove(m)
			else:
				u.remove(max(u))
	print(a)


t = int(input())
for _ in range(t):
	s = input()
	l = s.split('0')
	a = [len(i) for i in l]
	a = sorted(a, reverse=True)
	ans = 0
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)


for i in range(int(input())):
	t = input() + '0'
	k = 0
	arr = []
	for e in t:
		k += int(e)
		if k != 0 and e == '0':
			arr.append(k)
			k = 0
	arr.sort(reverse=True)
	print(sum(map(int, arr[0::2])))


t = int(input())
for i in range(t):
	s = input()
	scores = list(map(lambda x: len(x), s.split('0')))
	scores.sort(reverse=True)
	ans = sum(scores[::2])
	print(ans)


for _ in range(int(input())):
	a = input()
	if '1' not in a:
		print(0)
	elif '0' not in a:
		print(len(a))
	else:
		zeros = []
		ones = []
		count = 1
		for i in range(len(a) - 1):
			if a[i] == '0' and a[i + 1] == '1':
				zeros.append(count)
				count = 1
			elif a[i] == '0' and a[i + 1] == '0':
				count += 1
			elif a[i] == '1' and a[i + 1] == '1':
				count += 1
			else:
				ones.append(count)
				count = 1
		if a[-1] == '0':
			zeros.append(count)
		else:
			ones.append(count)
		ones.sort(reverse=True)
		a = 0
		for i in range(len(ones)):
			if i % 2 == 0:
				a += ones[i]
		print(a)


for _ in range(int(input())):
	f = sum(sorted([len(j) for j in input().split('0')], reverse=True)[::2])
	print(f)


numberTestCases = int(input())
for i in range(numberTestCases):
	binaryString = input()
	sequencesValues = [0] * len(binaryString)
	currentSequenceIndex = -1
	inSequence = False
	for j in range(len(binaryString)):
		if binaryString[j] == '1':
			if not inSequence:
				inSequence = True
				currentSequenceIndex = j
			sequencesValues[currentSequenceIndex] += 1
		elif inSequence:
			inSequence = False
	sequencesValues.sort()
	pointsAlice = 0
	alicesTurn = True
	for k in range(len(sequencesValues) - 1, -1, -1):
		if alicesTurn:
			pointsAlice += sequencesValues[k]
			alicesTurn = False
		else:
			alicesTurn = True
	print(pointsAlice)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	S = input().strip() + '0'
	L = []
	NOW = 0
	for s in S:
		if s == '0':
			L.append(NOW)
			NOW = 0
		else:
			NOW += 1
	L.sort(reverse=True)
	ANS = 0
	for i in range(0, len(L), 2):
		ANS += L[i]
	print(ANS)


t = int(input())
while t > 0:
	t -= 1
	a = input()
	vals = []
	state = '0'
	count = 0
	for elem in a:
		if elem == state:
			count += 1
		else:
			if elem == '0':
				vals.append(count)
			count = 1
			state = elem
	if state == '1':
		vals.append(count)
	vals.sort(reverse=True)
	score = 0
	for val in vals[0::2]:
		score += val
	print(score)


for _ in range(int(input())):
	s = input()
	w = []
	a = False
	for i in s:
		if i == '1':
			if a:
				w[-1] += 1
			else:
				w.append(1)
				a = True
		else:
			a = False
	w.sort()
	print(sum(w[::-2]))


def main(case):
	lst = []
	line = input()
	cur = 0
	for i in line:
		if i == '1':
			cur += 1
		elif cur != 0:
			lst.append(cur)
			cur = 0
	if cur != 0:
		lst.append(cur)
	lst = sorted(lst, reverse=True)
	sm = 0
	for i in range(0, len(lst), 2):
		sm += lst[i]
	print(sm)
t = int(input())
for i in range(t):
	main(i + 1)


testcases = int(input())
for i in range(testcases):
	sequence = input()
	sequence = sequence.split('0')
	sequence = [len(item) for item in sequence if len(item) > 0]
	sequence.sort(reverse=True)
	print(sum(sequence[::2]))


rw = int(input())
for qwe in range(rw):
	s = input()
	k = []
	p = 0
	for i in s:
		if i == '1':
			p += 1
		elif p != 0:
			k.append(p)
			p = 0
	if p != 0:
		k.append(p)
		p = 0
	k.sort()
	k.reverse()
	s = 0
	for i in range(0, len(k), 2):
		s += k[i]
	print(s)


for _ in range(int(input())):
	s = input()
	i = 0
	a = 0
	b = 0
	s = s.replace('10', '1#0')
	s = s.replace('01', '0#1')
	s = s.split('#')
	s = [i for i in s if '1' in i]
	s.sort(reverse=True)
	for i in range(0, len(s), 2):
		if i % 2 == 0:
			a += len(s[i])
	print(a)


def cnt(s):
	count = 0
	counter = 0
	flag = 0
	lol = []
	for i in range(len(s)):
		flag = 0
		if s[i] == '1':
			counter = counter + 1
		else:
			lol.append(counter)
			flag = 1
			counter = 0
	if flag == 0:
		lol.append(counter)
	return lol
t = int(input())
for _ in range(t):
	s = input()
	x = cnt(s)
	x.sort(reverse=True)
	ans = 0
	for i in range(0, len(x), 2):
		ans += x[i]
	print(ans)


T = int(input())
for _ in range(0, T):
	s = input()
	c = 1
	L = []
	for i in range(1, len(s)):
		if s[i] != s[i - 1]:
			if s[i - 1] == '1':
				L.append(c)
			c = 1
		else:
			c += 1
	if s[-1] == '1':
		L.append(c)
	L.sort()
	L = L[::-1]
	ans = 0
	for i in range(0, len(L), 2):
		ans += L[i]
	print(ans)


for _ in range(int(input())):
	s = [*input()]
	cons = []
	p = -1
	for i in range(len(s)):
		if s[i] == '1':
			if s[i] == p:
				cons[-1][1] = i
			else:
				cons.append([i, i, s[i]])
		p = s[i]
	cons.sort(key=lambda x: -(x[1] - x[0] + 1))
	print(sum([i[1] - i[0] + 1 for i in cons[::2]]))


t = int(input())
for _ in range(t):
	n = input().split('0')
	for i in range(len(n)):
		n[i] = len(n[i])
	n.sort(reverse=True)
	x = 0
	for i in range(0, len(n), 2):
		x += n[i]
	print(x)


for _ in range(int(input())):
	s = sorted(input().split('0'))
	alice = 0
	for i in range(len(s) - 1, -1, -2):
		alice += len(s[i])
	print(alice)


def remg(s):
	count = 0
	track = []
	for i in range(len(s)):
		if int(s[i]) == 1:
			count += 1
		else:
			track.append(count)
			count = 0
		if i == len(s) - 1:
			track.append(count)
	A = 0
	while len(track) != 0:
		A += max(track)
		track.remove(max(track))
		if len(track) == 0:
			break
		track.remove(max(track))
	return A
n = int(input())
res = []
for i in range(n):
	a = str(input())
	res.append(remg(a))
for j in res:
	print(j)


def solve():
	arr = input()
	leni = []
	count = 0
	for i in range(len(arr)):
		if arr[i] == '1':
			count += 1
		else:
			leni.append(count)
			count = 0
	leni.append(count)
	leni.sort(reverse=True)
	alice = 0
	for i in range(0, len(leni), 2):
		alice += leni[i]
	print(alice)
test = int(input())
while test:
	solve()
	test -= 1


for _ in range(int(input())):
	(X, Ones, Counter) = (input(), [], 0)
	for i in X:
		if i == '1':
			Counter += 1
		else:
			Ones.append(Counter)
			Counter = 0
	Ones.append(Counter)
	print(sum(sorted(Ones, reverse=True)[::2]))


for _ in range(int(input())):
	s = []
	for x in input():
		s.append(int(x))
	s.append(0)
	lis = []
	count = 0
	for x in s:
		if x == 0:
			lis.append(count)
			count = 0
		else:
			count += 1
	lis.sort()
	lis = lis[::-1]
	print(sum(lis[::2]))


import sys, math
from itertools import groupby
for _ in range(int(input())):
	s = input()
	l = []
	for i in s:
		l.append(i)
	l1 = []
	for (i, j) in groupby(l):
		k = len(list(j))
		if i == '1':
			l1.append(k)
	k = 0
	l1.sort(reverse=True)
	for i in range(0, len(l1), 2):
		k = k + l1[i]
	print(k)


import sys
input = sys.stdin.readline
for f in range(int(input())):
	s = input()
	s = s[0:len(s) - 1]
	l = []
	one = False
	cur = 0
	for c in s:
		if one:
			if c == '1':
				cur += 1
			else:
				l.append(cur)
				one = False
		elif c == '1':
			one = True
			cur = 1
	if one:
		l.append(cur)
	l.sort(reverse=True)
	score = 0
	alice = True
	for x in l:
		if alice:
			score += x
			alice = False
		else:
			alice = True
	print(score)


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	s = stdin.readline().strip('\n')
	s = '0' + s + '0'
	prv = '2'
	l = []
	cnt = 0
	for i in s:
		if i == '1':
			cnt += 1
		if i == '0':
			l.append(cnt)
			cnt = 0
	l.sort(reverse=True)
	ans = 0
	for i in range(len(l)):
		if i % 2 == 0:
			ans += l[i]
	print(ans)


t = int(input())
for i in range(t):
	ar = [int(i) for i in input()]
	b = len(ar)
	one = []
	a = ar[0]
	if a == 0:
		start = False
		count = 0
	else:
		start = True
		count = 1
	for x in range(b - 1):
		if start == True:
			if ar[x + 1] == 1:
				count += 1
			else:
				one.append(count)
				count = 0
				start = False
		elif ar[x + 1] == 1:
			start = True
			count += 1
		else:
			pass
	one.append(count)
	Alice = 0
	one.sort(reverse=True)
	for f in range(len(one)):
		if f % 2 == 0:
			Alice += one[f]
		else:
			pass
	print(Alice)


for _ in range(int(input())):
	s = input()
	d = []
	count = 0
	sum = 0
	for i in range(len(s)):
		if s[i] == '1':
			count += 1
		elif s[i] == '0':
			if count != 0:
				d.append(count)
				count = 0
		if i == len(s) - 1:
			d.append(count)
	d = sorted(d)[::-1]
	for i in range(len(d)):
		if i % 2 == 0:
			sum += d[i]
	print(sum)


t = int(input())
sol = []
for i in range(t):
	s = input()
	s += '0'
	count = 0
	flag = 0
	l = []
	for i in s:
		if i == '1':
			count += 1
		if i == '0' and count != 0:
			l.append(count)
			count = 0
	l.sort()
	sol.append(sum(l[::-2]))
for i in sol:
	print(i)


t = int(input())
for _ in range(t):
	a = input()
	i = 0
	cnt_list = []
	n = len(a)
	while i < n:
		if a[i] == '1':
			c = 1
			i += 1
			if i == n:
				cnt_list.append(1)
				break
			while True and i < n:
				if a[i] == '0':
					if c > 0:
						cnt_list.append(c)
					i += 1
					break
				else:
					c += 1
					if i == n - 1:
						cnt_list.append(c)
					i += 1
		else:
			i += 1
	cnt_list = sorted(cnt_list)
	res = 0
	for i in range(len(cnt_list) - 1, -1, -2):
		res += cnt_list[i]
	print(res)


for _ in range(int(input())):
	s = str(input())
	al = []
	x = 0
	for i in s:
		if i == '1':
			x += 1
		if i == '0':
			al.append(x)
			x = 0
	al.append(x)
	al.sort(reverse=True)
	ans = 0
	for i in range(0, len(al), 2):
		ans += al[i]
	print(ans)


n = int(input())
for _ in range(n):
	alice_count = ''
	bob_count = ''
	s = input().split('0')
	x = True
	while s:
		if x:
			y = s.index(max(s))
			alice_count = alice_count + s.pop(y)
			x = False
		else:
			y = s.index(max(s))
			bob_count = bob_count + s.pop(y)
			x = True
	print(alice_count.count('1'))


for t in range(int(input())):
	s = input()
	a = []
	count = 0
	for i in s:
		if i == '1':
			count += 1
		if i == '0':
			a.append(count)
			count = 0
	a.append(count)
	a = sorted(a)
	a = a[::-1]
	p = 0
	for i in range(0, len(a), 2):
		p = p + a[i]
	print(p)


for _ in range(int(input())):
	s = input()
	array = [0]
	for i in s:
		if i == '1':
			array[-1] += 1
		elif array[-1] != 0:
			array.append(0)
	array.sort(reverse=True)
	array = array[::2]
	print(sum(array))


for _ in range(int(input())):
	s = input()
	l = s.split('0')
	a = []
	for x in l:
		if len(x) > 0:
			a.append(len(x))
	a.sort(reverse=True)
	ans = 0
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)


def function(s):
	ans = []
	i = 0
	while i < len(s):
		if s[i] == '1':
			(c, j) = (1, i + 1)
			while j < len(s) and s[j] == '1':
				c += 1
				j += 1
			ans.append(c)
			i = j
		i += 1
	sum = 0
	ans.sort(reverse=True)
	for i in range(0, len(ans), 2):
		sum += ans[i]
	return sum
t = int(input())
while t:
	s = str(input())
	print(function(s))
	t -= 1


import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	s = input()
	c = int(s[0]) & 1
	l = []
	for j in range(1, len(s)):
		if int(s[j]) & 1:
			if c == 0:
				c = 1
			elif s[j] == s[j - 1]:
				c += 1
		elif c != 0:
			l.append(c)
			c = 0
	if c != 0:
		l.append(c)
	l.sort(reverse=True)
	ans = 0
	for j in range(0, len(l), 2):
		if j % 2 == 0:
			ans += l[j]
	print(ans)


import sys

def main():
	res = ''
	input = sys.stdin.readline
	print = sys.stdout.write
	t = int(input())
	for _ in range(t):
		t = []
		s = input() + '0'
		k = 0
		for char in s:
			if char == '1':
				k += 1
			else:
				t.append(k)
				k = 0
		t.sort(reverse=True)
		sub_res = f'{sum(t[::2])}\n'
		res += sub_res
	print(res)
main()


t = int(input())
for k in range(t):
	a = input()
	e = len(a)
	b = []
	count = 0
	for i in range(len(a)):
		if a[i] == '1':
			count += 1
		else:
			if count > 0:
				b.append(count)
			count = 0
		if i == len(a) - 1:
			b.append(count)
			break
	c = sorted(b)
	c = c[::-1]
	uni = 0
	for i in range(len(c)):
		if i % 2 == 0:
			uni += c[i]
	print(int(uni))


from functools import reduce
from collections import Counter
import time
import datetime

def time_t():
	print('Current date and time: ', datetime.datetime.now())
	print('Current year: ', datetime.date.today().strftime('%Y'))
	print('Month of year: ', datetime.date.today().strftime('%B'))
	print('Week number of the year: ', datetime.date.today().strftime('%W'))
	print('Weekday of the week: ', datetime.date.today().strftime('%w'))
	print('Day of year: ', datetime.date.today().strftime('%j'))
	print('Day of the month : ', datetime.date.today().strftime('%d'))
	print('Day of week: ', datetime.date.today().strftime('%A'))

def ip():
	return int(input())

def sip():
	return input()

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

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

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

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(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)
t = ip()
while t:
	t -= 1
	s = sip()
	flag = 0
	count = 0
	val = []
	i = 0
	while i < len(s):
		if s[i] == '1':
			count = 0
			for j in range(i, len(s)):
				if s[j] == '1':
					count += 1
					i = j
				else:
					break
			val.append(count)
		i += 1
	val.sort(reverse=True)
	final = 0
	i = 0
	while i < len(val):
		final += val[i]
		i += 2
	print(final)


T = int(input())
for i in range(T):
	s = input()
	l = []
	count = 0
	for i in range(len(s)):
		if s[i] == '1':
			count += 1
		elif s[i] == '0':
			l.append(count)
			count = 0
		if i == len(s) - 1:
			l.append(count)
	l.sort(reverse=True)
	Alice_Score = 0
	Bob_Score = 0
	for i in range(len(l)):
		if i % 2 == 0:
			Alice_Score += l[i]
		else:
			Bob_Score += l[i]
	if Alice_Score > Bob_Score:
		print(Alice_Score)
	else:
		print(Bob_Score)


import sys
import math
from functools import reduce
import bisect

def getN():
	return int(input())

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

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

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

def index(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	return False
for _ in range(int(input())):
	s = input()
	seg = [0]
	new = False
	for i in range(len(s)):
		if s[i] == '1':
			seg[-1] += 1
			new = True
		elif new:
			new = False
			seg.append(0)
	seg.sort(reverse=True)
	ans = 0
	for i in range(0, len(seg), 2):
		ans += seg[i]
	print(ans)


for test in range(int(input())):
	string = input()
	listeee = []
	count = 0
	for elt in string:
		if elt == '1':
			count += 1
		else:
			listeee.append(count)
			count = 0
	listeee.append(count)
	listeee.sort(reverse=True)
	score = 0
	for i in range(0, len(listeee), 2):
		score += listeee[i]
	print(score)


for j in range(int(input())):
	s = input()
	i = 0
	ans = []
	while i < len(s):
		if s[i] == '1':
			count = i
			while i < len(s) and s[i] == '1':
				i += 1
			ans.append(i - count)
		else:
			i += 1
	if len(ans) == 0:
		print(0)
		continue
	ans.sort(reverse=True)
	res = 0
	for i in range(0, len(ans), 2):
		res += ans[i]
	print(res)


t = int(input())
for _ in range(t):
	s = input()
	l = []
	going = 0
	temp = 0
	for i in s:
		if i == '0':
			if going == 1:
				l.append(temp)
				temp = 0
				going = 0
		elif going == 0:
			going = 1
			temp = 1
		else:
			temp += 1
	if going == 1:
		l.append(temp)
	ans = 0
	l.sort(reverse=True)
	for i in range(0, len(l), 2):
		ans += l[i]
	print(ans)


n_tc = int(input())

def countOne(array):
	aux = []
	count = 0
	for el in array:
		if int(el) == 1:
			count += 1
		if int(el) == 0 and count > 0:
			aux.append(count)
			count = 0
	if count > 0:
		aux.append(count)
	return aux

def countAlice(array):
	count = 0
	isAlice = True
	for i in range(len(array)):
		max_ = max(array)
		if isAlice:
			count += max_
		isAlice = not isAlice
		array.remove(max_)
	return count
for i in range(n_tc):
	string = input()
	aux = countOne(string)
	print(countAlice(aux))


for _ in range(int(input())):
	s = input()
	t = s.split('0')
	su = 0
	t = sorted(t, reverse=True)
	for i in range(0, len(t), 2):
		su += len(t[i])
	print(su)


for _ in range(int(input())):
	a = list(input().split('0'))
	ans = 0
	li = sorted(filter(lambda x: x != '', a), key=len, reverse=True)
	for i in range(0, len(li), 2):
		ans += len(li[i])
	print(ans)


for _ in range(int(input())):
	s = input()
	s += '0'
	n = len(s)
	arr = []
	c = 0
	ans = 0
	if s[0] == '1':
		c = 1
	for i in range(1, n):
		if s[i] == '1' and s[i - 1] == '0':
			c = 1
		if s[i] == '1' and s[i - 1] == '1':
			c += 1
		if s[i] == '0' and s[i - 1] == '1':
			arr.append(c)
	arr.sort()
	for i in range(len(arr) - 1, -1, -2):
		ans += arr[i]
	print(ans)


test = int(input())
for t in range(test):
	str1 = input()
	if '1' not in str1:
		print(0)
	elif '0' not in str1:
		print(len(str1))
	else:
		lst = list()
		count = 0
		for i in range(len(str1)):
			if str1[i] == '0':
				lst.append(i + 1)
		lst2 = list()
		a = lst[0] - 1
		if a >= 1:
			lst2.append(a)
		for x in range(len(lst)):
			if x + 1 < len(lst):
				lst2.append(lst[x + 1] - lst[x] - 1)
		b = len(str1) - lst[len(lst) - 1]
		if b >= 1:
			lst2.append(b)
		lst2.sort()
		Alice = 0
		for x in range(len(lst2)):
			if len(lst2) % 2 == 0:
				if x % 2 != 0:
					Alice = Alice + lst2[x]
			elif x % 2 == 0:
				Alice = Alice + lst2[x]
		print(Alice)


for _ in range(int(input())):
	c = 0
	ls = []
	j = input()
	r = 0
	for k in range(len(j)):
		if j[k] == '1':
			r += 1
		elif r != 0:
			ls.append(r)
			r = 0
		if k == len(j) - 1:
			ls.append(r)
	ls.sort()
	ls.reverse()
	for ii in range(0, len(ls), 2):
		c += ls[ii]
	print(c)


import bisect
for _ in range(int(input())):
	s = input()
	n = len(s)
	a = []
	i = 0
	while i < n:
		if s[i] == '1':
			c = 0
			j = i
			while j < n:
				if s[j] == '0':
					break
				c += 1
				j += 1
			i = j
			a.append(c)
			if j == n:
				break
		i += 1
	s1 = 0
	a.sort()
	a.reverse()
	for i in range(len(a)):
		if i & 1 == 0:
			s1 += a[i]
	print(s1)


for i in range(int(input())):
	s = str(input())
	(counter, sounter, x) = (0, 0, [])
	for j in s:
		if j == '1':
			counter += 1
		else:
			x.append(counter)
			counter = 0
	x.append(counter)
	x.sort(reverse=True)
	for k in range(0, len(x), 2):
		sounter += x[k]
	print(sounter)


from itertools import groupby
for _ in range(int(input())):
	s = input()
	l = []
	for (i, j) in groupby(s):
		if i == '1':
			l.append(len(list(j)))
	l.sort(reverse=True)
	c = 0
	n = len(l)
	for i in range(0, n, 2):
		c += l[i]
	print(c)


for t in range(int(input())):
	s = input()
	n = len(s)
	(sol, pin) = ([0] * 2, 0)
	while True:
		i = j = 0
		bi = bj = -1
		while i < n:
			if s[i] == '1':
				j = i
				while j < n and s[j] == '1':
					j += 1
				if j - i >= bj - bi:
					(bi, bj) = (i, j)
				i = j
			else:
				i += 1
		if bi >= 0:
			sol[pin] += bj - bi
			s = s[:bi] + s[bj:]
			n -= bj - bi
		else:
			print(sol[0])
			break
		pin ^= 1


for _ in range(int(input())):
	s = list(input())
	a = []
	c = 0
	x = 0
	if all((x == '0' for x in s)):
		print('0')
	elif all((x == '1' for x in s)):
		print(len(s))
	else:
		for i in range(len(s)):
			if s[i] == '1':
				c = c + 1
			elif c != 0:
				a.append(c)
				c = 0
		if s[-1] == '1':
			a.append(c)
		a.sort(reverse=True)
		for i in range(len(a)):
			if i % 2 == 0:
				x = x + a[i]
		print(x)


t = int(input())
for _ in range(t):
	s = input()
	ones = []
	curr = 0
	for i in range(len(s)):
		if s[i] == '0' and curr != 0:
			ones.append(curr)
			curr = 0
		elif s[i] == '1':
			curr += 1
	if curr > 0:
		ones.append(curr)
	ones = sorted(ones, reverse=True)
	answer = 0
	for i in range(0, len(ones), 2):
		answer += ones[i]
	print(answer)


res = ''
for _ in range(int(input())):
	s = input()
	prev = s[0]
	blocks = []
	curr = prev == '1'
	for letter in s[1:]:
		if letter == '1':
			curr += 1
		elif curr != 0:
			blocks.append(curr)
			curr = 0
		prev = letter
	if curr != 0:
		blocks.append(curr)
	blocks.sort(reverse=True)
	ans = 0
	for i in range(0, len(blocks), 2):
		ans += blocks[i]
	res += '%d\n' % ans
print(res)


t = int(input())
for _ in range(t):
	s = input()
	temp = 0
	one = []
	for x in s:
		if x == '0':
			if temp != 0:
				one += [temp]
			temp = 0
		else:
			temp += 1
	if temp != 0:
		one += [temp]
	one.sort(reverse=True)
	ans = 0
	for i in range(0, len(one), 2):
		ans += one[i]
	print(ans)


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 ** 19
MOD = 10 ** 9 + 7

def RLE(data):
	from itertools import groupby
	return [(x, len(list(grp))) for (x, grp) in groupby(data)]
for _ in range(INT()):
	S = input()
	N = len(S)
	rle = RLE(S)
	rle.sort(reverse=1)
	ans = 0
	for (i, (k, v)) in enumerate(rle):
		if k == '0':
			break
		if i % 2 == 0:
			ans += v
	print(ans)


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

def solve():
	string = input()
	sequences = []
	currSeqLength = 0
	for number in string:
		if number == '0':
			if currSeqLength > 0:
				sequences.append(currSeqLength)
				currSeqLength = 0
		else:
			currSeqLength += 1
	if currSeqLength > 0:
		sequences.append(currSeqLength)
	sequences.sort()
	points = [0, 0]
	curr = 0
	for i in range(len(sequences) - 1, -1, -1):
		points[curr] += sequences[i]
		curr = 1 - curr
	print(points[0])
main()


for t in range(int(input())):
	s = input()
	tekchar = s[0]
	teklen = 1
	a = []
	for i in range(1, len(s)):
		if s[i] == tekchar:
			teklen += 1
		else:
			if tekchar == '1':
				a.append(teklen)
			tekchar = s[i]
			teklen = 1
	if tekchar == '1':
		a.append(teklen)
	a.sort(reverse=True)
	print(sum(a[0::2]))


gans = []
for _ in range(int(input())):
	u = list(map(int, list(input())))
	n = len(u)
	w = []
	k = 0
	for i in range(n):
		if u[i] == 1:
			k += 1
		else:
			if k > 0:
				w.append(k)
			k = 0
	if k > 0:
		w.append(k)
	w.sort(reverse=1)
	ans = 0
	for i in range(0, len(w), 2):
		ans += w[i]
	gans.append(ans)
print('\n'.join(map(str, gans)))


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

def nn():
	return int(input())

def li():
	return list(input())

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

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

def solve():
	s = input()
	sets = []
	streak = 0
	for i in range(len(s)):
		if s[i] == '1':
			streak += 1
		elif streak > 0:
			sets.append(streak)
			streak = 0
	if streak > 0:
		sets.append(streak)
		streak = 0
	sets.sort(reverse=True)
	print(sum(sets[::2]))
q = nn()
for _ in range(q):
	solve()


from itertools import groupby

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

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

def solve():
	s = input()
	score = 0
	turn = True
	ones = sorted((sum((1 for _ in v)) for (k, v) in groupby(s) if k == '1'))
	while ones:
		if turn:
			score += ones.pop()
		else:
			ones.pop()
		turn = not turn
	return score
T = read_int()
for _ in range(T):
	print(solve())


for _ in range(int(input())):
	str1 = input()
	list1 = list(str1)
	list2 = []
	count1 = 0
	for i in range(len(list1)):
		if list1[i] == '0':
			list2.append(count1)
			count1 = 0
		else:
			count1 += 1
	if count1 != 0:
		list2.append(count1)
	list2.sort()
	list2.reverse()
	sum1 = 0
	for i in range(0, len(list2), 2):
		if i <= len(list2) - 1:
			sum1 += list2[i]
	print(sum1)


t = int(input())
for x in range(t):
	s = str(input())
	l = len(s)
	w = 0
	alice = 0
	while l != 0:
		a = 0
		y = 0
		j = -1
		k = -1
		jj = -1
		kk = -1
		while y < l:
			if s[y] == '0':
				y += 1
			else:
				aa = 1
				j = y
				k = y
				y += 1
				while y < l and s[y] == '1':
					aa += 1
					k += 1
					y += 1
				if aa > a:
					a = aa
					jj = j
					kk = k
		if j == -1:
			break
		else:
			lt = len(s)
			s = s[0:jj] + s[kk + 1:lt]
			if w == 0:
				w = 1
				bbb = kk - jj + 1
				alice += bbb
			else:
				w = 0
		l = len(s)
	print(alice)


for _ in range(int(input())):
	a = [i for i in input()]
	cnt = 0
	ans = []
	i = 0
	n = len(a)
	while i < n:
		if a[i] == '1':
			cnt += 1
			while i + 1 < n and a[i + 1] == '1':
				cnt += 1
				i += 1
			ans.append(cnt)
			cnt = 0
			i += 1
		else:
			cnt = 0
			i += 1
	m = len(ans)
	if m == 0:
		print(0)
	else:
		ans.sort(reverse=True)
		k = m // 2 + 1
		su = 0
		for i in range(0, m, 2):
			su += ans[i]
		print(su)


T = input()
T = int(T)

def solve(s):
	counts = []
	count = 0
	for x in s:
		if x == '1':
			count += 1
		elif count > 0:
			counts.append(count)
			count = 0
	if s[-1] == '1':
		counts.append(count)
	counts.sort(reverse=True)
	ans = 0
	for i in range(len(counts)):
		if i % 2 == 0:
			ans += counts[i]
	print(ans)
for i in range(T):
	s = input()
	solve(s)


from itertools import groupby

def solve(arr):
	g = groupby(arr)
	res = []
	for (k, v) in g:
		res.append((k, str(len(list(v)))))
	result = [int(x[1]) for x in res if x[0] == '1']
	result.sort(reverse=True)
	print(sum(result[0::2]))
n = int(input())
for _ in range(n):
	arr = input()
	solve(arr)


for t in range(int(input())):
	word = input().split('0')
	z = word.count('')
	score = 0
	word = sorted(word)
	for i in range(0, len(word) - z, 2):
		score += word[len(word) - i - 1].count('1')
	print(score)


t = int(input())
for _ in range(t):
	inp = input()
	res = []
	cnt = 0
	for i in range(len(inp)):
		if int(inp[i]) == 1:
			cnt += 1
		if int(inp[i]) == 0 and cnt > 0 or i == len(inp) - 1:
			res.append(cnt)
			cnt = 0
	result = 0
	res.sort(reverse=True)
	for i in range(len(res)):
		if i % 2 == 0:
			result = result + res[i]
	print(result)


t = int(input())
while t > 0:
	t -= 1
	a = input()
	a = list(a)
	n = len(a)
	i = 0
	while i < n:
		a[i] = int(a[i])
		i += 1
	stack = []
	ct = 0
	i = 0
	while i < n:
		if a[i] == 1:
			ct += 1
		if a[i] == 0:
			if ct != 0:
				stack.append(ct)
			ct = 0
		i += 1
	if ct != 0:
		stack.append(ct)
	stack.sort(reverse=True)
	ans = 0
	l = len(stack)
	i = 0
	while i < l:
		ans += stack[i]
		i += 2
	print(ans)


t = int(input())
for _ in range(t):
	arr = [int(x) for x in input()]
	li = []
	cnt = 0
	for i in range(len(arr)):
		if arr[i] == 0:
			if cnt > 0:
				li.append(cnt)
			cnt = 0
		else:
			cnt += 1
	if cnt > 0:
		li.append(cnt)
	li.sort(reverse=True)
	ans = 0
	for i in range(0, len(li), 2):
		ans += li[i]
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	(m, count) = (0, 0)
	a = []
	for i in range(len(s)):
		if s[i] == '1':
			count += 1
		else:
			a.append(count)
			count = 0
	if count > 0:
		a.append(count)
	a = sorted(a, key=int, reverse=True)
	for i in range(len(a)):
		if i % 2 == 0:
			m += a[i]
	print(m, end='\n')


t = int(input())
for i in range(t):
	a = input()
	b = list()
	c0 = 0
	c1 = 0
	for j in range(len(a)):
		if a[j] == '0':
			c0 -= 1
			if j != 0 and a[j - 1] == '1':
				b.append(c1)
			c1 = 0
		else:
			c1 += 1
			c0 = 0
	if c1 != 0:
		b.append(c1)
	b.sort(reverse=True)
	ans = 0
	for i in range(len(b)):
		if i % 2 == 0:
			ans += b[i]
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	l = list()
	count = 0
	for i in s:
		if i == '1':
			count += 1
		else:
			l.append(count)
			count = 0
	if count != 0:
		l.append(count)
	l.sort()
	total = 0
	for i in range(len(l) - 1, -1, -2):
		total += l[i]
	print(total)


t = int(input())
for test in range(t):
	s = str(input())
	cnt = 0
	l = []
	start = s[0]
	for i in range(1, len(s)):
		if start == s[i]:
			cnt += 1
		else:
			l.append([start, cnt + 1])
			start = s[i]
			cnt = 0
	l.append([start, cnt + 1])
	ones = []
	for it in l:
		if it[0] == '1':
			ones.append(it[1])
	ones.sort(reverse=True)
	sum = 0
	for i in range(0, len(ones), 2):
		sum += ones[i]
	print(sum)


t = int(input())
for tc in range(t):
	line = input()
	arr = []
	count = 0
	n = len(line)
	for i in range(n):
		if line[i] == '1':
			count += 1
		else:
			arr.append(count)
			count = 0
		if i == n - 1:
			arr.append(count)
	if i == '1':
		count += 1
		arr.append(count)
	score = 0
	arr.sort(reverse=True)
	for i in range(0, len(arr), 2):
		score += arr[i]
	print(score)


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	s = stdin.readline().strip()
	s = s.split('0')
	r = []
	for i in s:
		if len(i) != 0:
			r.append(len(i))
	r = sorted(r, reverse=True)
	if len(r) == 0:
		stdout.write('0\n')
	else:
		stdout.write(str(sum(r[0::2])) + '\n')


def solv():
	s = input()
	lst = []
	cnt = 0
	s = s + '0'
	for i in range(len(s)):
		if s[i] == '1':
			cnt = cnt + 1
		else:
			lst.append(cnt)
			cnt = 0
	lst.sort(reverse=True)
	ans = 0
	for i in range(0, len(lst), 2):
		ans = ans + lst[i]
	print(ans)
p = input()
for i in range(int(p)):
	solv()


for _ in range(int(input())):
	s = list(input())
	shit = 0
	l1 = []
	flag = 0
	for i in s:
		if i == '1':
			flag = 1
			shit += 1
		if i == '0':
			if flag == 1:
				l1.append(shit)
				flag = 0
			shit = 0
	if s[-1] == '1':
		l1.append(shit)
	l1.sort(reverse=True)
	ans = 0
	if len(l1) == 0:
		print(0)
		continue
	for i in range(0, len(l1), 2):
		ans += l1[i]
	print(ans)


t = int(input())
for i in range(t):
	arr = list((int(i) for i in input()))
	arri = []
	i = 0
	while i < len(arr):
		if arr[i] == 1:
			ans = 1
			i += 1
			while i < len(arr) and arr[i] == 1:
				ans += 1
				i += 1
			arri.append(ans)
		else:
			i += 1
	a = 0
	arri = sorted(arri)
	arri = arri[::-1]
	for i in range(len(arri)):
		if i % 2 == 0:
			a += arri[i]
	print(a)


T = int(input())
while T:
	s = input()
	D = []
	c = 0
	for i in s:
		if i == '1':
			c += 1
		else:
			if c != 0:
				D.append(c)
			c = 0
	if c != 0:
		D.append(c)
	D.sort(reverse=True)
	x = 0
	for i in range(len(D)):
		if i % 2 == 0:
			x += D[i]
	print(x)
	T = T - 1


a = int(input())
for i in range(a):
	u = str(input())
	ans = 0
	n = len(u)
	l2 = list(map(str, u.split('0')))
	l2.sort()
	for j in range(len(l2) - 1, -1, -2):
		ans += len(l2[j])
	print(ans)


t = int(input())
while t > 0:
	s = input()
	l = []
	k = -1
	for i in range(len(s)):
		if s[i] == '0' and i - k > 1:
			l.append(i - k - 1)
			k = i
		elif s[i] == '0':
			k = i
	if s[-1] != '0':
		l.append(len(s) - 1 - k)
	l.sort(reverse=True)
	ans = 0
	for i in range(0, len(l), 2):
		ans += l[i]
	print(ans)
	t -= 1


def sub(s):
	ans = []
	o = 0
	l = len(s)
	for x in range(l):
		if s[x] == '1':
			o += 1
			if x == l - 1:
				ans.append(o)
		elif s[x] == '0':
			if o == 0:
				continue
			else:
				ans.append(o)
				o = 0
	ans.sort()
	final = ans[-1::-2]
	return sum(list(map(int, final)))
t = int(input())
array = []
for i in range(t):
	array.append(input())
for x in array:
	print(sub(x))


ZERO = '0'
ONE = '1'

def compute_player_1_score(bin_string):
	ones_seqs = bin_string.replace(ZERO, ' ').split()
	ones_seqs = sorted(ones_seqs, key=len)
	player_1_score = 0
	player_2_score = 0
	while ones_seqs:
		player_1_score += len(ones_seqs[-1])
		ones_seqs.pop()
		if not ones_seqs:
			break
		player_2_score += len(ones_seqs[-1])
		ones_seqs.pop()
	return player_1_score

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


import math as mt

def tran(s):
	cou = []
	i = 0
	while i < len(s) - 1:
		if s[i] == '1':
			c = 1
			while c + i < len(s) and s[i + c] == '1':
				c += 1
			cou.append(c)
			i = i + c
		else:
			i += 1
	if len(s) > 1 and s[-1] == '1' and (s[-2] == '0'):
		cou.append(1)
	elif len(s) == 1 and s[0] == '1':
		cou.append(1)
	cou.sort()
	cou.reverse()
	an = 0
	for i in range(0, len(cou), 2):
		an += cou[i]
	return an
t = int(input())
ans = []
for i in range(t):
	s = input()
	r = tran(s)
	ans.append(r)
for i in ans:
	print(i)


for tt in range(int(input())):
	s = input()
	cons = []
	ctx = 0
	for i in range(len(s)):
		if s[i] == '1':
			ctx += 1
		else:
			if ctx:
				cons.append(ctx)
			ctx = 0
	if ctx:
		cons.append(ctx)
	if cons:
		cons.sort(reverse=True)
		sm = 0
		for i in range(0, len(cons)):
			if i % 2 == 0:
				sm += cons[i]
		print(sm)
	else:
		print(0)


for _ in range(int(input())):
	s = input()
	list1 = s.split('0')
	list1 = list(filter(None, list1))
	for i in range(len(list1)):
		list1[i] = len(list1[i])
	list1.sort()
	sum1 = 0
	while len(list1) != 0:
		sum1 += list1[-1]
		del list1[-1]
		try:
			del list1[-1]
		except:
			pass
	print(sum1)


t = int(input())
for _ in range(t):
	s = input()
	ans = 0
	ones = []
	one = 0
	s += '0'
	for ch in s:
		if ch == '1':
			one += 1
		elif one > 0:
			ones.append(one)
			one = 0
	ones.sort(reverse=True)
	for i in range(len(ones)):
		if i % 2 == 0:
			ans += ones[i]
	print(ans)


def remove_values(the_list, val):
	return [value for value in the_list if value != val]
for i in range(int(input())):
	s = input()
	a = list(map(len, s.split('0')))
	a = remove_values(a, 0)
	(A, B) = (0, 0)
	ma = 0
	for i in range(1000):
		if len(a) == 0:
			break
		ma = max(a)
		A += ma
		a.remove(ma)
		if len(a) == 0:
			break
		ma = max(a)
		B += ma
		a.remove(ma)
	print(A)


for _ in range(int(input())):
	a = []
	for i in input().split('0'):
		if len(i) > 0:
			a.append(len(i))
	a.sort(reverse=True)
	c = 0
	for i in range(0, len(a), 2):
		c += a[i]
	print(c)


t = int(input())
for _ in range(t):
	score = [0, 0]
	user = 0
	s = input()
	while len(s) > 0:
		mxlen = -1
		mxidx = -1
		i = 0
		while True:
			if i >= len(s):
				break
			c = s[i]
			if c == '1':
				j = i + 1
				while True:
					if j == len(s) or s[j] == '0':
						break
					j += 1
				if j - i > mxlen:
					mxlen = j - i
					mxidx = i
				i = j
			else:
				i += 1
		if mxlen != -1:
			score[user] += mxlen
		else:
			break
		s = s[:mxidx] + s[mxidx + mxlen:]
		user = abs(user - 1)
	print(score[0])


from sys import *
input = stdin.readline
output = stdout.write
for _ in range(int(input())):
	s = input()
	s = s[:-1]
	a = []
	cn = 0
	for i in range(len(s)):
		if cn == 0 and s[i] == '0':
			continue
		elif cn != 0 and s[i] == '0':
			a.append(cn)
			cn = 0
		else:
			cn += 1
	if cn > 0:
		a.append(cn)
	a.sort(reverse=True)
	sn = 0
	for i in range(0, len(a), 2):
		sn += a[i]
	stdout.write(str(sn) + '\n')


t = int(input())
for tt in range(t):
	s = input()
	cnt = 0
	freq = []
	for c in s:
		if c == '0':
			freq.append(cnt)
			cnt = 0
		else:
			cnt += 1
	if cnt != 0:
		freq.append(cnt)
	freq.sort(reverse=True)
	score = 0
	for i in range(len(freq)):
		if i % 2 == 0:
			score += freq[i]
	print(score)


t = int(input())
for i in range(t):
	s = input()
	c = 0
	l = []
	for j in range(len(s)):
		if s[j] == '1':
			c += 1
		elif c != 0:
			l.append(c)
			c = 0
	if c != 0:
		l.append(c)
	l = sorted(l, reverse=True)[::2]
	print(sum(l))


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

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

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

def solve():
	S = input()
	blocks = [len(s) for s in S.split('0') if s != '']
	blocks.sort(reverse=True)
	total = 0
	for i in range(0, len(blocks), 2):
		total += blocks[i]
	print(total)
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


t = int(input())
for i in range(t):
	s = input()
	ones = []
	current = 0
	for c in s:
		if c == '1':
			current += 1
		elif c == '0':
			if current > 0:
				ones.append(current)
			current = 0
	if current > 0:
		ones.append(current)
	ones.sort()
	ones = ones[::-1]
	print(sum((x if i % 2 == 0 else 0 for (i, x) in enumerate(ones))))


def solve(s):
	freq = []
	cnt = 0
	for i in range(len(s)):
		if s[i] == '0':
			if cnt > 0:
				freq.append(cnt)
			cnt = 0
			continue
		else:
			cnt += 1
			if i == len(s) - 1:
				freq.append(cnt)
	freq = sorted(freq, reverse=True)
	ans = 0
	for i in range(len(freq)):
		if i % 2 == 0:
			ans += freq[i]
	print(ans)
t = int(input())
for _ in range(t):
	s = input()
	solve(s)


T = int(input())
for _ in range(T):
	s = input()
	a = []
	cnt = 0
	for i in range(len(s)):
		if s[i] == '1':
			cnt += 1
		elif s[i] == '0' and cnt:
			a.append(cnt)
			cnt = 0
	if cnt:
		a.append(cnt)
	a.sort()
	a.reverse()
	(sm, asm) = (0, 0)
	for i in range(len(a)):
		sm += a[i]
		if i % 2 == 0:
			asm += a[i]
	if sm:
		print(max(asm, sm - asm))
	else:
		print(0)


t = int(input())
while t:
	s = list(input())
	arr = []
	ans = 0
	for i in range(len(s)):
		if s[i] == '1':
			ans += 1
		elif ans:
			arr.append(ans)
			ans = 0
	if ans:
		arr.append(ans)
	ans = 0
	arr.sort(reverse=True)
	for i in range(0, len(arr), 2):
		ans += arr[i]
	print(ans)
	t -= 1


for i in range(int(input())):
	A = str(input())
	B = []
	cnt = 0
	ans = 0
	for k in range(len(A)):
		if int(A[k]) == 0:
			if cnt > 0:
				B.append(cnt)
				cnt = 0
			cnt = 0
		if int(A[k]) == 1:
			cnt += 1
	else:
		if int(A[k]) == 1:
			B.append(cnt)
	B = sorted(B, reverse=True)
	for b in range(0, len(B), 2):
		ans += B[b]
	print(ans)


t = int(input())
while t > 0:
	s = input()
	l = []
	l = [len(i) for i in s.split('0') if len(i) > 0]
	alice = 0
	if len(l) > 0:
		alice = alice + max(l)
		l.remove(max(l))
		while len(l) > 0:
			l.remove(max(l))
			if len(l) > 0:
				alice = alice + max(l)
				l.remove(max(l))
			else:
				break
	print(alice)
	t -= 1


for _ in range(int(input())):
	s = [int(i) for i in input()]
	n = len(s)
	ans = []
	i = 0
	c = 1
	while i < n:
		if s[i] == 1:
			while i < n - 1 and s[i + 1] == 1:
				c += 1
				i += 1
			ans.append(c)
			i += 1
			c = 1
		else:
			i += 1
	ans = sorted(ans, reverse=True)
	ans1 = sum(ans[::2])
	ans2 = sum(ans[1::2])
	print(max(ans1, ans2))


for _ in range(int(input())):
	s = input()
	s = s.lstrip('0')
	l = s.split('0')
	l.sort()
	l2 = [len(l[i]) for i in range(-1, -(len(l) + 1), -2)]
	print(sum(l2))


def answer(A):
	l = []
	count = 0
	for i in range(len(A)):
		if A[i] == '1':
			count += 1
		else:
			if count > 0:
				l.append(count)
			count = 0
	if count > 0:
		l.append(count)
	l.sort(reverse=True)
	ans = 0
	for i in range(0, len(l), 2):
		ans += l[i]
	return ans
t = int(input())
for i in range(t):
	n = input()
	print(answer(n))


for t in range(int(input())):
	s = input().strip()
	n = len(s)
	ones = []
	i = 0
	sums = 0
	while i < n - 1:
		if s[i] == '1':
			sums += 1
			if s[i + 1] == '0':
				ones.append(sums)
				sums = 0
		i += 1
	if sums > 0 and i == n - 1:
		ones.append(sums + 1)
	elif i == n - 1 and s[i] == '1':
		ones.append(1)
	ones = sorted(ones, reverse=True)
	result = 0
	i = 0
	while 2 * i < len(ones):
		result += ones[2 * i]
		i += 1
	print(result)


t = int(input())
for inh in range(0, t):
	s = input()
	a = []
	j = 0
	for i in range(0, len(s)):
		if s[i] == '1':
			j += 1
		else:
			if j > 0:
				a.append(j)
			j = 0
	if j > 0:
		a.append(j)
	a.sort(reverse=True)
	ans = 0
	i = 0
	while i < len(a):
		ans += a[i]
		i += 2
	print(ans)


import heapq
t = int(input())
for i in range(t):
	S = input() + '0'
	n = len(S)
	ones = []
	j = 0
	count = 0
	while j < n:
		if S[j] == '1':
			count += 1
		else:
			heapq.heappush(ones, -count)
			count = 0
		j += 1
	ans = 0
	while ones:
		ans -= heapq.heappop(ones)
		if ones:
			heapq.heappop(ones)
	print(ans)


for _ in range(int(input())):
	string = input()
	temp = list()
	count = 0
	for i in range(len(string)):
		if string[i] == '1':
			count += 1
		else:
			if count != 0:
				temp.append(count)
			count = 0
	if count != 0:
		temp.append(count)
	print(sum(sorted(temp, reverse=True)[0::2]))


from sys import stdin, stdout
from math import gcd
from collections import defaultdict
from sys import getsizeof
input = stdin.readline
print = stdout.write

def fun(s):
	n = len(s)
	count = []
	noof1 = 0
	for i in range(n):
		if s[i] == '1':
			noof1 += 1
		elif noof1:
			count.append(noof1)
			noof1 = 0
	return count
for i in range(int(input())):
	s = input()
	count = fun(s)
	count.sort(reverse=True)
	sumcount = 0
	for i in range(len(count)):
		if i % 2 == 0:
			sumcount += count[i]
	print(str(sumcount) + '\n')


t = int(input())
for _ in range(t):
	string = input()
	(flag, count, out) = (int(string[0]), 1, [])
	for s in string[1:]:
		if flag == int(s):
			count += 1
		else:
			if flag:
				out.append(count)
			flag = int(s)
			count = 1
	else:
		if flag:
			out.append(count)
	print(sum([val for (idx, val) in enumerate(sorted(out, reverse=True)) if idx % 2 == 0]))


t = int(input())
for _ in range(t):
	s = input()
	l = []
	cnt = 0
	for i in s:
		if i == '1':
			cnt += 1
		elif cnt != 0:
			l.append(cnt)
			cnt = 0
	if cnt != 0:
		l.append(cnt)
	l.sort(reverse=True)
	i = 0
	x = len(l)
	sum_ = 0
	while i < x:
		sum_ += l[i]
		i += 2
	print(sum_)


for u in range(int(input())):
	s = input()
	temp = 0
	x = []
	for i in range(len(s)):
		if s[i] == '1':
			temp += 1
		else:
			x.append(temp)
			temp = 0
	if s[-1] == '1':
		x.append(temp)
	x = sorted(x)[::-1]
	ans = 0
	for i in range(len(x)):
		if i % 2 == 0:
			ans += x[i]
	print(ans)


t = int(input().split()[0])
for case in range(t):
	ones = []
	s = input().split()[0]
	curr = 0
	for i in range(len(s)):
		if s[i] == '1':
			curr += 1
			continue
		if curr > 0:
			ones.append(curr)
		curr = 0
	if curr > 0:
		ones.append(curr)
	ones.sort()
	ans = 0
	for i in range(len(ones) - 1, -1, -2):
		ans += ones[i]
	print(ans)


t = int(input())
ans = []
for i in range(t):
	s = input()
	d = [0 for i in range(len(s) + 1)]
	k = len(s)
	while k > 0 and len(s) > 0:
		n = '1'
		while len(n) < k:
			n = n + '1'
		d[k] = s.count(n)
		for j in range(0, d[k]):
			s = s.replace(n, '')
		k -= 1
	count = 0
	taken = 2
	for j in reversed(range(len(d))):
		while d[j] != 0:
			if d[j] > 0 and taken % 2 == 0:
				count += j
				taken += 1
				d[j] -= 1
			elif d[j] > 0 and taken % 2 != 0:
				d[j] -= 1
				taken += 1
	ans.append(count)
for i in ans:
	print(i)


def solv():
	s = list(map(int, input()))
	v = []
	sm = 0
	for n in s:
		if n:
			sm += 1
		else:
			v.append(sm)
			sm = 0
	if sm:
		v.append(sm)
	v.sort(reverse=True)
	res = 0
	for n in range(0, len(v), 2):
		res += v[n]
	print(res)
for _ in range(int(input())):
	solv()


def solve():
	S = input()
	vals = []
	(s, t) = (0, 0)
	while s < len(S):
		if S[s] == '0':
			s += 1
			continue
		t = s
		while t < len(S) and S[t] == '1':
			t += 1
		vals.append(t - s)
		s = t
	vals = sorted(vals, reverse=True)
	return sum(vals[::2])
TC = int(input())
for _ in range(TC):
	print(solve())


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


k = int(input())
for i in range(k):
	x = input()
	x = x + '0'
	y = 0
	a = []
	sum = 0
	for i in range(len(x)):
		if x[i] == '1':
			y = y + 1
		elif x[i] == '0' and x[i - 1] == '1':
			a.append(y)
			y = 0
	a.sort()
	a.reverse()
	for i in range(len(a)):
		if i % 2 == 0:
			sum = sum + a[i]
	print(sum)


for _ in range(int(input())):
	(a, b, c) = (['0'] + list(str(input())) + ['0'], [], [])
	for i in range(len(a)):
		if a[i] == '0':
			b.append(i)
	for i in range(len(b) - 1):
		c.append(b[i + 1] - b[i] - 1)
	c.sort(reverse=True)
	sa = 0
	for i in range(len(c)):
		if i % 2 == 0:
			sa += c[i]
	print(sa)


n = int(input())
for k in range(n):
	s = input()
	l = s.split('0')
	ls = []
	for i in l:
		a = i.count('1')
		ls.append(a)
	ls = sorted(ls, reverse=True)
	aa = 0
	for (num, j) in enumerate(ls):
		if num % 2 == 0:
			aa = j + aa
	print(aa)


def score(s):
	score_a = 0
	turn = 0
	while s.find('1') != -1:
		(max_l, curr_l) = (0, 0)
		for i in range(len(s)):
			if s[i] == '1':
				curr_l += 1
			else:
				if curr_l > max_l:
					max_l = curr_l
				curr_l = 0
		if curr_l > max_l:
			max_l = curr_l
		pos = s.find('1' * max_l)
		s = s[:pos] + s[pos + max_l + 1:]
		if turn % 2 == 0:
			score_a += max_l
		turn += 1
	return score_a
for i in range(int(input())):
	s = input()
	print(score(s))


for s in [*open(0)][1:]:
	a = sorted(list(map(len, s[:-1].split('0'))))
	print(sum(a[-1::-2]))


for _ in range(int(input())):
	s = input()
	s = s.split('0')
	s.sort()
	if len(s) == 1:
		print(len(s[0]))
	elif len(s) == 0:
		print(0)
	else:
		ans = 0
		for i in range(len(s) - 1, -1, -2):
			ans += len(s[i])
		print(ans)


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	ans = []
	i = 0
	while i < n:
		cnt = 0
		start = i
		while i < n and s[i] == '1':
			i += 1
			cnt += 1
		if i != start:
			ans.append(cnt)
		i += 1
	ans.sort()
	score = 0
	x = len(ans)
	for j in range(x - 1, -1, -2):
		score += ans[j]
	print(score)


for _ in range(int(input())):
	s = input().split('0')
	s.sort(key=lambda x: len(x), reverse=True)
	print(sum([len(s[x]) for x in range(0, len(s), 2)]))


(N,) = map(int, input().split())
for _ in range(N):
	s = input().strip()
	s += '0'
	m = 0
	K = []
	for c in s:
		if c == '1':
			m += 1
		else:
			K.append(m)
			m = 0
	K.sort()
	K = K[::-1]
	R = 0
	for i in range(len(K)):
		if i % 2 == 0:
			R += K[i]
	print(R)


from sys import *
input = stdin.readline
t = int(input())
for case in range(t):
	s = input().rstrip()
	Ans = 0
	move = 0
	while True:
		if not s or int(s) == 0:
			break
		s_split = s.split('0')
		max_seq = (0, '')
		for part in s_split:
			if len(part) > max_seq[0]:
				max_seq = (len(part), part)
		idx = s.index(max_seq[-1])
		s = s[:idx] + s[idx + max_seq[0]:]
		if move % 2:
			move += 1
			continue
		Ans += max_seq[0]
		move += 1
	print(Ans)


n = int(input())
lst = ''
i = 0
while i != n:
	insrt = ''
	inpt = input()
	for j in range(len(inpt)):
		if inpt[j] != '0':
			insrt += inpt[j]
		elif inpt[j] == '0' and j > 0:
			insrt += ' '
	lst += insrt
	insrt = ''
	i += 1
	lst = lst.split(' ')
	lst = sorted(lst, reverse=True)
	for k in lst:
		if k == '':
			lst.remove(k)
	alice = 0
	for p in range(len(lst)):
		if p % 2 == 0:
			alice += len(lst[p])
	print(alice)
	alice = 0
	lst = ''


for i in range(int(input())):
	s = input()
	c = 0
	ans = []
	for j in range(len(s)):
		if s[j] == '1':
			c += 1
		else:
			if c > 0:
				ans.append(c)
			c = 0
	if c > 0:
		ans.append(c)
	ans.sort(reverse=True)
	result = 0
	for j in range(len(ans)):
		if j % 2 == 0:
			result += ans[j]
	print(result)


for t in range(int(input())):
	a = input()
	l = []
	count = 0
	flag = 0
	for i in a:
		if i == '1':
			flag = 1
			count += 1
		elif flag == 1 and i == '0':
			l.append(count)
			flag = 0
			count = 0
	if count > 0:
		l.append(count)
	l.sort(reverse=True)
	count = 0
	for i in range(0, len(l), 2):
		count += l[i]
	print(count)


try:
	t = int(input())
	while t != 0:
		arr = input()
		arr = list(arr)
		(i, count) = (0, 0)
		popi = []
		while i != len(arr):
			if arr[i] == '1':
				count = count + 1
			elif count > 0:
				popi.append(count)
				count = 0
			i = i + 1
		if count > 0:
			popi.append(count)
		popi = sorted(popi, key=lambda x: -x)
		(j, sumi) = (0, 0)
		while j < len(popi):
			sumi += popi[j]
			j = j + 2
		print(sumi)
		t = t - 1
except EOFError:
	print(' ')


for _ in range(int(input())):
	A = input()
	X = []
	n = len(A)
	c = 0
	for _ in range(n):
		if A[_] == '1':
			c += 1
		else:
			if c != 0:
				X.append(c)
			c = 0
	X.append(c)
	X = list(reversed(sorted(X)))
	x = 0
	for _ in range(len(X)):
		if _ % 2 == 0:
			x += X[_]
	print(x)


import re
for j in range(int(input())):
	s = input()
	pattern = re.compile('1+')
	li = [len(value) for value in re.findall(pattern, s)]
	score = 0
	li.sort(reverse=True)
	for i in range(len(li)):
		if i % 2 == 0:
			score += li[i]
	print(score)


for _ in range(int(input())):
	s = input()
	count = 0
	sub = []
	for i in s:
		if i == '1':
			count += 1
		else:
			if not count == 0:
				sub.append(count)
			count = 0
	if not count == 0:
		sub.append(count)
	sub.sort(reverse=True)
	print(sum(sub[::2]))


for _ in range(int(input())):
	s = list(input().split('0'))
	count = 0
	for i in s:
		if i == '':
			s.remove('')
	s = sorted(s)[::-1]
	for i in range(0, len(s), 2):
		count += len(s[i])
	print(count)


t = int(input())
while t:
	s = str(input())
	n = len(s)
	alice = 0
	i = 0
	turn = 1
	ones = []
	while i < n:
		temp = i
		x = str()
		while temp < n:
			if s[temp] == '1':
				x += '1'
				temp += 1
			else:
				break
		if len(x) > 0:
			ones.append(x)
			i = temp
		else:
			i += 1
	m = len(ones)
	ones.sort(reverse=True)
	for i in range(m):
		if i % 2 == 0:
			alice += len(ones[i])
	print(alice)
	t -= 1


for _ in range(int(input())):
	s = input().split('0')
	s.sort(reverse=True)
	(alice, bob) = (0, 0)
	for i in range(len(s)):
		if i % 2 == 0:
			alice = alice + len(s[i])
		else:
			bob = bob + len(s[i])
	print(alice)


def println(lst):
	lst.reverse()
	reply = 0
	for i in range(len(lst)):
		if i % 2 == 0:
			reply += lst[i]
	print(reply)

def funk(s):
	count = 0
	ls = []
	for i in range(len(s)):
		if s[i] == '0':
			if count != 0:
				ls.append(count)
				count = 0
		else:
			count += 1
	if count != 0:
		ls.append(count)
	println(sorted(ls))
num = int(input())
for i in range(num):
	s = str(input())
	funk(s)


from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
	s = input().strip().split('0')
	s.sort(key=lambda x: len(x))
	s = [si for si in s if si]
	ans = 0
	while s:
		ans += len(s[-1])
		s.pop()
		if s:
			s.pop()
	print(ans)


n = int(input())
for i in range(n):
	l = input()
	l = l.replace('0', ' ')
	i_l = l.split()
	i_lc = [len(x) for x in i_l]
	i_lc.sort()
	s = 0
	for i in range(len(i_lc) - 1, -1, -2):
		s += i_lc[i]
	print(s)


for _ in range(int(input())):
	s = input()
	x = sorted((len(i) for i in s.split('0') if len(i) > 0))
	print(max(sum(x[::2]), sum(x[1::2])))


T = int(input())
for _ in range(T):
	S = input()
	ones = []
	seq = 1
	for (a, b) in zip(S, S[1:]):
		if a == b:
			seq += 1
		else:
			if a == '1':
				ones.append(seq)
			seq = 1
	if S[-1] == '1':
		ones.append(seq)
	ones.sort()
	i = ans = 0
	while ones:
		a = ones.pop()
		if i % 2 == 0:
			ans += a
		i += 1
	print(ans)


n = input()
for i in range(int(n)):
	li = str(input())
	lili = []
	a = 0
	ans = 0
	for j in range(len(li)):
		if str(li[j]) == '1':
			a += 1
		elif a > 0 or j == len(li) - 1:
			lili.append(a)
			a = 0
	if a > 0:
		lili.append(a)
	lili.sort()
	lili.reverse()
	for j in range(len(lili)):
		if j % 2 == 0:
			ans += lili[j]
	print(ans)


test = int(input())
for _ in range(test):
	arr = list(input())
	s = -1
	e = -1
	freq = []
	for i in range(len(arr)):
		if arr[i] == '1':
			if s == -1:
				s = i
		else:
			if s > -1:
				freq.append(i - s)
			s = -1
	if s > -1:
		freq.append(len(arr) - s)
	freq.sort(reverse=True)
	t = 0
	for i in range(0, len(freq), 2):
		t += freq[i]
	print(t)


for _ in range(int(input())):
	s = input()
	rep = []
	last = s[0]
	if last == '1':
		cnt = 1
	else:
		cnt = 0
	for i in range(1, len(s)):
		if s[i] == last and s[i] == '1':
			cnt += 1
		else:
			if cnt != 0:
				rep.append(cnt)
			if s[i] == '0':
				cnt = 0
			if s[i] == '1':
				cnt = 1
		last = s[i]
	if cnt != 0:
		rep.append(cnt)
	rep = sorted(rep, reverse=True)
	lis = rep[:]
	al = 0
	b = 0
	for i in range(1, len(lis) + 1):
		if i % 2 == 0:
			b += lis[i - 1]
		else:
			al += lis[i - 1]
	print(al)


from itertools import groupby
for _ in range(int(input())):
	s = input()
	a = []
	for (k, g) in groupby(s):
		if k == '1':
			a.append(len(list(g)))
	a.sort(reverse=True)
	print(sum(a[::2]))


for _ in range(int(input())):
	t = sorted(list(map(str, input().split('0'))), reverse=True)
	s = 0
	for i in range(0, len(t), 2):
		if len(t[i]) == 0:
			break
		s += len(t[i])
	print(s)


t = int(input())
for i in range(t):
	s = input()
	z = s.split('0')
	x = []
	for i in z:
		if i != '':
			x += (i,)
	score = 0
	lens = sorted(x, key=lambda i: len(i), reverse=True)
	for i in lens[0::2]:
		score += len(i)
	print(score)


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
sys.setrecursionlimit(300000)

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class BinaryTrie:

	class Node:

		def __init__(self, bit: bool=False):
			self.bit = bit
			self.children = []
			self.count = 0
			self.counter = 1

	def __init__(self, size):
		self.root = BinaryTrie.Node()
		self.size = size

	def convert(self, key):
		bits = []
		if isinstance(key, int):
			key = bin(key)[2:]
		if isinstance(key, str):
			for i in range(self.size - len(key)):
				bits += [False]
			for i in key:
				if i == '0':
					bits += [False]
				else:
					bits += [True]
		else:
			return list(key)
		return bits

	def add(self, key):
		node = self.root
		bits = self.convert(key)
		for bit in bits:
			found_in_child = False
			for child in node.children:
				if child.bit == bit:
					child.counter += 1
					node = child
					found_in_child = True
					break
			if not found_in_child:
				new_node = BinaryTrie.Node(bit)
				node.children.append(new_node)
				node = new_node
		node.count += 1

	def remove(self, key):
		node = self.root
		bits = self.convert(key)
		nodelist = [node]
		for bit in bits:
			for child in node.children:
				if child.bit == bit:
					node = child
					node.counter -= 1
					nodelist.append(node)
					break
		node.count -= 1
		if not node.children and (not node.count):
			for i in range(len(nodelist) - 2, -1, -1):
				nodelist[i].children.remove(nodelist[i + 1])
				if nodelist[i].children or nodelist[i].count:
					break

	def query(self, prefix, root=None):
		if not root:
			root = self.root
		node = root
		if not root.children:
			return 0
		for bit in prefix:
			bit_not_found = True
			for child in node.children:
				if child.bit == bit:
					bit_not_found = False
					node = child
					break
			if bit_not_found:
				return 0
		return node

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.data = 0
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key, val):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
			pCrawl.data += val
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		c = 0
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None

	def present(self, key):
		ans = 0
		pCrawl = self.root
		length = len(key)
		c = 0
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
			ans += pCrawl.data
		if pCrawl != None:
			return ans
		return -1
for ik in range(int(input())):
	s = input()
	a = []
	c = 0
	for i in range(len(s)):
		if s[i] == '0':
			if c != 0:
				a.append(c)
			c = 0
		else:
			c += 1
	if c != 0:
		a.append(c)
	a.sort(reverse=True)
	ans = 0
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)


import re

def resolve():
	N = int(input())
	for _ in range(N):
		S = input()
		splitted_S = sorted([x.count('1') for x in re.split('0+', S)])
		print(sum(splitted_S[::-2]))
resolve()


def solve(s):
	prev = '0'
	cnt = 0
	l = []
	for c in s:
		if c == '0':
			if cnt != 0:
				l.append(cnt)
			cnt = 0
			continue
		cnt += 1
	if cnt != 0:
		l.append(cnt)
	l.sort(reverse=True)
	res = 0
	for i in range(0, len(l), 2):
		res += l[i]
	return res

def main():
	t = int(input())
	while t > 0:
		s = input()
		print(solve(s))
		t -= 1
main()


a = int(input())
for b in range(a):
	c = input()
	d = [0 for i in range(len(c))]
	e = 0
	f = ''
	for g in c:
		if g == '1':
			d[e] += 1
		else:
			e += 1
	d.sort(reverse=True)
	h = 0
	for i in range(len(d) // 2 + len(d) % 2):
		h += d[i * 2]
	print(h)


def max1(s):
	(ans, temp) = (0, 0)
	for i in range(len(s)):
		if s[i] == '1':
			temp += 1
		else:
			ans = max(ans, temp)
			temp = 0
	ans = max(ans, temp)
	return ans
for _ in range(int(input())):
	n = input()
	alice = 0
	bob = 0
	x = 0
	if '1' not in n:
		print(alice)
		continue
	while '1' in n:
		x += 1
		a = max1(n)
		b = '1' * a
		n = n.replace(b, '', 1)
		if x % 2 != 0:
			alice += a
		else:
			bob += a
	print(alice)


for t in range(int(input())):
	s1 = input()
	count = 0
	l1 = []
	n = len(s1)
	for i in range(n):
		if s1[i] == '0':
			l1.append(count)
			count = 0
		elif s1[i] == '1':
			count += 1
		if i == n - 1 and s1[i] != '0':
			l1.append(count)
	l1.sort(reverse=True)
	l2 = l1[::2]
	print(sum(l2))


for _ in range(int(input())):
	s = input()
	s = s.split('0')
	arr = []
	for i in s:
		if len(i) > 0:
			arr.append(i)
	arr.sort()
	ans = 0
	for i in range(len(arr) - 1, -1, -2):
		ans += len(arr[i])
	print(ans)


for i in range(int(input())):
	s = sorted(input().split('0'), reverse=True)
	output = 0
	j = 0
	while j < len(s):
		output += len(s[j])
		j += 2
	print(output)


t = int(input())
while t > 0:
	inp_str = str(input())
	size = len(inp_str)
	len1 = []
	count = 0
	flag = 0
	for i in range(size):
		if flag == 0:
			if inp_str[i] == '1':
				count = 1
				flag = 1
		elif inp_str[i] == '0':
			flag = 0
			len1.append(count)
			count = 0
		else:
			count += 1
		if i == size - 1 and flag == 1:
			len1.append(count)
	len1.sort()
	a_score = 0
	b_score = 0
	for i in range(len(len1)):
		temp = len(len1) - 1 - i
		if i % 2 == 0:
			a_score += len1[temp]
		else:
			b_score += len1[temp]
	print(a_score)
	t -= 1


for _ in range(int(input())):
	n = input()
	c = 0
	l = []
	d = 0
	for i in n:
		if i == '1' and d == 0:
			d = 1
			l.append(1)
		elif i == '1' and d != 0:
			l[-1] += 1
		else:
			d = 0
	l.sort(reverse=True)
	for i in range(0, len(l), 2):
		c += l[i]
	print(c)


def main():
	T = int(input())
	for _ in range(T):
		s = input()
		l = []
		in_a_row = 0
		for i in s:
			if i == '1':
				in_a_row += 1
			else:
				if in_a_row > 0:
					l.append(in_a_row)
				in_a_row = 0
		if in_a_row > 0:
			l.append(in_a_row)
		l.sort(reverse=True)
		total = 0
		for i in range(len(l)):
			if i % 2 == 0:
				total += l[i]
		print(total)
main()


t = int(input())
for _ in range(t):
	s = input()
	lst = []
	now = 0
	for i in s:
		if i == '1':
			now += 1
		elif now != 0:
			lst.append(now)
			now = 0
	if now != 0:
		lst.append(now)
	lst.sort(reverse=True)
	ans = 0
	for i in range(len(lst)):
		if i % 2 == 0:
			ans += lst[i]
	print(ans)


def solve(s):
	cnt = 0
	sum = 0
	arr = []
	for i in range(len(s)):
		if s[i] == '1':
			cnt += 1
		else:
			if cnt > 0:
				arr.append(cnt)
			cnt = 0
	if cnt > 0:
		arr.append(cnt)
	arr.sort(reverse=True)
	if len(arr) > 0:
		for j in range(len(arr)):
			if j % 2 == 0:
				sum += arr[j]
		print(sum)
	else:
		print(0)
t = int(input())
while t != 0:
	S = str(input())
	solve(S)
	t -= 1


t = int(input())
while t > 0:
	s = list(input())
	uns = []
	cont = 0
	pts = 0
	for i in range(len(s)):
		if s[i] == '1':
			cont += 1
		elif s[i - 1] == '1':
			uns.append(cont)
			cont = 0
	if cont > 0:
		uns.append(cont)
	while uns != []:
		pts += max(uns)
		uns.remove(max(uns))
		if uns == []:
			break
		uns.remove(max(uns))
	print(pts)
	t -= 1


t = int(input())
while t > 0:
	t -= 1
	s = input()
	ans = []
	ln = 0
	if s[0] == '1':
		ln += 1
	for i in range(1, len(s)):
		if s[i] == '0':
			if ln != 0:
				ans.append(ln)
				ln = 0
		else:
			ln += 1
	if ln != 0:
		ans.append(ln)
	ans.sort(reverse=True)
	a = 0
	b = 0
	for i in range(len(ans)):
		if i % 2 == 0:
			a += ans[i]
		else:
			b += ans[i]
	print(a)


def max_ScoreFunc(s):
	size = len(s)
	alice_score = []
	count = 0
	for i in range(len(s)):
		if s[i] == '1':
			count += 1
		elif count:
			alice_score.append(count)
			count = 0
	if count:
		alice_score.append(count)
	answer_reverse_sorted = sorted(alice_score)
	answer_reverse_sorted.reverse()
	ans = sum(answer_reverse_sorted[0::2])
	return ans
t = int(input())
temp_arr = []
for i in range(t):
	s = str(input())
	ans = max_ScoreFunc(s)
	temp_arr.append(ans)
for j in temp_arr:
	print(j)


for t in range(int(input())):
	l = input()
	n = len(l)
	sl = []
	i = 0
	knt = 0
	for i in range(0, len(l)):
		if l[i] == '1':
			knt += 1
			if i == len(l) - 1:
				sl.append(knt)
			else:
				continue
		elif l[i] == '0' and knt != 0:
			sl.append(knt)
			knt = 0
	sl.sort(reverse=True)
	ans = 0
	for i in range(0, len(sl), 2):
		ans += sl[i]
	print(ans)


t = int(input())
from collections import Counter
for _ in range(t):
	(*a,) = input().split('0')
	a.sort(reverse=True)
	al = a[0::2]
	ans = len(''.join(al))
	print(ans)


for _ in range(int(input())):
	s = input()
	now = s[0]
	tim = 0
	ans = 0
	arr = []
	odin = 0
	for i in s:
		if i == now:
			tim += 1
		else:
			if now == '1':
				arr.append(tim)
			now = i
			tim = 1
	if now == '1':
		arr.append(tim)
	arr = sorted(arr)
	arr = arr[::-1]
	for i in range(0, len(arr), 2):
		ans += arr[i]
	print(ans)


import math

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

def btd(n):
	return int(n, 2)
t = int(input())
for k in range(t):
	s = input()
	n = len(s)
	i = 0
	ans = 0
	a = []
	while i < n:
		if s[i] == '0':
			i += 1
		else:
			if s[i] == '1':
				j = i
				count = 0
				while j < n:
					if s[j] == '1':
						count += 1
						j += 1
					else:
						break
				a.append(count)
			i = j
	a.sort(reverse=True)
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)


for _ in range(int(input())):
	S = input() + '0'
	ans = []
	x = 0
	for s in S:
		if s == '1':
			x += 1
		elif x:
			ans += [x]
			x = 0
	ans.sort()
	print(sum(ans[-1::-2]))


T = int(input())
while T != 0:
	N = input()
	x = N.split('0')
	ans = []
	b = len(x)
	while b != 0:
		m = x.pop()
		n = len(m)
		if n != 0:
			ans.append(n)
		b -= 1
	ans.sort(reverse=True)
	a = 0
	for i in range(0, len(ans), 2):
		a += ans[i]
	print(a)
	T -= 1


from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

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

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

def sarr():
	return [int(i) for i in input()]

def inn():
	return int(input())
mo = 1000000007
for _ in range(int(input())):
	s = input()
	n = len(s)
	res = []
	i = 0
	while i < n:
		if s[i] == '0':
			i += 1
		else:
			c = 0
			while i < n and s[i] == '1':
				c += 1
				i += 1
			res += [c]
	res.sort(reverse=True)
	ans = 0
	for i in range(len(res)):
		if i % 2 == 0:
			ans += res[i]
	print(ans)


for j in range(int(input())):
	a = input()
	li = []
	count = 0
	for j in a:
		if j == '0':
			li.append(count)
			count = 0
		else:
			count += 1
	if a[-1] != '0':
		li.append(count)
	li = sorted(li, reverse=True)
	(ali, bob) = (0, 0)
	for j in range(len(li)):
		if li[j] == 0:
			break
		if j % 2 == 0:
			ali += li[j]
		else:
			bob += li[j]
	print(ali)


a = int(input())
for i in range(a):
	b = input()
	c = []
	t = 0
	u = -1
	sum = 0
	for i in range(len(b)):
		if b[i] == '1' and t == 0:
			c.append(1)
			u += 1
			t = 1
		elif b[i] == '1' and t == 1:
			c[u] += 1
		elif b[i] == '0' and t == 1:
			t = 0
	for j in range(0, u + 1, 2):
		if len(c) > 0:
			sum += max(c)
			c.remove(max(c))
			if len(c) > 0:
				c.remove(max(c))
	print(sum)


import sys
from collections import Counter
from math import ceil, gcd, log
from bisect import bisect, bisect_left, bisect_right
input = sys.stdin.readline

def check(a, b, c):
	if a + b <= c or a + c <= b or b + c <= a:
		return False
	else:
		return True

def solve(s):
	if len(s) == 1:
		if s == 1:
			print(1)
		else:
			print(0)
		return
	if '1' not in s:
		print(0)
		return
	temp = ''
	arr = s.split('0')
	ans = []
	for i in arr:
		if len(i) != 0:
			ans.append(i)
	ans[-1] = ans[-1][:len(ans[-1]) - 1]
	f = all((len(i) == 0 for i in ans))
	if f:
		print(0)
		return
	ans = sorted(ans, reverse=True)
	fin = 0
	for i in range(len(ans)):
		if i % 2 == 0:
			fin += len(ans[i])
	print(fin)
	return

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


for _ in range(int(input())):
	s = input()
	l = s.split('0')
	R = []
	for i in l:
		if i != '':
			R.append(len(i))
	R = sorted(R, reverse=True)
	result = 0
	for i in range(len(R)):
		if i % 2 == 0:
			result += R[i]
	print(result)


tst = int(input())
while tst > 0:
	str = input()
	ls = list()
	cnt = 0
	for i in range(len(str)):
		if str[i] == '1':
			cnt += 1
			if i == len(str) - 1:
				ls.append(cnt)
		else:
			ls.append(cnt)
			cnt = 0
	ls = sorted(ls, reverse=True)
	i = 0
	ans = 0
	while i < len(ls):
		ans += ls[i]
		i += 2
	print(ans)
	tst -= 1


t = int(input())
for _ in range(t):
	s = str(input())
	k = s.split('0')
	sum = 0
	l = []
	for i in k:
		l.append(len(i))
	l.sort(reverse=True)
	for i in range(0, len(l), 2):
		sum += l[i]
	print(sum)


for i in range(int(input())):
	a = input().split('0')
	a.sort(reverse=True)
	j = 0
	s = 0
	while j < len(a):
		if j % 2 == 0:
			s += len(a[j])
		j += 1
	print(s)


q = int(input())
for _ in range(q):
	s = input()
	jed = []
	n = len(s)
	count = 0
	for i in range(n):
		if s[i] == '1':
			count += 1
		else:
			if count > 0:
				jed.append(count)
			count = 0
	if count > 0:
		jed.append(count)
	jed.sort()
	jed.reverse()
	wyn = 0
	i = 0
	if len(jed) == 0:
		print(0)
	else:
		while i < len(jed):
			wyn += jed[i]
			i += 2
		print(wyn)


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7
T = int(stdin.readline())
for _ in range(T):
	s = stdin.readline().strip('\n')
	c = 0
	fin = [0]
	n = len(s)
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			continue
		else:
			fin.append(i + 1)
	fin.append(n)
	if s[0] == '0':
		st = 1
	else:
		st = 0
	ans = []
	for i in range(len(fin) - 1):
		ans.append(fin[i + 1] - fin[i])
	g = []
	for i in range(st, len(ans), 2):
		g.append(ans[i])
	res = 0
	g.sort(reverse=True)
	for i in range(0, len(g), 2):
		res += g[i]
	print(res)


from sys import stdin, stdout
from math import gcd, sqrt, factorial
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 0 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for i in range(I()):
	s = S() + '0'
	cnt = 0
	a = []
	for i in s:
		if i == '1':
			cnt += 1
		elif cnt:
			a += (cnt,)
			cnt = 0
	a.sort(reverse=True)
	sm = 0
	for i in range(len(a)):
		if i + 1 & 1:
			sm += a[i]
	print(sm)


for _ in range(int(input())):
	(a, w) = ([], 0)
	for i in input():
		if i == '0':
			a.append(w)
			w = 0
		else:
			w += 1
	if w:
		a.append(w)
	a.sort(reverse=True)
	w = 0
	for i in range(0, len(a), 2):
		w += a[i]
	print(w)


MOD = 1000000007
from collections import defaultdict as dd, Counter, deque

def si():
	return input()

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

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

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

def out(v):
	print(v)

def spout():
	print(v, end=' ')

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

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

def vow():
	return ['a', 'e', 'i', 'o', 'u']

def let():
	return [chr(i) for i in range(97, 123)]

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

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

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)
t = ii()
while t:
	t -= 1
	s = si().split('0')
	c = 0
	s.sort(key=lambda x: len(x), reverse=True)
	for i in range(0, len(s), 2):
		c += len(s[i])
	print(c)


for _ in range(int(input())):
	a = input()
	b = []
	s = 0
	for i in a:
		if i == '1':
			s += 1
		elif s != 0:
			b.append(s)
			s = 0
	b.append(s)
	s = 0
	b.sort(reverse=True)
	for i in range(len(b)):
		if i % 2 == 0:
			s += b[i]
	print(s)


t = int(input())
for i in range(0, t):
	s = input()
	l = []
	x = 0
	for j in range(0, len(s)):
		if s[j] == '1':
			x = x + 1
		else:
			l.append(x)
			x = 0
	l.append(x)
	l.sort()
	ln = len(l)
	s = 0
	for k in range(0, ln, 2):
		s = s + l[ln - 1 - k]
	print(s)


for _ in range(int(input())):
	s = input()
	a = [int(s[0])]
	n = len(s)
	i = 1
	while i < n:
		if s[i] != s[i - 1]:
			a += (int(s[i]),)
		else:
			a[-1] += int(s[i])
		i += 1
	a = [x for x in a if x]
	a.sort(reverse=True)
	print(sum(a[::2]))


t = int(input())
for i in range(t):
	s = list(input().split('0'))
	l = []
	for x in s:
		l.append(len(x))
	l.sort()
	n = len(l)
	alice = 0
	for a in range(n - 1, -1, -1):
		if n % 2 == 0:
			if a % 2 == 1:
				alice += l[a]
		elif a % 2 == 0:
			alice += l[a]
	print(alice)


for _ in range(int(input())):
	S = input()
	Alice = 1
	Score = 0
	while S.count('1') != 0:
		N = len(S)
		start = False
		time = 0
		Index = -1
		Max = 0
		for i in range(N):
			if S[i] == '1':
				if start:
					time += 1
				else:
					time += 1
					start = True
			elif start:
				start = False
				if time > Max:
					Index = i - time
					Max = time
				time = 0
			else:
				continue
		if time > Max:
			Index = N - time
			Max = time
		if Alice:
			Score += Max
		S = S[:Index] + S[Index + Max + 1:]
		Alice = 1 - Alice
	print(Score)


t = int(input())
i = 1
while i <= t:
	s = input()
	l1 = []
	count = 0
	l = 0
	while l < len(s):
		if s[l] == '1':
			count += 1
		if s[l] == '0' or l == len(s) - 1:
			l1.append(count)
			count = 0
		l += 1
	l1.sort()
	sum1 = 0
	l = len(l1) - 1
	while l >= 0:
		sum1 += l1[l]
		l -= 2
	print(sum1)
	i += 1


t = input()
t = int(t)
while t > 0:
	s = input()
	count = 0
	lst = []
	for c in s:
		if c == '1':
			count += 1
		else:
			if count > 0:
				lst.append(count)
			count = 0
	if count > 0:
		lst.append(count)
	lst = sorted(lst)
	lst = lst[::-1]
	ans = 0
	for i in range(len(lst)):
		if i % 2 == 0:
			ans += lst[i]
	print(ans)
	t -= 1


for _ in range(int(input())):
	a = list(input().replace('0', ' ').split())
	i = 1
	s = 0
	while len(a) != 0:
		if i % 2 != 0:
			x = a.index(max(a))
			y = a.pop(x)
			z = len(y)
			s += len(y)
		else:
			a.pop(a.index(max(a)))
		i += 1
	print(s)


import bisect

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

def list_input():
	return list(map(int, input().split()))
for _ in range(int(input())):
	s = input()
	d = []
	i = 0
	while i < len(s):
		if s[i] == '1':
			count = 1
			i += 1
			while i < len(s) and s[i] == '1':
				count += 1
				i += 1
			d.append(count)
		else:
			i += 1
	d.sort(reverse=True)
	ans = 0
	for i in range(0, len(d), 2):
		ans += d[i]
	print(ans)


from itertools import groupby
t = int(input())
for i in range(t):
	lst = []
	s = input()
	for i in s:
		lst.append(int(i))
	res = [list(y) for (x, y) in groupby(lst)]
	l = []
	for j in res:
		if j[0] == 1:
			l.append(len(j))
	l.sort(reverse=True)
	a = 0
	for k in range(len(l)):
		if k % 2 == 0:
			a += l[k]
	print(a)


import re
import operator
from functools import reduce
t = int(input())
for _ in range(t):
	s = input()
	l = re.findall('(1+)', s)
	l = sorted(l, reverse=True)
	print(len(reduce(operator.add, l[::2], '')))


n = int(input())
final = []
result = []
for i in range(n):
	s = input()
	msum = 0
	count = 0
	final = []
	for i in s:
		if int(i) == 1:
			count += 1
		elif int(i) == 0:
			final.append(count)
			count = 0
	final.append(count)
	final.sort(reverse=True)
	for i in range(0, len(final), 2):
		msum += final[i]
	result.append(msum)
for i in result:
	print(i)


t = int(input())
while t:
	s = input()
	l = []
	(j, cnt) = (0, 0)
	n = s.count('1')
	if s.count('0') == len(s):
		print('0')
	else:
		while s[0] != '1':
			s = s.replace('0', '', 1)
		while sum(l) != n:
			for i in range(j, len(s)):
				if s[i] == '1':
					cnt += 1
				else:
					break
			l.append(cnt)
			cnt = 0
			j = i + 1
		l.sort(reverse=True)
		ans = [l[i] for i in range(len(l)) if i % 2 == 0]
		print(sum(ans))
	t -= 1


for _ in range(int(input())):
	s = input()
	l = []
	f = 0
	c = 0
	for i in s:
		if f == 0 and i == '1':
			f = 1
			c += 1
		elif f == 0 and i == '0':
			(f, c) = (0, 0)
		elif f == 1 and i == '1':
			c += 1
		elif f == 1 and i == '0':
			l.append(c)
			(c, f) = (0, 0)
	if c > 0:
		l.append(c)
	l.sort(reverse=True)
	s = 0
	for i in l[::2]:
		s += i
	print(s)


def solve(s):
	lengths = []
	last = '0'
	n = 0
	for c in s + '0':
		if c == '0':
			if last == '1':
				lengths.append(n)
				n = 0
			last = '0'
		elif c == '1':
			last = '1'
			n += 1
	return sum(sorted(lengths, reverse=True)[::2])
for _ in range(int(input())):
	s = input().rstrip()
	print(solve(s))


testes = int(input())

def eh_par(numero):
	if numero % 2 == 0:
		retorno = True
	else:
		retorno = False
	return retorno
for i in range(testes):
	string_binaria = input()
	array_de_um = string_binaria.split('0')
	alice = 0
	bob = 0
	for i in range(len(array_de_um)):
		if eh_par(i):
			alice += len(max(array_de_um))
			array_de_um.remove(max(array_de_um))
		else:
			bob += len(max(array_de_um))
			array_de_um.remove(max(array_de_um))
	print(alice)


def get_one_counter_list(arrayList):
	one_counter_list = []
	one_counter = 0
	for item in range(len(arrayList)):
		if arrayList[item] == '1':
			one_counter += 1
		else:
			if one_counter > 0:
				one_counter_list.append(one_counter)
			one_counter = 0
	if one_counter > 0:
		one_counter_list.append(one_counter)
	one_counter_list.sort(reverse=True)
	max_one_alice(one_counter_list)

def max_one_alice(lists):
	max_one = 0
	for item in range(len(lists)):
		if item % 2 == 0:
			max_one += lists[item]
	print(max_one)
t = int(input())
for i in range(0, t):
	input_str = input()
	get_one_counter_list(input_str)


from itertools import groupby
from itertools import combinations
from itertools import permutations
from collections import Counter

def valid(n):
	array = [int(d) for d in str(n)]
	out = 0
	List = [list(y) for (x, y) in groupby(array)]
	a = 1
	while len(List) >= 1:
		l = {'value': 0, 'index': 0}
		for (idx, x) in enumerate(List):
			if x[0] == 1:
				if l['value'] < len(x):
					l['value'] = len(x)
					l['index'] = idx
		List.pop(l['index'])
		List = [j for i in List for j in i]
		List = [list(y) for (x, y) in groupby(List)]
		if a == 1:
			a = 0
			out += l['value']
		else:
			a = 1
	print(out)
t = int(input())
for i in range(t):
	n = int(input())
	valid(n)


for _ in range(int(input())):
	cur = 0
	temp = []
	for v in input():
		if v == '1':
			cur += 1
		elif cur:
			temp.append(cur)
			cur = 0
	if cur:
		temp.append(cur)
	temp.sort(reverse=True)
	print(sum(temp[::2]))


for i in range(int(input())):
	s = input()
	l = []
	flag = 0
	i = 0
	while i < len(s):
		ct = 0
		while i < len(s) and s[i] == '1':
			ct += 1
			i += 1
		if ct > 0:
			l.append(ct)
		i += 1
	l = sorted(l)[::-1]
	ans = 0
	for i in range(len(l)):
		if i % 2 == 0:
			ans += l[i]
	print(ans)


for _ in range(int(input())):
	s = input()
	l = s.split('0')
	k = []
	for i in l:
		if i != '':
			k.append(len(i))
	k = sorted(k)[::-1]
	ans = sum(k[::2])
	print(ans)


n = int(input().strip())
printing = []
for test in range(n):
	m = input()
	score = 0
	turn = 0
	while '1' in m:
		lengths = []
		starts = []
		a = m[0]
		count = 1
		length = 1
		while count < len(m):
			if m[count] == a:
				length += 1
			else:
				if a == '1':
					starts.append(count)
					lengths.append(length)
				a = m[count]
				length = 1
			count += 1
		if a == '1':
			starts.append(count)
			lengths.append(length)
		count = starts[lengths.index(max(lengths))]
		m = m[:count - max(lengths)] + m[count:]
		turn += 1
		if turn % 2 == 1:
			score += max(lengths)
	printing.append(score)
for item in printing:
	print(item)


T = int(input())
for i in range(T):
	print(len(''.join(sorted(list(filter(lambda x: x, input().split('0'))))[::-2])))


import re

def solve(n):
	l = sorted(re.findall('[1]+', n))[::-1]
	count = 0
	for i in range(0, len(l), 2):
		count += len(l[i])
	return count
for _ in range(int(input())):
	n = input()
	print(solve(n))


for i in range(int(input())):
	s = input()
	l = []
	counter = 0
	for c in s:
		if c == '0':
			if counter > 0:
				l.append(counter)
				counter = 0
		if c == '1':
			counter += 1
	l.append(counter)
	l = sorted(l, reverse=True)
	print(sum([l[i] for i in range(len(l)) if not i % 2]))


for _ in range(int(input())):
	s = sorted(input().split('0'), key=len, reverse=True)
	print(sum(map(len, s[::2])))


t = int(input())
for _ in range(t):
	s = input()
	alice = 0
	turn = 0
	for x in range(len(s), 0, -1):
		substrings = s.count('1' * x)
		for i in range(substrings):
			turn ^= 1
			if turn == 1:
				alice += x
		s = s.replace('1' * x, '')
	print(alice)


from math import ceil
for _ in range(int(input())):
	li = input()
	temp = 0
	freq = []
	i = 0
	while i < len(li):
		temp = 0
		test = 0
		while i < len(li) and li[i] == '1':
			temp += 1
			i += 1
			test = 1
		if test == 0:
			i += 1
		if temp > 0:
			freq.append(temp)
	freq.sort(reverse=True)
	ans = 0
	for i in range(0, len(freq), 2):
		ans += freq[i]
	print(ans)


a = int(input())
for h in range(a):
	d = input()
	ff = 0
	k = []
	for l in range(len(d)):
		if d[l] == '1':
			ff += 1
		else:
			k.append(ff)
			ff = 0
	k.append(ff)
	k.sort(reverse=True)
	print(sum(k[0::2]))


from collections import deque
for i in range(int(input())):
	s = str(input())
	stk = deque()
	l = []
	for i in range(len(s)):
		stk.append(s[i])
		co = 0
		if stk[-1] == '0':
			stk.pop()
			while len(stk) != 0:
				stk.pop()
				co += 1
			l.append(co)
		elif i == len(s) - 1 and s[i] == '1':
			while len(stk) != 0:
				stk.pop()
				co += 1
			l.append(co)
		else:
			continue
	l.sort(reverse=True)
	an = 0
	for i in range(len(l)):
		if i % 2 == 0:
			an += l[i]
	print(an)


def main():
	for _ in range(int(input())):
		a = list(input())
		l1 = []
		k = 1
		for i in range(len(a) - 1):
			if a[i] == a[i + 1]:
				k += 1
			else:
				l1.append([a[i], k])
				k = 1
		l1.append([a[-1], k])
		l1.sort(key=lambda x: (-ord(x[0]), -x[1]))
		l1 = list(filter(lambda x: x[0] == '1', l1))
		k = 0
		for i in range(0, len(l1), 2):
			k += l1[i][1]
		print(k)
main()


repetitions = int(input())
while repetitions > 0:
	auxList = []
	count = 0
	sequence = list(map(int, input()))
	for i in range(len(sequence)):
		if sequence[i] == 1:
			count += 1
		elif sequence[i] == 0 and count > 0:
			auxList.append(count)
			count = 0
	if count > 0:
		auxList.append(count)
	scoreSum = 0
	loops = len(auxList)
	auxList.sort(reverse=True)
	aliceTurn = True
	while len(auxList) > 0:
		if aliceTurn:
			scoreSum += auxList.pop(0)
			aliceTurn = False
		else:
			auxList.pop(0)
			aliceTurn = True
	repetitions -= 1
	print(scoreSum)


for _ in range(int(input())):
	s = input().split('0')
	s = [substr for substr in s if len(substr) != 0]
	s.sort(reverse=True)
	Alice = 0
	for ind in range(0, len(s), 2):
		Alice += len(s[ind])
	print(Alice)


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

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

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

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

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

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

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

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

def make(s):
	l = [[s[0], 1]]
	for i in range(1, len(s)):
		if s[i] == l[-1][0]:
			l[-1][1] += 1
		else:
			l.append([s[i], 1])
	l1 = []
	for i in l:
		if i[0] != '0':
			l1.append(i[1])
	return sorted(l1, reverse=1)
for _ in range(val()):
	l = make(st())
	ans = 0
	for i in range(0, len(l), 2):
		ans += l[i]
	print(ans)


def res(string):
	lst = list()
	char = string[0]
	char_collection = char
	for i in range(1, len(string)):
		if char == string[i]:
			char_collection += string[i]
		else:
			if '0' not in char_collection:
				lst.append(char_collection)
			char = string[i]
			char_collection = string[i]
	if '0' not in char_collection:
		lst.append(char_collection)
	lst.sort(key=lambda x: len(x))
	sum = 0
	for i in range(len(lst) - 1, -1, -2):
		sum += len(lst[i])
	print(sum)
t = int(input())
str_list = list()
for i in range(t):
	str_list.append(input())
for i in str_list:
	res(i)


import sys
from os import path
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	s = input()
	a = []
	count = 0
	for i in s:
		if i == '1':
			count += 1
		else:
			a.append(count)
			count = 0
	a.append(count)
	ans = 0
	for i in list(reversed(sorted(a)))[::2]:
		ans += i
	print(ans)

def main():
	tc = int(input().strip())
	for case in range(tc):
		solve()
main()


import re
t = int(input())
for _ in range(t):
	s = input()
	one_groups = re.split('0+', s)
	one_groups.sort(reverse=True)
	alice_points = 0
	for i in range(0, len(one_groups), 2):
		alice_points += len(one_groups[i])
	print(alice_points)


T = int(input())
for t in range(T):
	s = input()
	blocks = s.split('0')
	size = [len(block) for block in blocks]
	ans = 0
	for (i, x) in enumerate(sorted(size, reverse=True)):
		if i % 2 == 0:
			ans += x
	print(ans)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin, stdout
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math
import math
import time
from queue import Queue

def seive(n):
	l = [True]
	l = l * (n + 1)
	for i in range(2, int(sqrt(n)) + 1):
		if l[i] == True:
			val = i * i
			while val < len(l):
				l[val] = False
				val += i
	prime = []
	for i in range(2, len(l)):
		if l[i] == True:
			prime.append(i)
	return prime

def dp(l, i, n, val, ans):
	if i >= n or val < 0:
		return 1000000
	elif val == 0:
		return 0
	else:
		if ans[i] == 1000000:
			ans[i] = min(min(1 + dp(l, i + 1, n, val - l[i], ans), 1 + dp(l, i, n, val - l[i], ans)), dp(l, i + 1, n, val, ans))
		return ans[i]
from queue import Queue

def factors(n):
	l = []
	for i in range(1, int(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 check1(s, v, x):
	while True:
		if v not in s:
			return v
		else:
			v -= 1

def check2(s, v, x):
	while True:
		if v not in s:
			return v
		else:
			v += 1

def up(n):
	j = n - 1
	while j > 0:
		if n % j == 0:
			break
		j -= 1
	return j

def fac(n):
	c = 1
	i = 1
	while i <= n:
		c *= i
		i += 1
	return c

def check_happy(n):
	ss = set()
	print(n)
	while n != 1:
		val = n
		s = 0
		print(val)
		while val != 0:
			s += (val % 10) ** 2
			val = val // 10
		print(val)
		print('hi')
		if val in ss:
			return False
		else:
			n = val
			ss.add(n)
	return True

def update(a, b):
	c = 1
	val = a
	while a < b:
		print(c, a)
		c += c
		a += a
	print(1)
	while a > b:
		print()
		a -= val
		c -= 1
	return c
import random as rand

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
from itertools import permutations

def insertion_sort(arr):
	for i in range(len(arr)):
		j = i
		while j > 0:
			if arr[j] < arr[j - 1]:
				temp = arr[j]
				arr[j] = arr[j - 1]
				arr[j - 1] = temp
			j -= 1
	return arr

def quick_sort(arr, low, high):
	i = low
	j = high
	while i < j:
		if arr[i] > arr[low] and arr[j] < arr[low]:
			temp = arr[i]
			arr[i] = arr[j]
			arr[j] = arr[i]
			i += 1
			j -= 1
		elif arr[i] <= arr[low]:
			i += 1
		elif arr[j] >= arr[low]:
			j -= 1
	print(i, j)
	toto = arr[j]
	arr[j] = arr[low]
	arr[low] = toto
	return j

def dodo(arr, low, high):
	if low < high:
		val = quick_sort(arr, low, high)
		dodo(arr, low, val - 1)
		dodo(arr, val + 1, high)

def dp(arr, c, n, k, z, ans):
	if k == 0:
		return ans
	elif c == 0:
		return dp(arr, c + 1, n, k - 1, z, ans + arr[c + 1])
	elif c == n - 1:
		if z == 0:
			return 0
		else:
			return dp(arr, c - 1, n, k - 1, z - 1, ans + arr[c - 1])
	elif z == 0:
		return dp(arr, c + 1, n, k - 1, z, ans + arr[c + 1])
	else:
		return max(dp(arr, c + 1, n, k - 1, z, ans + arr[c + 1]), dp(arr, c - 1, n, k - 1, z - 1, ans + arr[c - 1]))

def check(arr, val):
	a = -1
	for i in range(len(arr)):
		if arr[i][len(arr[i]) - 1] == val:
			a = i
			break
	return a

def reverse(s, i, ans):
	if i >= len(s):
		return ans
	else:
		return reverse(s, i + 1, s[i] + ans)

def update(arr, i, j, n, m):
	if i >= 0 and i < n and (j >= 0) and (j < m):
		if arr[i][j] == 1:
			arr[i][j] == 2
			return [i, j]
	return [-1, -1]
t = int(stdin.readline())
for i in range(t):
	s = str(stdin.readline())
	l = []
	val = 0
	for j in s:
		if j == '1':
			val += 1
		else:
			if val != 0:
				l.append(val)
			val = 0
	l.sort(reverse=True)
	ans = 0
	j = 0
	while j < len(l):
		ans += l[j]
		j += 2
	print(ans)


for t in range(int(input())):
	s = input()
	n = len(s)
	ol = list()
	ans = 0
	c = False
	temp = 0
	for i in range(n):
		if s[i] == '1':
			c = True
			temp += 1
		if s[i] == '0':
			if c:
				ol.append(temp)
			temp = 0
			c = False
	ol.append(temp)
	ol.sort(reverse=True)
	for i in range(len(ol)):
		if not i % 2:
			ans += ol[i]
	print(ans)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
sys.setrecursionlimit(10 ** 6)
I = sys.stdin.readline

def ii():
	return int(I().strip())

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

def mi():
	return map(int, I().strip().split())

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

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

def main():
	ans = ''
	for _ in range(ii()):
		s = I().strip()
		arr = []
		if '1' not in s:
			ans += '0\n'
		elif '0' not in s:
			ans += str(len(s)) + '\n'
		else:
			i = 0
			while i < len(s):
				while i < len(s) and s[i] != '1':
					i += 1
				j = i
				while j < len(s) and s[j] == '1':
					j += 1
				arr.append(j - i)
				i = j
			arr.sort(reverse=True)
			a = 0
			f = 1
			for i in range(len(arr)):
				if i % 2 == 0:
					a += arr[i]
			ans += str(a) + '\n'
	print(ans)
main()


t = int(input())
for i in range(t):
	s = input().strip()
	o = []
	c = 0
	for j in range(len(s)):
		if s[j] == '1':
			c = c + 1
		elif c > 0:
			o.append(c)
			c = 0
	if c > 0:
		o.append(c)
	c = 0
	o.sort(reverse=True)
	for j in range(0, len(o), 2):
		c = c + o[j]
	print(c)


for t in range(int(input())):
	s = str(input())
	occur = []
	count = 0
	for i in range(len(s)):
		if s[i] == '1':
			count += 1
			if i == len(s) - 1:
				occur.append(count)
		else:
			occur.append(count)
			count = 0
	try:
		while True:
			occur.remove(0)
	except ValueError:
		pass
	occur = sorted(occur, reverse=True)
	ans = 0
	if len(occur) % 2:
		for i in range(len(occur) // 2 + 1):
			ans += occur[2 * i]
	else:
		for i in range(len(occur) // 2):
			ans += occur[2 * i]
	print(ans)


T = int(input())
for t in range(T):
	s = sorted(input().split('0'), reverse=True)
	ans = 0
	for i in range(0, len(s), 2):
		ans += len(s[i])
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = input().rstrip() + '$'
	left = -1
	ones = []
	for (i, (ch1, ch2)) in enumerate(zip(s, s[1:])):
		if ch1 != ch2:
			if ch1 == '0':
				left = i
			else:
				ones.append(i - left)
	ones.sort(reverse=True)
	ans = sum(ones[::2])
	print(ans)


for t in range(int(input())):
	n = input()
	one = 0
	oneli = []
	for i in n:
		if i == '1':
			one += 1
		elif one > 0:
			oneli.append(one)
			one = 0
	if one > 0:
		oneli.append(one)
	oneli.sort(reverse=True)
	ans = 0
	for ele in oneli[0:len(oneli):2]:
		ans += ele
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	count = 0
	l = []
	for i in s:
		if i == '1':
			count += 1
		else:
			if count:
				l.append(count)
			count = 0
	else:
		if count:
			l.append(count)
	l = sorted(l)
	l = l[::-2]
	print(sum(l))


k = int(input())

def uns(lista):
	aux = []
	parte = ''
	for i in range(len(lista)):
		if lista[i] != '0':
			parte += lista[i]
		elif parte != '':
			aux.append(parte)
			parte = ''
	if parte != '':
		aux.append(parte)
	aux.sort(reverse=True)
	return aux
for i in range(k):
	seq = input()
	pontos = 0
	aux = uns(list(seq))
	if len(aux) == 0:
		print(0)
		continue
	controle = True
	while controle:
		if aux[0] in seq:
			pontos += len(aux.pop(0))
		if len(aux) >= 1:
			aux.pop(0)
		if len(aux) == 0:
			controle = False
	print(pontos)


import sys

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

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	s = minp().split('0')
	s.sort(key=lambda x: len(x), reverse=True)
	print(sum(map(len, s[::2])))
for i in range(mint()):
	solve()


for _ in range(int(input())):
	s = input()
	a = []
	result = count = 0
	for i in range(len(s)):
		if s[i] == '1':
			count += 1
		elif s[i] == '0':
			a.append(count)
			count = 0
		if i == len(s) - 1 and s[i] == '1':
			a.append(count)
	a = sorted(a)
	b = len(a)
	while b > 0:
		result += a[b - 1]
		b -= 2
	print(result)


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())
for case in range(1, itg() + 1):
	s = inp()
	stack = []
	k = 0
	for c in s:
		if c == '1':
			k += 1
		elif k:
			stack.append(k)
			k = 0
	if k:
		stack.append(k)
	stack.sort()
	ans = 0
	while stack:
		ans += stack.pop()
		if stack:
			stack.pop()
	print(ans)


t = int(input())

def get_max_sim(x):
	g = [0] * 2
	for i in x:
		if i == '1':
			g[0] += 1
		else:
			g[1] = max(g)
			g[0] = 0
	return max(g)
for i in range(t):
	s = input()
	a = 0
	while s.count('1'):
		l = get_max_sim(s)
		a += l
		s = s.replace('1' * l, '', 1)
		l = get_max_sim(s)
		s = s.replace('1' * l, '', 1)
	print(a)


def f():
	a = input() + '0'
	arr = []
	l = 0
	for i in range(len(a)):
		if a[i] == '1':
			l += 1
		else:
			if l != 0:
				arr += [l]
			l = 0
	arr.sort()
	arr.reverse()
	res = 0
	for i in range(0, len(arr), 2):
		res += arr[i]
	print(res)
for i in range(int(input())):
	f()


import math
for _ in range(int(input())):
	arr = list(input())
	cont = False
	seq = []
	val = 0
	ans = 0
	for i in range(len(arr)):
		if arr[i] == '1':
			val += 1
			cont = True
		else:
			if cont:
				seq.append(val)
				cont = False
			val = 0
	if cont:
		seq.append(val)
	seq = sorted(seq, reverse=True)
	for i in range(len(seq)):
		if i % 2 == 0:
			ans += seq[i]
	print(ans)


cases = int(input())
for _ in range(cases):
	n = input()
	if '1' not in n:
		print(0)
		continue
	else:
		n = n.split('0')
	tot = 0
	l = sorted(n)[::-1]
	for i in range(0, len(l), 2):
		tot += len(l[i])
	print(tot)


from itertools import groupby
for _ in range(int(input())):
	s = input()
	d = {'1': [], '0': []}
	for (num, group) in groupby(s):
		d[num].append(len(list(group)))
	l = sorted(d['1'], reverse=True)
	total = 0
	for i in range(len(l)):
		if i % 2 == 0:
			total += l[i]
	print(total)


t = int(input())
while t:
	t = t - 1
	str = input()
	l1 = str.split('0')
	l1.sort(reverse=True)
	sum = 0
	for i in range(0, len(l1)):
		if i % 2 == 0:
			sum = sum + len(l1[i])
	print(sum)


t = int(input())
for i in range(t):
	s = [len(e) for e in input().split('0')]
	s.sort(reverse=True)
	c = 0
	for i in range(0, len(s), 2):
		c += s[i]
	print(c)


t = int(input())
for i in range(t):
	s = input()
	l = []
	cnt = 0
	for j in range(len(s)):
		if s[j] == '1':
			cnt += 1
		elif cnt > 0:
			l.append(cnt)
			cnt = 0
	if cnt > 0:
		l.append(cnt)
	l.sort()
	v = len(l)
	score = 0
	for j in range(v - 1, -1, -2):
		score += l[j]
	print(score)


for _ in range(int(input())):
	string = input()
	str_arr = []
	new = ''
	for i in string:
		if i == '1':
			new += i
		elif new != '':
			str_arr.append(new)
			new = ''
	if new != '':
		str_arr.append(new)
	str_arr = sorted(str_arr, reverse=True)
	count = 0
	for i in range(0, len(str_arr), 2):
		count += len(str_arr[i])
	print(count)


n = int(input())
for _ in range(n):
	string = list(filter(lambda x: x != '', input().split('0')))
	aux = True
	alice = ''
	while len(string) > 0:
		maior = max(string)
		if aux:
			alice += maior
		aux = not aux
		string.remove(maior)
	print(len(alice))


t = int(input())

def fun1(a):
	if '0' in set(a):
		return True
	else:
		return False

def fun2(a):
	if '1' in set(a):
		return True
	return False
for _ in range(t):
	a = input()
	if fun1(a) and (not fun2(a)):
		print(0)
	elif fun2(a) and (not fun1(a)):
		print(len(a))
	else:
		i = 0
		al = 0
		bo = 0
		while fun1(a) and fun2(a):
			if not i % 2:
				tmp = a.split('0')
				a = a.replace(max(tmp), '', 1)
				al += len(max(tmp))
				i += 1
			else:
				tmp = a.split('0')
				a = a.replace(max(tmp), '', 1)
				bo += len(max(tmp))
				i += 1
		print(al)


t = int(input())
for q in range(t):
	ch = input()
	L = [len(i) for i in ch.split('0')]
	L.sort(reverse=True)
	somme = 0
	for i in range(len(L)):
		if i % 2 == 0:
			somme += L[i]
	print(somme)


t = int(input())
for _ in range(t):
	s = list(input())
	n = len(s)
	l = []
	k = 0
	f = 0
	for i in range(n):
		if s[i] == '1':
			k = k + 1
			if i == n - 1:
				l.append(k)
		else:
			l.append(k)
			f = 1
			k = 0
	if len(l) == 0:
		print(0)
	else:
		l.sort(reverse=True)
		ans = 0
		for i in range(0, len(l), 2):
			ans = ans + l[i]
		print(ans)


t = int(input())
for i in range(t):
	n = input() + '0'
	ones = []
	num = 0
	keep = False
	for char in n:
		if char == '1':
			num += 1
			keep = True
		if char == '0' and keep:
			ones.append(num)
			num = 0
			keep = False
	ones.sort(reverse=True)
	print(sum(ones[::2]))


from collections import *
from math import *
for _ in range(int(input())):
	s = input()
	cnt = 0
	l = []
	for i in range(len(s)):
		if s[i] == '1':
			cnt += 1
		if s[i] == '0':
			if cnt:
				l.append(cnt)
			cnt = 0
	if cnt:
		l.append(cnt)
	l.sort()
	l.reverse()
	print(sum(l[::2]))


t = int(input())
for _ in range(t):
	s = input()
	if s[0] == '1':
		flag = 1
		count = 1
	else:
		flag = 0
		count = 0
	data = []
	for i in range(1, len(s)):
		if flag == 1:
			if s[i] == '1':
				count += 1
			else:
				data.append(count)
				count = 0
				flag = 0
		elif s[i] == '1':
			count = 1
			flag = 1
	if count > 0:
		data.append(count)
	ans = 0
	data = sorted(data, reverse=True)
	for i in range(len(data)):
		if i % 2 == 0:
			ans += data[i]
	print(ans)


for _ in range(int(input())):
	a = input()
	p = []
	t = 0
	for i in range(len(a)):
		if a[i] == '1' and i != len(a) - 1:
			t += 1
		elif a[i] == '1' and i == len(a) - 1:
			p.append(t + 1)
		elif t == 0:
			pass
		else:
			p.append(t)
			t = 0
	if len(p) == 0:
		print(0)
	else:
		s = 0
		p.sort(reverse=True)
		for i in range(0, len(p), 2):
			s += p[i]
		print(s)


t = int(input())
for i in range(t):
	s = input()
	count = 0
	alice = 0
	l = []
	for i in range(len(s)):
		if s[i] == '1':
			count += 1
			if i == len(s) - 1:
				l.append(count)
		else:
			l.append(count)
			count = 0
	l.sort(reverse=True)
	for i in range(0, len(l), 2):
		alice = alice + l[i]
	print(alice)


t = int(input())
for i in range(t):
	seq_1 = []
	a = input()
	contador = 0
	for numero in a:
		if numero == '1':
			contador += 1
		else:
			if contador > 0:
				seq_1.append(contador)
			contador = 0
	if contador > 0:
		seq_1.append(contador)
	resposta = 0
	seq_1.sort()
	for i in range(len(seq_1) - 1, -1, -2):
		resposta += seq_1[i]
	print(resposta)


for u in range(int(input())):
	s = input()
	c = 0
	l = []
	n = len(s)
	for i in range(n):
		if s[i] == '1':
			c = c + 1
		else:
			if c > 0:
				l.append(c)
			c = 0
	if c > 0:
		l.append(c)
	l.sort(reverse=True)
	(x, y) = (0, 0)
	for i in range(len(l)):
		if i % 2 == 0:
			x = x + l[i]
	print(x)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	s = input()[:-1]
	a = []
	c = 0
	for i in s:
		if i == '1':
			c += 1
		elif c:
			a.append(c)
			c = 0
	if c:
		a.append(c)
	a.sort(reverse=True)
	print(sum(a[::2]))


t = int(input())
for j in range(t):
	s = input()
	L = []
	c = 0
	for i in s:
		if i == '0':
			if c > 0:
				L.append(c)
				c = 0
		else:
			c = c + 1
	if c > 0:
		L.append(c)
	a = len(L)
	L = sorted(L)
	L.reverse()
	C = []
	for i in range(a):
		k = L[i]
		if i % 2 == 0:
			C.append(k)
	print(sum(C))


test = int(input())
for t in range(test):
	str1 = input()
	lst = list()
	c = 0
	for x in range(len(str1)):
		if str1[x] == '0':
			if c > 0:
				lst.append(c)
			c = 0
		else:
			c = c + 1
	if c > 0:
		lst.append(c)
	lst.sort()
	Alice = 0
	for j in range(len(lst) - 1, -1, -2):
		Alice = Alice + lst[j]
	print(Alice)


t = int(input())
for j in range(t):
	alice = 0
	bob = 0
	flag = True
	binary = list(map(int, input()))
	aux = list(binary)
	for i in range(len(binary) - 1):
		if binary[i] == 1:
			if binary[i + 1] == 1:
				aux[i + 1] = aux[i] + aux[i + 1]
				aux[i] = 0
	orderedAux = sorted(aux)
	for i in range(len(orderedAux) - 1, -1, -1):
		if flag:
			alice += orderedAux[i]
			flag = False
		else:
			bob += orderedAux[i]
			flag = True
	print(alice)


for _ in range(int(input())):
	n = str(input())
	a = list(n)
	c = list()
	flag = False
	count = 0
	for i in range(len(a)):
		if a[i] == '1':
			count += 1
			flag = True
		elif a[i] == '0' and flag == True:
			c.append(count)
			count = 0
		if i == len(a) - 1 and a[i] == '1':
			c.append(count)
	c.sort()
	c.reverse()
	ans = 0
	for i in range(len(c)):
		if i == 1:
			pass
		elif i % 2 == 0 or i == 0:
			ans += c[i]
	print(ans)


def solve():
	s = input()
	ones = s.split('0')
	ones.sort(reverse=True)
	res = 0
	flag = True
	for i in range(len(ones)):
		if ones[i] == '':
			continue
		if flag:
			res += len(ones[i])
		flag = not flag
	print(res)

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


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

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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

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

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

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	s = input()
	n = len(s)
	a = []
	i = 0
	while i < n:
		if s[i] == '1':
			c = 1
			i += 1
			while i < n and s[i] == '1':
				i += 1
				c += 1
			a.append(c)
			c = 0
		else:
			i += 1
	a.sort(reverse=True)
	ans = 0
	for i in range(len(a)):
		if i % 2 == 0:
			ans += a[i]
	print(ans)


t = int(input())
for _t in range(t):
	s = input()
	l = []
	c = 0
	sm = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
		else:
			sm += c
			l.append(c)
			c = 0
	l.append(c)
	sm += c
	l.sort()
	h = 0
	for i in range(len(l)):
		if i % 2:
			h += l[i]
	print(max(h, sm - h))


for _ in range(int(input())):
	l = input()
	c = 1
	s = []
	for i in range(len(l) - 1):
		if l[i] == '1' and l[i + 1] == '1':
			c = c + 1
		elif l[i] == '1' and l[i + 1] == '0':
			s.append(c)
			c = 1
	if l[-1] == '1':
		s.append(c)
	s.sort(reverse=True)
	sum1 = 0
	sum2 = 0
	for i in range(len(s)):
		if i % 2:
			sum1 = sum1 + s[i]
		else:
			sum2 = sum2 + s[i]
	print(max(sum1, sum2))


def main():
	t = int(input())
	for _ in range(t):
		a = input()
		b = []
		count = 0
		for i in a:
			if i == '1':
				count += 1
			else:
				if count != 0:
					b.append(count)
				count = 0
		else:
			if count != 0:
				b.append(count)
		b.sort(reverse=True)
		ans = 0
		for i in range(0, len(b), 2):
			ans += b[i]
		print(ans)
main()


from sys import stdin, stdout
from collections import defaultdict
import math
for _ in range(int(input())):
	s = input()
	l = []
	f = 0
	c = 0
	for i in range(len(s)):
		if s[i] == '1':
			if f == 0:
				f = 1
				c += 1
			else:
				c += 1
		elif f == 1:
			l.append(c)
			c = 0
			f = 0
	if f == 1:
		l.append(c)
		c = 0
		f = 0
	l.sort(reverse=True)
	ans = 0
	for i in range(len(l)):
		if i % 2 == 0:
			ans += l[i]
	print(ans)


import io
import os
from collections import Counter, defaultdict, deque

def makeRepeat(arr):
	repeat = [[arr[0], 0]]
	for x in arr:
		if x == repeat[-1][0]:
			repeat[-1][1] += 1
		else:
			repeat.append([x, 1])
	return repeat

def solve(S):
	repeats = makeRepeat(S)
	freq = sorted([count for (x, count) in repeats if x == '1'], reverse=True)
	score = 0
	for i in range(0, len(freq), 2):
		score += freq[i]
	return score
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	S = input().decode().rstrip()
	ans = solve(S)
	print(ans)


t = int(input())
for i in range(t):
	arr = input()
	temp = []
	n = len(arr)
	ptr = 0
	while ptr < n:
		if arr[ptr] == '1':
			count = 0
			while ptr < n and arr[ptr] == '1':
				count += 1
				ptr += 1
			temp.append(count)
		else:
			ptr += 1
	temp.sort(reverse=True)
	ans = 0
	for i in range(0, len(temp), 2):
		ans += temp[i]
	print(ans)


n = int(input())
for i in range(n):
	string = str(input())
	ara = [0]
	len_string = len(string)
	flag = 0
	cnt = 0
	index = 0
	for j in range(index, len_string):
		if flag == 1:
			if string[j] == '1' and j != len_string - 1:
				cnt += 1
				flag = 1
			elif string[j] == '1' and j == len_string - 1:
				cnt += 1
				ara.append(cnt)
			else:
				ara.append(cnt)
				cnt = 0
				flag = 0
		elif string[j] == '1' and j != len_string - 1:
			flag = 1
			cnt += 1
		elif string[j] == '1' and j == len_string - 1:
			ara.append(1)
	ara.sort()
	ara.reverse()
	ans = 0
	for j in range(len(ara)):
		if j % 2 == 0:
			ans += ara[j]
	print(ans)


n = int(input())
for i in range(n):
	s = input()
	s += '0'
	a = []
	tmp = 0
	for j in range(len(s)):
		if s[j] == '1':
			tmp += 1
		else:
			if tmp > 0:
				a.append(tmp)
			tmp = 0
	a.sort()
	a.reverse()
	s_m = 0
	for j in range(0, len(a), 2):
		s_m += a[j]
	print(s_m)


t = int(input())
for _ in range(t):
	s = [len(i) for i in input().split('0')]
	s = sorted(list(filter(0 .__ne__, s)), reverse=True)
	print(sum([s[i] for i in range(0, len(s), 2)]))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = input().strip()
	n = len(s)
	ans = []
	count = 0
	flag = 0
	for i in range(n):
		if s[i] == '1':
			count += 1
			flag = 1
		elif flag == 1:
			ans.append(count)
			count = 0
			flag = 0
	ans.append(count)
	ans.sort(reverse=True)
	res = 0
	for i in range(0, len(ans), 2):
		res += ans[i]
	print(res)


t = int(input())
for T in range(t):
	s = input()
	al = True
	ans = 0
	a = []
	temp = 0
	for i in s:
		if i == '1':
			temp += 1
		else:
			if temp != 0:
				a.append(temp)
			temp = 0
	if temp != 0:
		a.append(temp)
	nn = len(a)
	a.sort(reverse=True)
	for i in range(0, nn, 2):
		ans += a[i]
	print(ans)


def AliceScore(nums):
	score = 0
	alice_turn = True
	while '1' in nums:
		longest = -1
		start_idx = -1
		i = 0
		while i < len(nums):
			if nums[i] == '1':
				streak = 0
				while i < len(nums) and nums[i] == '1':
					i += 1
					streak += 1
				if streak > longest:
					longest = streak
					start_idx = i - streak
			else:
				i += 1
		if alice_turn:
			score += longest
		alice_turn = not alice_turn
		nums = nums[:start_idx] + nums[start_idx + longest:]
	return score
array_list = []
n = int(input())
for i in range(n):
	array_list.append(list(input()))
for array in array_list:
	print(AliceScore(array))


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

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

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

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

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

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

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

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

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

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

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

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

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

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

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
for _ in range(ii()):
	s = input()
	for i in range(100, 0, -1):
		s = s.replace('0' * i, ' ')
	a = s.split()
	a.sort(reverse=True)
	ans = 0
	for i in range(0, len(a), 2):
		ans += len(a[i])
	print(ans)


t = int(input())
while t != 0:
	t -= 1
	s = input()
	i = 0
	n = len(s)
	ones = []
	while True:
		cnt = 0
		while i < n and s[i] == '1':
			cnt += 1
			i += 1
		ones.append(cnt)
		cnt = 0
		while i < n and s[i] == '0':
			cnt += 1
			i += 1
		if i == n:
			break
	ones.sort(reverse=True)
	ans = 0
	for i in range(0, len(ones), 2):
		ans += ones[i]
	print(ans)


from collections import Counter
from itertools import groupby

def call(s):
	x = 0
	lis = []
	coun = groupby(s)
	for (i, c) in coun:
		count = 0
		for j in c:
			count += 1
		lis.append((i, count))
	new = sorted(lis)
	turn = 0
	alice = 0
	for i in range(len(new) - 1, -1, -1):
		(no, nu) = new[i]
		if turn % 2 == 0 and no == '1':
			alice += nu
		turn += 1
	print(alice)
t = int(input())
for i in range(t):
	s = input()
	call(s)


import itertools

def solve(s):
	ones = []
	for (_, group) in itertools.groupby(s):
		grp = list(group)
		if grp[0] == '1':
			ones.append(grp)
	ones = sorted(ones, key=lambda x: -len(x))
	res = 0
	for i in range(0, len(ones), 2):
		res += len(ones[i])
	return res
res = []
t = int(input())
while t:
	s = input()
	res.append(solve(s))
	t -= 1
for r in res:
	print(r)


t = int(input())
for _ in range(t):
	n = input()
	c = 0
	a = []
	for s in n:
		if s == '1':
			c += 1
		else:
			if c != 0:
				a.append(c)
			c = 0
	if c != 0:
		a.append(c)
	a.sort()
	a.reverse()
	b = 0
	for i in range(len(a)):
		if i % 2 == 0:
			b += a[i]
	print(b)


t = int(input())
while t:
	s = input()
	n = len(s)
	a = []
	u = 0
	if s[0] == '0':
		f = 0
	else:
		f = 1
		u = 1
	d = {}
	for x in range(1, n):
		if s[x] == s[x - 1] and s[x] == '1' and (f == 1):
			u += 1
		if s[x] != s[x - 1] and s[x] == '1':
			f = 1
			u = 1
		if s[x] == '0':
			if s[x - 1] == '1':
				a.append(u)
			u = 0
			f = 0
	a.append(u)
	a = sorted(a, reverse=True)
	su = 0
	for x in range(len(a)):
		if x % 2 == 0:
			su += a[x]
	print(su)
	t -= 1


for _ in range(int(input())):
	s = input()
	i = 0
	b = []
	count = 0
	n = len(s)
	while i < n:
		if s[i] == '1':
			c = ''
			j = i
			while j < n:
				if s[j] == '1':
					c += '1'
					count += 1
					j += 1
				else:
					break
			b.append(c)
			i = i + count
			count = 0
		else:
			i += 1
	b.sort()
	q = 0
	i = len(b) - 1
	while i >= 0:
		q += len(b[i])
		i -= 2
	print(q)


for _ in range(int(input())):
	z = list(map(int, list(input().strip())))
	n = len(z)
	if all(z) == True:
		print(n)
	else:
		count = 0
		z1 = []
		for x in range(n):
			if x == n - 1 and z[x] == 1:
				z1.append(count + 1)
			elif z[x] == 0:
				z1.append(count)
				count = 0
			else:
				count += 1
		z1.sort()
		alice = 0
		for x in range(len(z1) - 1, -1, -2):
			if z1[x] == 0:
				break
			else:
				alice += z1[x]
		print(alice)


t = int(input())
for tt in range(t):
	s = input()
	i = 0
	nums1 = []
	while i < len(s):
		num = 0
		while i < len(s) and s[i] == '1':
			i += 1
			num += 1
		if num:
			nums1 += [num]
		i += 1
	nums1.sort(reverse=True)
	print(sum(nums1[::2]))


for _ in range(int(input())):
	st = input()
	li = []
	count = 0
	for i in st:
		if i == '1':
			count += 1
		else:
			if count != 0:
				li.append(count)
			count = 0
	if count != 0:
		li.append(count)
	li.sort(reverse=True)
	ans = 0
	for i in range(0, len(li), 2):
		ans += li[i]
	print(ans)


from heapq import heappush, heappop
t = int(input())
for ti in range(t):
	s = input()
	cur = 0
	h = []
	for c in s:
		if c == '1':
			cur += 1
		elif cur != 0:
			heappush(h, -cur)
			cur = 0
	else:
		if cur != 0:
			heappush(h, -cur)
			cur = 0
	point = 0
	i = 0
	while len(h) > 0:
		temp = heappop(h)
		if i % 2 == 0:
			point -= temp
		i += 1
	print(point)


t = int(input())
for _ in range(t):
	x = input()
	ones = [0]
	i = 0
	while i < len(x):
		if x[i] == '1':
			j = i
			count = 0
			while j < len(x):
				if x[j] != '1':
					break
				count += 1
				j += 1
				i += 1
			ones.append(count)
			i -= 1
		i += 1
	ones.sort(reverse=True)
	step = 0
	for i in range(0, len(ones), 2):
		step += ones[i]
	print(step)


for i in range(int(input())):
	x = input().split('0')
	x.sort()
	x = x[::-1]
	a = 0
	for i in range(0, len(x), 2):
		a += len(x[i])
	print(a)


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	s = [int(i) for i in input()]
	ans = [0]
	for i in s:
		if ans[-1] == 0 and i == 0:
			continue
		elif i == 0:
			ans.append(0)
		else:
			ans[-1] += 1
	ans.sort(reverse=True)
	print(sum(ans[::2]))


import re
t = int(input())
for i in range(t):
	s = input()
	a = re.split('0+', s)
	a.sort(reverse=True)
	count = 0
	for j in range(0, len(a), 2):
		count = count + len(a[j])
	print(count)


for t in range(int(input())):
	s = str(input())
	l = []
	c = 0
	x = 0
	n = len(s)
	for i in range(n):
		if s[i] == '1':
			c += 1
		elif c > 0:
			l.append(c)
			c = 0
	if s[-1] != '0':
		l.append(c)
	l = sorted(l)[::-1]
	for j in range(0, len(l), 2):
		x += l[j]
	print(x)


import sys, math
input = sys.stdin.readline
t = int(input())
for r in range(t):
	s = input().strip('\n')
	n = len(s)
	l = []
	count1 = 0
	for i in s:
		l.append(int(i))
		if int(i) == 1:
			count1 += 1
	toggle = 0
	alice = 0
	while count1 > 0:
		i = 0
		length = 0
		start = 0
		end = 0
		while i < n:
			if l[i] == 1:
				j = i + 1
				while j < n:
					if l[j] == 0:
						break
					j += 1
				if j - i > length:
					length = j - i
					start = i
					end = j
			i += 1
		temp = l[0:start] + l[end:]
		l = temp
		if toggle == 0:
			alice += length
		toggle ^= 1
		count1 = 0
		for k in l:
			if k == 1:
				count1 += 1
		n = len(l)
	print(alice)


from itertools import groupby
for _ in range(0, int(input())):
	s = input()
	groups = groupby(s)
	v = []
	for g in groups:
		if g[0] == '1':
			v.append(len(list(g[1])))
	v = sorted(v, reverse=True)
	print(sum(v[::2]))


for _ in range(int(input())):
	s = list(input())
	li = []
	count = 0
	sum = 0
	for i in range(len(s)):
		if s[i] == '1':
			count += 1
		else:
			if count != 0:
				li.append(count)
			count = 0
		if i == len(s) - 1 and count != 0:
			li.append(count)
			count = 0
	li.sort(reverse=True)
	for i in range(0, len(li), 2):
		sum += li[i]
	print(sum)


def main():
	for i in range(int(input())):
		v = input()
		alice = 0
		empt = []
		times = 0
		if '0' not in v:
			alice = len(v)
		else:
			for i in range(len(v)):
				if v[i] == '1':
					times += 1
				elif v[i] == '0':
					empt.append(times)
					times = 0
			if v[-1] == '1':
				empt.append(times)
			empt.sort(reverse=True)
			end = len(empt)
			for i in range(0, end, 2):
				alice += empt[i]
		print(alice)
main()


def solve(s):
	res = turn = 0
	while len(s):
		max_ones = cnt = 0
		for (i, c) in enumerate(s):
			if c == '0':
				max_ones = max(max_ones, cnt)
				cnt = 0
			else:
				cnt += 1
		max_ones = max(max_ones, cnt)
		s = s.replace('1' * max_ones, '', 1)
		if turn == 0:
			res += max_ones
		turn ^= 1
		if max_ones == 0:
			break
	return res
T = int(input())
res = []
for _ in range(T):
	s = input()
	ans = solve(s)
	res.append(str(ans))
print('\n'.join(res))


T = int(input())
newList = []
for _ in range(T):
	sum = 0
	myList = []
	s = list(input())
	k = 0
	for i in range(len(s)):
		if i != len(s) - 1:
			if s[i] == '1':
				k += 1
			else:
				if k != 0:
					myList.append(k)
				k = 0
		elif s[-1] == '1':
			myList.append(k + 1)
		else:
			myList.append(k)
	myList = sorted(myList, reverse=True)
	for j in range(len(myList)):
		if j % 2 == 0:
			sum += myList[j]
	newList.append(sum)
for elem in newList:
	print(elem)


for _ in range(int(input())):
	s = input()
	a = list()
	curr = 0
	s += '0'
	for i in s:
		if i == '1':
			curr += 1
		else:
			if curr > 0:
				a.append(curr)
			curr = 0
	a.sort(reverse=True)
	c = 0
	for i in range(0, len(a), 2):
		c += a[i]
	print(c)


from collections import Counter
import sys
sys.setrecursionlimit(10 ** 6)
mod = 1000000007
inf = int(1e+18)
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]

def inverse(a):
	return pow(a, -1, mod)

def solve():
	s = input()
	g = {}
	p = 0
	for i in range(len(s)):
		if s[i] == '1':
			continue
		g[i - p] = g.get(i - p, 0) + 1
		p = i + 1
	if s[-1] == '1':
		g[len(s) - p] = g.get(len(s) - p, 0) + 1
	ans = 0
	turn = True
	for (value, cnt) in sorted(g.items(), reverse=True):
		if turn:
			ans += value * ((cnt + 1) // 2)
		else:
			ans += value * (cnt // 2)
		if cnt % 2 == 1:
			turn = not turn
	print(ans)

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


def sum(a):
	c = 0
	f = []
	for l in a:
		if l == 1:
			c += 1
		else:
			f.append(c)
			c = 0
	f.append(c)
	f.sort()
	s = 0
	if len(f) % 2 == 0:
		for j in range(len(f)):
			if j % 2 != 0:
				s += f[j]
	else:
		for j in range(len(f)):
			if j % 2 == 0:
				s += f[j]
	print(s, '\n')
t = int(input())
for e in range(t):
	a = list(map(int, input()))
	sum(a)


for _ in range(int(input())):
	s = input()
	num = []
	for i in s.split('0'):
		if i:
			num.append(len(i))
	num.sort(reverse=True)
	total = 0
	i = 0
	while i < len(num):
		total = total + num[i]
		i = i + 2
	print('%d\n' % total)


t = int(input())
for q in range(t):
	s = input()
	cnt = 0
	arr = []
	for i in range(len(s)):
		if s[i] == '1':
			cnt += 1
		elif s[i] == '0':
			arr.append(cnt)
			cnt = 0
	if cnt > 0:
		arr.append(cnt)
	arr.sort(reverse=True)
	ans = 0
	for i in range(0, len(arr), 2):
		ans += arr[i]
	print(ans)


def subStringRemoval(s):
	return sum(s[::-2])
t = int(input())
for i in range(t):
	s = map(len, input().split('0'))
	print(subStringRemoval(sorted(s)))


import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
T = ni()
for _ in range(T):
	s = str(ns())
	le = len(s)
	su = 0
	temp = []
	for i in range(le):
		if s[i] == '1':
			su += 1
		else:
			temp.append(su)
			su = 0
	temp.append(su)
	temp.sort()
	l = len(temp)
	ans = 0
	for i in range(l - 1, -1, -2):
		ans += temp[i]
	print(ans)


def find_max(a):
	c = 0
	i = 0
	ans = 0
	while i < len(a):
		if a[i] == '1':
			c += 1
		elif a[i] == '0':
			ans = max(ans, c)
			c = 0
		i += 1
	return max(ans, c)
for _ in range(int(input())):
	a = input()
	alice = 0
	c = 0
	bob = 0
	while True:
		if c == 0:
			p = find_max(a)
			if p >= 1:
				alice += p
				a = a.replace('1' * p, '0', 1)
				c = 1
			elif p == 0:
				print(alice)
				break
		elif c == 1:
			q = find_max(a)
			bob += q
			if q >= 1:
				a = a.replace('1' * q, '0', 1)
				c = 0
			elif q == 0:
				print(alice)
				break


from itertools import groupby
for i in range(int(input())):
	n = input()
	results = []
	for (k, j) in groupby(n):
		if k == '1':
			results.append(len(list(j)))
	results.sort(reverse=True)
	alex = 0
	for i in range(0, len(results), 2):
		alex += results[i]
	print(alex)


for t in range(int(input())):
	l = list(input()) + ['0']
	ol = []
	curr = '0'
	le = 1
	for i in l:
		if i == curr:
			le += 1
		else:
			if curr == '1':
				ol.append(le)
			curr = i
			le = 1
	ol = list(sorted(ol))[::-1]
	ans = 0
	for i in range(0, len(ol), 2):
		ans += ol[i]
	print(ans)


for _ in range(int(input())):
	arr = list(input())
	cont_ones = []
	curr = 0
	for i in arr:
		if curr != 0:
			if i == '1':
				curr += 1
			else:
				cont_ones.append(curr)
				curr = 0
		elif i == '1':
			curr = 1
	if curr:
		cont_ones.append(curr)
	cont_ones.sort(reverse=True)
	score = 0
	for i in range(0, len(cont_ones), 2):
		score += int(cont_ones[i])
	print(score)


t = int(input())
for i in range(t):
	a = input().strip('0').split('0')
	a.sort(reverse=True)
	s = 0
	for y in a[::2]:
		s = s + len(y)
	print(s)


for _ in range(int(input())):
	s = input()
	lol = []
	j = 0
	for i in s:
		if i == '1':
			j += 1
		else:
			lol.append(j)
			j = 0
	if s[-1] == '1':
		lol.append(j)
	lol.sort()
	lol = lol[::-1]
	s = 0
	for i in range(len(lol)):
		if i % 2 == 0:
			s += lol[i]
	print(s)


for s in ' ' * int(input()):
	(n, cnt) = (sorted(input().replace('0', ' ').split(), key=lambda x: len(x), reverse=True), 0)
	for i in range(0, len(n), 2):
		cnt += len(n[i])
	print(cnt)


def f(stri):
	n = len(stri)
	c = []
	count = 0
	for i in range(n):
		if stri[i] == '1':
			count += 1
		elif count != 0 and stri[i] == '0':
			c += [count]
			count = 0
		elif stri[i] != '0' and stri[i] != '1':
			return 'error'
	if count != 0:
		c += [count]
	return c
n = int(input())
for i in range(n):
	c = 0
	s = input()
	a = f(s)
	a.sort(reverse=True)
	for j in range(len(a)):
		if j % 2 == 0:
			c += a[j]
	print(c)


for _ in range(int(input())):
	x = input()
	x = x.split('0')
	c = ans = 0
	s = []
	for i in x:
		if i:
			s.append(len(i))
	s.sort(reverse=True)
	for i in s:
		c += 1
		if c % 2:
			ans += i
	print(ans)


for test in range(int(input())):
	s = input()
	a = []
	now = 0
	n = len(s)
	for i in range(n):
		if s[i] == '0':
			if now > 0:
				a.append(now)
			now = 0
		else:
			now += 1
	if now > 0:
		a.append(now)
	a.sort(reverse=True)
	ans = 0
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)


def countSubstrings(array):
	sub_arr = []
	start = 0
	prev = 0
	for (i, e) in enumerate(array):
		if e == 1 and prev == 0:
			start = i
		if e == 0 and prev == 1:
			sub_arr.append(i - start)
		if i == len(array) - 1 and e == 1:
			sub_arr.append(i - start + 1)
		prev = e
	return sub_arr

def printSolution(array):
	sub_arr = countSubstrings(array)
	sub_arr.sort(reverse=True)
	sum = 0
	for i in range(0, len(sub_arr), 2):
		sum += sub_arr[i]
	print(sum)

def submit():
	for case in range(int(input())):
		array = [int(e) for e in input()]
		printSolution(array)
submit()


t = int(input())
for i in range(t):
	s = input()
	n = len(s)
	arr = []
	alice = 0
	bob = 0
	while len(s) > 0:
		start = s.find('1')
		if start == -1:
			break
		end = s.find('0', start)
		if end == -1:
			arr.append(len(s) - start)
			s = ''
		else:
			arr.append(end - start)
			s = s[end + 1:]
	arr = sorted(arr)
	if len(arr) % 2 == 0:
		for j in range(len(arr)):
			if j % 2 == 0:
				bob = bob + arr[j]
			else:
				alice = alice + arr[j]
	else:
		for j in range(len(arr)):
			if j % 2 == 0:
				alice = alice + arr[j]
			else:
				bob = bob + arr[j]
	print(alice)


n = int(input())
for i in range(n):
	s = input()
	z = s.split('0')
	x = []
	for i in z:
		if i != '':
			x += (i,)
	score = 0
	store = sorted(x, key=lambda i: len(i), reverse=True)
	for i in store[0::2]:
		score += len(i)
	print(score)


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = 10 ** 9 + 7

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

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = []
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

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

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

def main():
	s = input()
	n = len(s)
	one = []
	cnt = 0
	for i in range(n):
		if s[i] == '1':
			cnt += 1
		else:
			if cnt:
				one.append(cnt)
			cnt = 0
	if cnt:
		one.append(cnt)
	one = sorted(one, reverse=True)
	ans = 0
	for i in range(0, len(one), 2):
		ans += one[i]
	print(ans)
t = 1
t = int(input())
for _ in range(t):
	main()


n1 = int(input())
for i in range(n1):
	s = input()
	m = s.split('0')
	l = []
	c = 0
	for j in range(len(m)):
		if m[j] != '':
			l.append(len(m[j]))
	l.sort(reverse=True)
	for j in range(0, len(l), 2):
		c += l[j]
	print(c)


import re
n = int(input())
a = []
for i in range(n):
	a.append(input())
	a[-1] = re.sub('[0]', ' ', a[-1]).split()
	a[-1].sort()
	a[-1].reverse()
b = []
for i in range(n):
	if len(a[-1]) == 0:
		b.append([0])
	else:
		count = 0
		for j in range(0, len(a[i]), 2):
			count += len(a[i][j])
		b.append(count)
for i in b:
	print(i)


from sys import stdin, stdout
import math
from collections import Counter, deque
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
S = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()
mod = 1000000007

def pr(a):
	return ''.join(list(map(str, a)))

def solve():
	s = S()
	a = s.split('0')
	l = []
	for i in a:
		c = i.count('1')
		if c:
			l += [c]
	l.sort(reverse=True)
	print(sum(l[0:len(a):2]))
for _ in range(I()):
	solve()


for _ in range(int(input())):
	s = input()
	n = len(s)
	l = []
	c = 0
	for i in range(n):
		if s[i] == '1':
			c += 1
		else:
			if c != 0:
				l.append(c)
			c = 0
	if c != 0:
		l.append(c)
	l.sort(reverse=True)
	ans = 0
	n = len(l)
	for i in range(0, n, 2):
		ans += l[i]
	print(ans)


from functools import lru_cache
from sys import stdin, stdout
import sys
from math import *
input = stdin.readline
for __ in range(int(input())):
	s = input()
	ar = []
	x = 0
	y = 0
	while y < len(s):
		if s[x] == s[y]:
			y += 1
		else:
			if s[x] == '1':
				ar.append(y - x)
			x = y
	if x != len(s) - 1:
		ar.append(y - x)
	ar.sort(reverse=True)
	ans = 0
	for i in range(len(ar)):
		if i % 2 == 0:
			ans += ar[i]
	print(ans)


import sys
input = sys.stdin.readline
I = lambda : list(map(str, input().split()))
(m,) = I()
m = int(m)
while m:
	m -= 1
	arr = I()[0]
	li = arr.split('0')
	temp = []
	for i in li:
		if i != '':
			temp.append(i)
	k = 0
	val = 0
	for i in sorted(temp, reverse=True):
		if k % 2 == 0:
			k += 1
			val += len(i)
		else:
			k += 1
	print(val)


for _ in range(int(input())):
	s = str(input())
	arr = []
	k = 0
	for i in range(len(s)):
		if s[i] == '1':
			k += 1
		elif s[i] == '0':
			arr.append(k)
			k = 0
	if k != 0:
		arr.append(k)
	arr.sort(reverse=True)
	ans = 0
	i = 0
	while i < len(arr):
		ans += arr[i]
		i += 2
	print(ans)


n = int(input())
for _ in range(n):
	s = list(input())
	my_list = []
	i = 0
	while i < len(s):
		f = 1
		count = 0
		if s[i] == '1':
			for j in range(i, len(s)):
				if s[j] == '0':
					x = j
					f = 0
					break
				count += 1
		if f:
			i += 1
		else:
			i = x
			my_list.append(count)
	if s[-1] == '1':
		k = len(s) - 1
		c = 0
		while k >= 0 and s[k] == '1':
			c += 1
			k -= 1
		my_list.append(c)
	ans = 0
	if len(my_list) == 0:
		print(0)
	else:
		me = 0
		while len(my_list) > 0:
			if me % 2 == 0:
				ans += max(my_list)
				my_list.remove(max(my_list))
			else:
				my_list.remove(max(my_list))
			me += 1
		print(ans)


for y in range(int(input())):
	a = input()
	b = a.split('0')
	l = []
	p = []
	for i in b:
		l.append(len(i))
	for i in l:
		if i != 0:
			p.append(i)
	p.sort(reverse=True)
	t = 0
	for i in range(0, len(p), 2):
		t += p[i]
	print(t)


for t in range(int(input())):
	s = input()
	ans = 0
	p = 0
	en = 0
	while '1' in s:
		mx = 0
		c = 1
		for i in range(len(s) - 1):
			if s[i] == '1' and s[i + 1] == '1':
				c = c + 1
				if c > mx:
					mx = c
					en = i + 1
			else:
				c = 1
		st = en - mx + 1
		s1 = ''
		for j in range(len(s)):
			if j < st or j > en:
				s1 = s1 + s[j]
		s = s1
		if p % 2 == 0:
			ans = ans + mx
		if mx == 0:
			break
		else:
			p = p + 1
	c = 0
	for i in range(len(s)):
		if s[i] == '1':
			c = c + 1
	if p % 2 == 1:
		ans = ans + int(c / 2)
	else:
		ans = ans + int(c / 2) + c % 2
	print(ans)


t = int(input())
for i in range(t):
	ans = 0
	i = 0
	lst = input()
	lst = lst.split('0')
	lst2 = []
	for item in lst:
		lst2.append(len(item))
	lst2.sort()
	lst2.reverse()
	while i < len(lst2):
		ans = ans + lst2[i]
		i += 2
	print(ans)


def solve(s):
	ans = []
	i = 0
	while i < len(s):
		cnt = 0
		if s[i] == '1':
			while i < len(s) and s[i] != '0':
				i += 1
				cnt += 1
			ans.append(cnt)
			i -= 1
		i += 1
	ans.sort()
	i = len(ans) - 1
	cnt = 0
	while i >= 0:
		cnt += ans[i]
		i -= 2
	print(cnt)
t = int(input())
for i in range(t):
	solve(input())


n = int(input())
for i in range(n):
	s = list(filter(None, input().split('0')))
	s.sort(key=len, reverse=True)
	if len(s) == 0:
		print('0')
		continue
	r = ''
	for j in s[::2]:
		r += j
	print(len(r))


mod = 1000000007
ssi = lambda : map(int, input().split())
for _ in range(int(input())):
	s = input().split('0')
	s = sorted(s, reverse=True)
	alice = 0
	for i in range(len(s)):
		if s[i] == '':
			break
		elif i % 2 == 0:
			alice += s[i].count('1')
	print(alice)


t = int(input())
for _ in range(t):
	l = []
	s = input()
	i = 0
	n = len(s)
	a = 0
	while i < n:
		if s[i] == '1':
			c = 1
			i += 1
			while i < n and s[i] == '1':
				i += 1
				c += 1
			l.append(c)
		else:
			i += 1
	l.sort()
	l.reverse()
	for j in range(0, len(l)):
		if j & 1 == 0:
			a += l[j]
	print(a)


for _ in range(int(input())):
	s = input()
	l = []
	c = 0
	k = s.find('1')
	for i in range(k, len(s)):
		if s[i] == '1':
			c += 1
		else:
			l.append(c)
			c = 0
	if s[len(s) - 1] == '1':
		l.append(c)
	l.sort(reverse=True)
	a = 0
	for i in range(len(l)):
		if i % 2 == 0:
			a += l[i]
	print(a)


for i in range(int(input())):
	arr = [*input()]
	l = []
	c = 0
	ans = 0
	for j in range(len(arr)):
		if arr[j] == '1':
			c += 1
			if len(l) > 0:
				l.pop(-1)
			l.append(c)
		else:
			c = 0
			l.append(0)
	l = sorted([i for i in l if i != 0], reverse=True)
	for j in range(len(l)):
		if j % 2 == 0:
			ans += l[j]
	print(ans)


for t in range(int(input())):
	s = sorted(input().split('0'))
	les = sorted([len(i) for i in s], reverse=True)
	print(sum(les[::2]))


for _ in range(int(input())):
	s = input()
	l = []
	i = 0
	while i < len(s):
		cnt = 0
		while i < len(s) and s[i] == '1':
			cnt += 1
			i += 1
		if cnt > 0:
			l.append(cnt)
		while i < len(s) and s[i] == '0':
			i += 1
	l.sort(reverse=True)
	sum = 0
	for i in range(0, len(l), 2):
		sum += l[i]
	print(sum)


t = int(input())
for _ in range(t):
	s = input()
	f = True
	(a, b, x, y, z) = (0, 0, 0, 0, 0)
	while '1' in s:
		x = s.count('1')
		for i in range(x, 0, -1):
			if '1' * i in s:
				y = i
				break
		if f:
			a += y
		else:
			b += y
		z = s.index('1' * y)
		s = s[:z] + s[z + y:]
		f = not f
	print(a)


for _ in [0] * int(input()):
	a = list(input())
	arr = []
	ct = 0
	zflag = False
	for b in a:
		if b == '0' and zflag == False:
			ct += 1
		elif b == '1' and zflag == False:
			arr.append(ct)
			ct = 1
			zflag = True
		elif b == '0' and zflag == True:
			arr.append(ct)
			ct = 1
			zflag = False
		elif b == '1' and zflag == True:
			ct += 1
	arr.append(ct)
	ans = arr[1::2]
	ans.sort()
	ans = ans[::-1]
	print(sum(ans[::2]))


t = int(input())
for i in range(t):
	s = input()
	c1 = s.count('1')
	o1 = []
	if c1 == 0:
		print(0)
	else:
		i = 0
		while i < len(s):
			if s[i] == '1' and i != len(s) - 1:
				count = 1
				j = i
				while s[j] == s[j + 1]:
					count += 1
					j = j + 1
					if j == len(s) - 1:
						break
				o1.append(count)
				i = i + count
			elif s[i] == '1' and i == len(s) - 1:
				o1.append(1)
				break
			else:
				i = i + 1
		o1.sort(reverse=True)
		s = 0
		r = 0
		while r < len(o1):
			s = s + o1[r]
			r = r + 2
		print(s)


import sys
input = sys.stdin.readline

def sub_string(s):
	sub = s.split('0')
	sub.sort(reverse=True)
	return (sub[0], len(sub[0]))

def solve():
	s = input()
	alice = 0
	i = 0
	s = s.replace('\n', '')
	while '1' in s:
		(sub, c) = sub_string(s)
		if i % 2 == 0 and '0' not in sub:
			alice += c
		s = s.replace(sub, '', 1)
		i += 1
	print(alice)
T = int(input())
for _ in range(T):
	solve()


T = int(input())
for test in range(T):
	s = input()
	num = []
	count = 1
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			count += 1
		else:
			if s[i] == '0':
				num.append(count)
			count = 1
	if s[-1] == '1':
		num.append(count)
	num.sort(reverse=True)
	print(sum(num[0::2]))


for _ in range(int(input())):
	ans = 0
	S = input()
	l = sorted(S.split('0'), reverse=True)
	for i in range(len(l)):
		if i % 2 == 0:
			ans += len(l[i])
	print(ans)


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

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

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

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

def solve():
	st = input()
	ls = []
	c_o = 0
	for val in st:
		if val == '1':
			c_o += 1
		else:
			if c_o > 0:
				ls.append(c_o)
			c_o = 0
	if c_o > 0:
		ls.append(c_o)
	ls.sort(reverse=True)
	ans = 0
	for val in ls[::2]:
		ans += val
	print(ans)

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


import math
from decimal import Decimal
import heapq
import copy
import heapq
from collections import deque
from collections import defaultdict
MOD = 1000000007

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def da():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	return (n, m, a)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def lol(lst, k):
	k = k % len(lst)
	ret = [0] * len(lst)
	for i in range(len(lst)):
		if i + k < len(lst) and i + k >= 0:
			ret[i] = lst[i + k]
		if i + k >= len(lst):
			ret[i] = lst[i + k - len(lst)]
		if i + k < 0:
			ret[i] = lst[i + k + len(lst)]
	return ret

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def fact(n):
	tc = []
	ans = {}
	d = 2
	while d * d <= n:
		if n % d == 0:
			tc.append(d)
			n //= d
		else:
			d += 1
	if n > 1:
		tc.append(n)
	for i in tc:
		ans[i] = ans.get(i, 0) + 1
	return ans

def to_zero(n, s):
	lst = s[0]
	ans = []
	for i in range(n):
		if lst == s[i]:
			continue
		elif lst == '0':
			lst = '1'
			ans.append(i)
		else:
			lst = '0'
			ans.append(i)
	if lst == '1':
		ans.append(n)
	return ans
for _ in range(int(input())):
	s = input()
	s = s.split('0')
	a = []
	for i in s:
		d = len(i)
		if d > 0:
			a.append(d)
	a.sort(reverse=True)
	ans = 0
	for i in range(len(a)):
		if i % 2 == 0:
			ans += a[i]
	print(ans)


from itertools import groupby
t = int(input())
for _ in range(0, t):
	s = [i for i in input()]
	sg = [list(g) for (s, g) in groupby(s)]
	ones = []
	for i in sg:
		if i[0] == '1':
			ones.append(len(i))
	ones.sort(reverse=True)
	alice = 0
	for i in range(0, len(ones), 2):
		alice += ones[i]
	print(alice)


set_num = int(input())
for _ in range(set_num):
	seq = input().split('0')
	values = []
	for element in seq:
		if len(element) > 0:
			values.append(len(element))
	values.sort(reverse=True)
	result = 0
	for i in range(0, len(values), 2):
		result += values[i]
	print(result)


for _ in range(int(input())):
	s = input()
	a = list(s)
	p = []
	c = 0
	for i in range(len(a)):
		if a[i] == '1':
			c += 1
		if a[i] == '0':
			p.append(c)
			c = 0
	if a[-1] == '1':
		p.append(c)
	p.sort(reverse=True)
	ans = 0
	for i in range(len(p)):
		if i % 2 == 0:
			ans += p[i]
	print(ans)


def solve(s, n):
	tmp = []
	i = 0
	while i < n:
		if s[i] == '1':
			j = i + 1
			while j < n and s[j] == '1':
				j += 1
			tmp.append(j - i)
			i = j
		i += 1
	tmp.sort(reverse=True)
	res = 0
	for i in range(0, len(tmp), 2):
		res += tmp[i]
	return res

def main():
	T = int(input())
	for _ in range(T):
		s = input()
		n = len(s)
		out = solve(s, n)
		print(out)
main()


for _ in range(int(input())):
	s = input()
	cnt_table = []
	cnt = 0
	for i in s:
		if i == '1':
			cnt += 1
		else:
			cnt_table.append(cnt)
			cnt = 0
	cnt_table.append(cnt)
	cnt_table.sort(reverse=True)
	score = 0
	for i in range(len(cnt_table)):
		if i % 2 == 0:
			score += cnt_table[i]
	print(score)


def solve():
	s = input()
	lens = []
	i = 0
	count = 0
	while i < len(s):
		while i < len(s) and s[i] == '1':
			i += 1
			count += 1
		if count > 0:
			lens.append(count)
		count = 0
		while i < len(s) and s[i] != '1':
			i += 1
	if not lens:
		print(0)
	else:
		lens.sort(reverse=True)
		ans = 0
		for i in range(0, len(lens), 2):
			ans += lens[i]
		print(ans)
for i in range(int(input())):
	solve()


t = int(input())
for p in range(t):
	s = input()
	n = len(s)
	ans = 0
	grp_of_one = []
	i = 0
	curr = 0
	while i < n:
		if s[i] == '1':
			curr += 1
		else:
			grp_of_one.append(curr)
			curr = 0
		i += 1
	if curr != 0:
		grp_of_one.append(curr)
	grp_of_one.sort()
	grp_of_one.reverse()
	m = len(grp_of_one)
	for j in range(0, m, 2):
		ans += grp_of_one[j]
	print(ans)


def sieve():
	n = 10 ** 5
	s = [[] for i in range(n + 1)]
	for i in range(2, n + 1, 2):
		s[i] = [2]
	for i in range(3, n + 1, 2):
		if s[i]:
			continue
		else:
			for j in range(i, n + 1, i):
				s[j].append(i)
	return s

def prime():
	n = 10 ** 5
	s = [1 for i in range(n + 1)]
	for i in range(2, n + 1):
		if s[i] == 1:
			for j in range(i * i, i < n + 1, i):
				s[j] = 0
	primes = []
	for i in range(2, n + 1):
		if s[i] == 1:
			primes.append(i)
	return primes
for cases in range(int(input())):
	s = input()
	l = []
	count = 0
	for i in range(0, len(s)):
		if i == len(s) - 1 and s[i] == '1':
			l.append(count + 1)
		elif s[i] == '0':
			l.append(count)
			count = 0
		else:
			count += 1
	l.sort()
	l.reverse()
	alice = 0
	for i in range(0, len(l), 2):
		alice += l[i]
	print(alice)


for _ in range(int(input())):
	x = []
	s = input()
	c = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
			if i == len(s) - 1:
				x.append(c)
		else:
			x.append(c)
			c = 0
	z = max(x)
	count = 0
	while z:
		count += z
		x.remove(z)
		if len(x) > 0:
			x.remove(max(x))
			if len(x) == 0:
				break
		else:
			break
		z = max(x)
	print(count)


import math
for _ in range(int(input())):
	s = input()
	A = []
	one = 0
	for i in range(len(s)):
		if s[i] == '1':
			one += 1
		else:
			A.append(one)
			one = 0
	if s[len(s) - 1] == '1':
		A.append(one)
	A.sort(reverse=True)
	fans = 0
	for i in range(0, len(A), 2):
		fans += A[i]
	print(fans)


t = int(input())
while t:
	t -= 1
	s = input()
	y = s.split('0')
	y = sorted(y, reverse=True)
	a = '1'
	for i in range(0, len(y), 2):
		a += y[i]
	print(len(a) - 1)


t = int(input())
for i in range(t):
	s = input()
	arr = []
	count = 0
	for j in range(len(s)):
		if s[j] == '1':
			count += 1
		if s[j] == '0' and count != 0:
			arr.append(count)
			count = 0
	if count != 0:
		arr.append(count)
	arr.sort(reverse=True)
	points = 0
	for i in range(0, len(arr), 2):
		points += arr[i]
	print(points)


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

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

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

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = int(input())
	for _ in range(t):
		st = input()
		n = len(st)
		lis = []
		c = 0
		count = 0
		for i in range(n):
			if c == 0 and st[i] == '1':
				c = 1
				count += 1
				continue
			if c == 1 and st[i] == '1':
				count += 1
			elif c == 1:
				lis.append(count)
				count = 0
				c = 0
		if c == 1:
			lis.append(count)
			count = 0
			c = 0
		lis.sort(reverse=True)
		ans = 0
		for i in range(len(lis)):
			if i % 2 == 0:
				ans += lis[i]
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


for _ in range(int(input())):
	s = input()
	t = s.split('0')
	a = 0
	b = 0
	t.sort(key=len, reverse=True)
	for i in range(len(t)):
		if t[i] != '' and i % 2 == 0:
			a += len(t[i])
		elif t[i] != '':
			b += len(t[i])
	print(max(a, b))


n = int(input())
for _ in range(n):
	res = 0
	s = input().split('0')
	l = []
	for i in s:
		if s != '':
			l.append(len(i))
	for i in range(len(l)):
		if not i % 2:
			res += sorted(l, reverse=True)[i]
	print(res)


t = int(input())
while t > 0:
	str1 = input().split('0')
	count = 0
	arr = []
	for i in str1:
		if i.startswith('1'):
			arr.append(len(i))
	arr.sort(reverse=True)
	for i in range(len(arr)):
		if i % 2 == 0:
			count += arr[i]
	print(count)
	t -= 1


for _ in range(int(input())):
	a = input()
	b = a.split('0')
	b = list(filter(lambda x: len(x) > 0, b))
	b = sorted([len(i) for i in b], reverse=True)
	r = 0
	for i in range(0, len(b), 2):
		r += b[i]
	print(r)


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

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

class ostream:

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

def get_input(a=str):
	return a(input())

def get_int_input():
	return get_input(int)

def get_input_arr(a):
	return list(map(a, input().split()))

def get_int_input_arr():
	return get_input_arr(int)

def solve():
	t = get_int_input()
	for _ in range(t):
		st = get_input()
		one_len = []
		curr_len = 0
		ptr = 0
		while ptr < len(st):
			if st[ptr] == '1':
				curr_len += 1
			else:
				if curr_len > 0:
					one_len.append(curr_len)
				curr_len = 0
			ptr += 1
		if curr_len > 0:
			one_len.append(curr_len)
			curr_len = 0
		one_len.sort(reverse=True)
		res = 0
		for i in range(len(one_len)):
			if i % 2 == 0:
				res += one_len[i]
		cout << res << endl

def main():
	solve()
main()


n = int(input())
for i in range(n):
	final = []
	s = input()
	cur = j = total = 0
	while j < len(s):
		if s[j] == '1':
			cur += 1
		else:
			if cur > 0:
				final.append(cur)
			cur = 0
		j += 1
	final.append(cur)
	final.sort(reverse=True)
	for j in range(len(final)):
		if j % 2 == 0:
			total += final[j]
	print(total)


t = int(input())
for _ in range(t):
	s = input()
	a = []
	count = 0
	p = 1
	for i in range(0, len(s) - 1):
		if s[i] == '1':
			count += 1
			if s[i] != s[i + 1]:
				a.append(count)
				count = 0
	if s[-1] == '1':
		if len(s) == 1:
			a.append(1)
		elif s[-1] == s[-1]:
			count += 1
			a.append(count)
		else:
			a.append(1)
	a.sort()
	ans = 0
	for i in range(len(a) - 1, -1, -2):
		ans += a[i]
	print(ans)


def maxRepeating(str):
	n = len(str)
	count = 0
	res = str[0]
	output = []
	first = 0
	second = 0
	answer = 0
	cur_count = 1
	for i in range(n):
		if i < n - 1 and str[i] == str[i + 1]:
			cur_count += 1
		else:
			if cur_count > count:
				res = str[i]
				if i == n - 1 and str[i - 1] == '0':
					if str[i] == '1':
						output.append(1)
				elif str[i] == '1':
					output.append(cur_count)
			cur_count = 1
	output = sorted(output, reverse=True)
	if len(output) == 0:
		return 0
	else:
		for i in range(0, len(output), 2):
			first = first + output[i]
	return first
t = int(input())
for tests in range(t):
	word = input()
	print(maxRepeating(word))


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

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

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

def solve():
	ss = input()
	oc = []
	last = '0'
	for c in ss:
		if c == '1':
			if last == '0':
				oc.append(1)
			else:
				oc[-1] += 1
		last = c
	oc.sort(reverse=True)
	print(sum((c for c in oc[::2])))

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


for _ in range(int(input())):
	arr = list(input().split('0'))
	for i in arr:
		if i == '':
			arr.remove('')
	arr.sort(key=len, reverse=True)
	sum = 0
	for i in range(0, len(arr), 2):
		sum += len(arr[i])
	print(sum)


t = int(input())
for _ in range(t):
	s = input()
	co = []
	cnt = 0
	for x in s:
		if x == '1':
			cnt += 1
		else:
			co.append(cnt)
			cnt = 0
	co.append(cnt)
	co.sort(reverse=True)
	alice = 0
	for i in range(0, len(co), 2):
		alice += co[i]
	print(alice)


for i in range(int(input())):
	li = []
	x = input()
	x = list(x)
	c = 1
	coun = 0
	for j in range(len(x)):
		k = c
		if x[j] == '1':
			c = 1
			if c == 1:
				coun += 1
		else:
			c = 0
		if j == len(x) - 1:
			c = 0
			k = 1
		if k == 1 and c == 0:
			li.append(coun)
			coun = 0
	li.sort(reverse=True)
	ans = 0
	for j in range(len(li)):
		if j % 2 == 0:
			ans += li[j]
	print(ans)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

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

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def sumDigits(no):
	return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
MOD = 1000000007
PMOD = 998244353
N = 10 ** 5
T = 1
T = int(stdin.readline())
for _ in range(T):
	a = list(stdin.readline().strip('\n'))
	n = len(a)
	s = []
	c = 0
	for i in range(n):
		if a[i] == '1':
			c += 1
		else:
			s.append(c)
			c = 0
	s.append(c)
	s.sort(reverse=True)
	ans = 0
	for i in range(0, len(s), 2):
		ans += s[i]
	print(ans)


a = input()
for i in range(int(a)):
	c = list(input().split(str(0)))
	d = []
	t = 0
	for j in range(len(c)):
		d.append(len(c[j]))
	d.sort()
	for j in range(len(d) - 1, -1, -2):
		t += d[j]
	print(t)


import math
import sys
import itertools
import random
import bisect
import heapq
import collections

def lcm(x, y):
	return x * y // math.gcd(x, y)

def hcf(x, y):
	return math.gcd(x, y)

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

def primeFactors(n):
	res = []
	while n % 2 == 0:
		res.append(2)
		n //= 2
	for i in range(3, math.sqrt(n) + 1, 2):
		while n % i == 0:
			res.append(i)
			n //= i
	if n > 2:
		res.append(n)
	return res
for _ in range(0, int(input())):
	s = list(input())
	s += ['0']
	res = []
	curr = 0
	for i in s:
		if i == '1':
			curr += 1
		else:
			res.append(curr)
			curr = 0
	res.sort()
	res.reverse()
	r = 0
	for i in range(0, len(res)):
		if i % 2 == 0:
			r += res[i]
	print(r)


t = int(input())
for i in range(t):
	s = input()
	xr = []
	k = 0
	for j in range(len(s)):
		if s[j] == '1':
			k += 1
		elif k != 0:
			xr.append(k)
			k = 0
	if k != 0:
		xr.append(k)
	xr.sort(reverse=True)
	al = 0
	for y in range(0, len(xr), 2):
		al += xr[y]
	print(al)


t = int(input())
for i in range(t):
	x = input()
	arr = []
	count = 0
	for j in range(len(x)):
		if x[j] == '1':
			count += 1
		else:
			arr.append(count)
			count = 0
	arr.append(count)
	arr.sort(reverse=True)
	ans = 0
	for j in range(len(arr)):
		if j % 2 == 0:
			ans += arr[j]
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	k = 0
	l = []
	for j in range(len(s)):
		if s[j] == '1':
			k += 1
		else:
			l.append(k)
			k = 0
	if s[-1] == '1':
		l.append(k)
	l1 = list(filter(lambda a: a != 0, l))
	l1.sort(reverse=True)
	ans = 0
	for y in l1[0:len(l1):2]:
		ans += y
	print(ans)


t = int(input())
while t:
	s = input().split('0')
	s.sort(reverse=True)
	aliceScr = 0
	turn = 0
	for ele in s:
		if turn % 2 == 0:
			aliceScr += len(ele)
		turn += 1
	print(aliceScr)
	t -= 1


from sys import stdin
m = int(stdin.readline().strip())
for caso in range(m):
	s = stdin.readline().strip()
	arr = []
	c = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
		else:
			if i > 0 and s[i - 1] == '1':
				arr.append(c)
			c = 0
	if s[-1] == '1':
		arr.append(c)
	ans = 0
	arr.sort()
	arr = arr[::-1]
	for i in range(len(arr)):
		if i % 2 == 0:
			ans += arr[i]
	print(ans)


from re import split
t = int(input())
for _ in range(t):
	s = split('[0]+', input())
	s = list(map(lambda x: len(x), s))
	s.sort()
	score = 0
	for i in range(len(s) - 1, -1, -2):
		score += s.pop(i)
	print(score)


t = int(input())
for _ in range(t):
	l = input()
	leng = len(l)
	a = 0
	sw = 0
	al = 0
	bl = 0
	while '1' in l:
		if '1' * (leng - a) in l:
			if sw == 0:
				al += leng - a
				sw += 1
			else:
				bl += leng - a
				sw = 0
			l = l.replace('1' * (leng - a), '', 1)
			continue
		a += 1
	print(al)


import sys
import string
import math
from collections import defaultdict
from functools import lru_cache
from collections import Counter
from fractions import Fraction

def mi(s):
	return map(int, s.strip().split())

def lmi(s):
	return list(mi(s))

def tmi(s):
	return tuple(mi(s))

def mf(f, s):
	return map(f, s)

def lmf(f, s):
	return list(mf(f, s))

def js(lst):
	return ' '.join((str(d) for d in lst))

def jsns(lst):
	return ''.join((str(d) for d in lst))

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

def linesp():
	return line().split()

def iline():
	return int(line())

def mat(n):
	matr = []
	for _ in range(n):
		matr.append(linesp())
	return matr

def matns(n):
	mat = []
	for _ in range(n):
		mat.append([c for c in line()])
	return mat

def mati(n):
	mat = []
	for _ in range(n):
		mat.append(lmi(line()))
	return mat

def pmat(mat):
	for row in mat:
		print(js(row))

def solve(S):
	S = [(k, v) for (k, v) in Counter(map(len, S.split('0'))).items() if k != 0]
	new_S = []
	for (k, v) in S:
		new_S.extend([k] * v)
	new_S.sort(reverse=True)
	new_S = [k for (e, k) in enumerate(new_S) if e % 2 == 0]
	print(sum(new_S))

def main():
	t = iline()
	for _ in range(t):
		arr = line()
		solve(arr)
main()


T = int(input())
for t in range(T):
	B = input()
	L = []
	if B.find('1') == -1:
		print('0')
	else:
		c = 0
		for i in range(len(B)):
			if B[i] == '0':
				L.append(c)
				c = 0
			else:
				c += 1
		L.append(c)
		L.sort(reverse=True)
		ans = 0
		for i in range(len(L)):
			if i % 2 == 0:
				ans += L[i]
		print(ans)
		L.clear()


n = int(input())
for i in range(n):
	m = sorted(list(map(len, input().split('0'))), reverse=True)
	ans = 0
	number = m.count(0)
	for i in range(number):
		m.remove(0)
	for i in range(len(m)):
		if i % 2 == 0:
			ans += m[i]
	print(ans)


for _ in range(int(input())):
	s = input()
	ones = []
	cnt = 0
	for i in range(len(s)):
		if s[i] == '1':
			cnt += 1
		else:
			if cnt != 0:
				ones.append(cnt)
			cnt = 0
	if cnt != 0:
		ones.append(cnt)
	ones.sort(reverse=True)
	ans = 0
	for i in range(0, len(ones), 2):
		ans += ones[i]
	print(ans)


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


t1 = int(input())
for _ in range(t1):
	s = str(input())
	t = ''
	a = []
	for i in s:
		if i == '1':
			t += '1'
		else:
			a.append(len(t))
			t = ''
	a.append(len(t))
	a.sort()
	a.reverse()
	l = 0
	for i in range(len(a)):
		if i % 2 == 0:
			l += a[i]
	print(l)


tc = int(input())
for test in range(tc):
	A = input()
	x = []
	count = 0
	sol = 0
	for i in A:
		if i == '1':
			count += 1
		else:
			x.append(count)
			count = 0
	x.append(count)
	x = sorted(x)
	x = x[::-1]
	for i in range(0, len(x), 2):
		sol += x[i]
	print(sol)


res = []
for t in range(int(input())):
	data = list(input().split('0'))
	data.sort(key=lambda x: -len(x))
	data = data[::2]
	data = ''.join(data)
	res.append(len(data))
print(*res, sep='\n')


for _ in range(int(input())):
	s = list(map(int, list(input())))
	countlist = []
	count = 1
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			count += 1
		else:
			countlist.append(count)
			count = 1
	countlist.append(count)
	checklist = []
	if s[0] == 0:
		for i in range(1, len(countlist), 2):
			checklist.append(countlist[i])
	else:
		for i in range(0, len(countlist), 2):
			checklist.append(countlist[i])
	checklist.sort(reverse=True)
	ans = 0
	for i in range(0, len(checklist), 2):
		ans += checklist[i]
	print(ans)


import sys, math
try:
	(sys.stdin, sys.stdout) = (open('input.txt', 'r'), open('out.txt', 'w'))
except:
	pass
from sys import stdin, stdout
mod = int(1000000000.0 + 7)
from statistics import mode
from collections import *
from math import ceil, floor, inf, factorial, gcd, log2, sqrt, log
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()

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

def setbits(n):
	return bin(n).count('1')

def resetbits(n):
	return bin(n).count('0')

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r):
	(num, den) = (1, 1)
	r = min(n, n - r)
	for i in range(r):
		num *= n - i
		den *= i + 1
	return num // den

def ncr_p(n, r, p):
	(num, den) = (1, 1)
	r = min(r, n - r)
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * modinv(den, p) % p

def isPrime(num):
	if num <= 1:
		return False
	if num == 2 or n == 3:
		return True
	if num % 2 == 0 or num % 3 == 0:
		return False
	m = int(num ** 0.5) + 1
	for i in range(5, m, 6):
		if num % i == 0 or num % (i + 2) == 0:
			return False
	return True

def bin_search(arr, low, high, val):
	while low <= high:
		mid = low + (high - low) // 2
		if arr[mid] == val:
			return mid
		elif arr[mid] < val:
			low = mid + 1
		else:
			high = mid - 1
	return -1

def sumofdigit(num):
	count = 0
	while num:
		count += num % 10
		num //= 10
	return count

def inputmatrix():
	(r, c) = iia()
	mat = [0] * r
	for i in range(r):
		mat[i] = iia()
	return (r, c, mat)

def prefix_sum(n, arr):
	for i in range(1, n):
		arr[i] += arr[i - 1]
	return arr

def binomial(n, k):
	if 0 <= k <= n:
		ntok = 1
		ktok = 1
		for t in range(1, min(k, n - k) + 1):
			ntok *= n
			ktok *= t
			n -= 1
		return ntok // ktok
	else:
		return 0

def divisors(n):
	res = []
	for i in range(1, ceil(sqrt(n)) + 1):
		if n % i == 0:
			if i == n // i:
				res.append(i)
			else:
				res.append(i)
				res.append(n // i)
	return res
for _ in range(ii1()):
	s = is1()
	lis = []
	n = len(s)
	count = 0
	for i in range(n):
		if s[i] == '1':
			count += 1
		elif count > 0:
			lis.append(count)
			count = 0
	if count > 0:
		lis.append(count)
	lis.sort(reverse=True)
	ans = 0
	m = len(lis)
	for i in range(m):
		if i % 2 == 0:
			ans += lis[i]
	print(ans)


t = int(input())
while t:
	s = input()
	a = []
	cnt = 0
	for i in range(len(s)):
		if s[i] == '1':
			cnt += 1
		elif cnt > 0:
			a.append(cnt)
			cnt = 0
	if cnt > 0:
		a.append(cnt)
	a.sort(key=lambda x: -x)
	s = 0
	for i in range(len(a)):
		s += (i % 2 == 0) * a[i]
	print(s)
	t -= 1


import re
for t in range(int(input())):
	print(sum(sorted(map(len, re.findall('1+', input())), reverse=True)[::2]))


def function(s):
	k = s.split('0')
	A = []
	for z in k:
		if z != '':
			A.append(len(z))
	return A
for _ in range(int(input())):
	s = str(input())
	A = sorted(function(s))
	sumA = 0
	for i in range(len(A) - 1, -1, -2):
		sumA = sumA + A[i]
	print(sumA)


for i in range(int(input())):
	s = input() + 'z'
	l = 0
	r = 0
	z = []
	cnt = 0
	while r < len(s):
		if s[r] != '1':
			z.append(s[l:r])
			r += 1
			l = r
		else:
			r += 1
	z.sort(reverse=True)
	for i in range(len(z)):
		if not z[i]:
			break
		elif i % 2 == 0:
			cnt += len(z[i])
	print(cnt)


q = int(input())
while q > 0:
	ls = []
	s = str(input())
	i = 0
	while i < len(s):
		if s[i] == '1':
			j = i
			cnt = 0
			while j < len(s) and s[j] == '1':
				cnt += 1
				j += 1
			i = j
			ls += [cnt]
		else:
			i += 1
	ls.sort()
	i = len(ls) - 1
	ans = 0
	while i >= 0:
		ans += ls[i]
		i -= 2
	print(ans)
	q -= 1


for _ in range(int(input())):
	s = str(input())
	arr = []
	i = 0
	n = len(s)
	while i < len(s):
		if s[i] == '1':
			count = 0
			while i < n and s[i] == '1':
				count += 1
				i += 1
			arr.append(count)
		i += 1
	arr.sort(reverse=True)
	ans = 0
	for i in range(0, len(arr), 2):
		ans += arr[i]
	print(ans)


for _ in range(int(input())):
	s = list(input())
	s.append('0')
	a = []
	x = -1
	for i in range(len(s)):
		if s[i] == '1':
			x = i
			break
	if x == -1:
		print(0)
		continue
	u = 1
	c = 1
	for i in range(x + 1, len(s)):
		if s[i] == '1' and u == 1:
			c += 1
		if s[i] == '0' and u == 1:
			u = 0
			a.append(c)
		if s[i] == '1' and u == 0:
			u = 1
			c = 1
	a.sort(reverse=True)
	v = 0
	for i in range(0, len(a), 2):
		v += a[i]
	print(v)


t = int(input())
for _ in range(t):
	s = list(map(lambda x: int(x), input()))
	array = []
	soma = 0
	for i in s:
		if i == 0 and soma > 0:
			array.append(soma)
			soma = 0
		elif i == 1:
			soma += 1
	if soma > 0:
		array.append(soma)
	array.sort(reverse=True)
	result = 0
	for j in range(0, len(array), 2):
		result += array[j]
	print(result)


board = ''

def findTest():
	global board
	if board.count('1') == 0:
		return -1
	ones = board.split('0')
	longest = max(ones, key=len)
	ones.remove(longest)
	board = '0'.join(ones)
	return len(longest)
for i in range(int(input())):
	board = input()
	scores = [0, 0]
	turn = 0
	while not turn == -1:
		find = findTest()
		if find == -1:
			turn = -1
		else:
			scores[turn] += find
		if turn > -1:
			turn = not turn
	print(scores[0])


t = 1
t = int(input())
while t:
	t -= 1
	s = input()
	ones = []
	cont = 0
	for el in s:
		if el == '1':
			cont += 1
		else:
			if cont:
				ones.append(cont)
			cont = 0
	if cont:
		ones.append(cont)
	ones.sort(reverse=True)
	ans = 0
	for i in range(0, len(ones), 2):
		ans += ones[i]
	print(ans)


def solve(s):
	n = len(s)
	arr = []
	c = 0
	for i in s:
		if i == '0':
			if c > 0:
				arr.append(c)
			c = 0
		else:
			c += 1
	if c > 0:
		arr.append(c)
	arr.sort(reverse=True)
	i = 0
	ans = 0
	while i < len(arr):
		ans += arr[i]
		i += 2
	return ans
t = int(input())
while t:
	s = input()
	print(solve(s))
	t -= 1


for i in range(int(input())):
	n = input()
	A = 0
	for p in range(len(n)):
		maxk = 0
		k = 0
		m = 0
		for j in range(len(n)):
			if n[j] == '1':
				k += 1
				m = 1
			elif m == 1:
				if maxk < k:
					maxk = k
				k = 0
				m = 0
			try:
				b = n[j + 1]
			except IndexError:
				if maxk < k:
					maxk = k
		if p % 2 != 1:
			A += maxk
		n = n.replace('1' * maxk, '', 1)
		if '1' not in n:
			break
	print(A)


def processo(seq):
	l = splitNew(seq, '0')
	l.sort(reverse=True)
	i = 0
	n = len(l)
	out = 0
	while True:
		if i >= n:
			break
		out += len(l[i])
		i += 2
	return out

def splitNew(seq, x):
	y = ''
	l = []
	n = len(seq)
	for i in range(n):
		if seq[i] == x:
			if y != '':
				l.append(y)
				y = ''
		else:
			if i == n - 1:
				y += seq[i]
				l.append(y)
			y += seq[i]
	return l
n = int(input())
for k in range(n):
	seq = str(input())
	print(processo(seq))


from sys import stdin, stdout
test = int(stdin.readline())
for _ in range(test):
	s = list(stdin.readline().strip())
	s = [int(x) for x in s]
	cnt = 1
	temp = []
	for i in range(len(s) - 1):
		if not s[i] ^ s[i + 1]:
			if s[i] == 1:
				cnt += 1
		elif s[i] == 1:
			temp.append(cnt)
			cnt = 1
	if s[-1] == 1:
		temp.append(cnt)
	temp.sort(reverse=True)
	sm = 0
	for i in range(0, len(temp), 2):
		sm += temp[i]
	print(sm)


import sys, math
input = lambda : sys.stdin.readline().rstrip()
for i in range(int(input())):
	s = input()
	mas = []
	c = 0
	k = len(s)
	cur = 0
	while c < k:
		if s[c] == '1':
			cur += 1
		elif cur != 0:
			mas.append(cur)
			cur = 0
		c += 1
	if cur != 0:
		mas.append(cur)
		cur = 0
	if len(mas) == 0:
		print(0)
	else:
		mas = sorted(mas)
		mas = mas[::-1]
		ans = 0
		for i in range(len(mas)):
			if i % 2 == 0:
				ans += mas[i]
		print(ans)


for _ in range(int(input())):
	s = input().split('0')
	c = 0
	s = sorted(s, reverse=True, key=lambda x: len(x))
	for i in range(len(s)):
		if i % 2 == 0:
			c += len(s[i])
	print(c)


from sys import *

def resolve(t):
	string = str(stdin.readline().rstrip())
	arr = string.split('0')
	arr.sort(key=len)
	arr.reverse()
	result = 0
	i = 0
	for sub in arr:
		if i % 2 == 0:
			result = result + len(sub)
		i = i + 1
	print(result)
T = int(stdin.readline().rstrip())
for t in range(T):
	resolve(t)


def convert(s):
	chars = []
	for char in s:
		chars.append(char)
	substrings = []
	while chars != []:
		last = chars.pop()
		substring = last
		while chars != []:
			if chars[-1] == last:
				chars.pop()
				substring = substring + last
			else:
				break
		substrings.append(substring)
	ones = []
	for s in substrings:
		if '1' in s:
			ones.append(len(s))
	ones = sorted(ones, reverse=True)
	total = 0
	i = 0
	while 2 * i <= len(ones) - 1:
		total += ones[2 * i]
		i += 1
	return total
T = int(input())
for i in range(T):
	print(convert(input()))


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 IF(c, t, f):
	return t if c else f

def main():
	t = I()
	rr = []
	for _ in range(t):
		s = S()
		t = []
		u = 0
		for c in s:
			if c == '0':
				if u > 0:
					t.append(u)
				u = 0
			else:
				u += 1
		if u > 0:
			t.append(u)
		t = sorted(t, reverse=True)
		rr.append(sum(t[::2]))
	return JA(rr, '\n')
print(main())


for _ in range(int(input())):
	st = input()
	b = st.split('0')
	a = []
	al = 0
	for item in b:
		a.append(len(item))
	a.sort()
	a = a[::-1]
	for i in range(0, len(a), 2):
		al += a[i]
	print(al)


t = int(input())
for _ in range(t):
	s = input()
	block = []
	start = False
	count = 0
	for char in s:
		if char == '1':
			count += 1
			start = True
		elif start:
			block.append(count)
			start = False
			count = 0
	if start:
		block.append(count)
	block.sort(reverse=True)
	ans = 0
	for i in range(0, len(block), 2):
		ans += block[i]
	print(ans)


t = int(input())
for _ in range(t):
	n = list(input())
	li = list()
	c = 0
	i = 0
	p = len(n)
	fg0 = 1
	fg1 = 1
	for i in range(p):
		if n[i] == '1':
			c += 1
		if n[i] == '0' or i == p - 1:
			li.append(c)
			c = 0
	li.sort()
	li.reverse()
	z = 0
	m = 0
	while m < len(li):
		z += li[m]
		m += 2
	print(z)


for _ in range(int(input())):
	s = input()
	count = 0
	lis = []
	for i in range(len(s)):
		if s[i] == '1':
			count += 1
		else:
			lis.append(count)
			count = 0
	if s[-1] == '1':
		lis.append(count)
	lis.sort(reverse=True)
	sumo = 0
	for i in range(0, len(lis), 2):
		sumo += lis[i]
	print(sumo)


for t in range(int(input())):
	k = tuple(input().split('0'))
	k = sorted(k, reverse=True)
	a = 0
	for i in range(len(k)):
		if i & 1 == 0:
			a += len(k[i])
	print(a)


for _ in range(int(input())):
	n = list(input())
	l = []
	c = 0
	for i in range(len(n)):
		if n[i] == '1':
			c += 1
		else:
			l.append(c)
			c = 0
	if c != 0:
		l.append(c)
	l.sort()
	c = d = 0
	for i in range(len(l)):
		if i % 2 == 0:
			c += l[i]
		else:
			d += l[i]
	print(max(c, d))


for _ in range(int(input())):
	s = input()
	d = 0
	t = 0
	ans = [0, 0]
	n = len(s)
	while d == 0:
		d = 1
		mex = 0
		i = -1
		j = -1
		l = 0
		r = 0
		while l < n:
			while l < n and s[l] == '0':
				l += 1
			r = l
			while r + 1 < n and s[r + 1] == '1':
				r += 1
			if r < n and r - l + 1 > mex:
				mex = r - l + 1
				i = l
				j = r
				d = 0
			l = r + 1
		ans[t] += mex
		temp = ''
		for k in range(i):
			temp += s[k]
		for k in range(j + 1, n):
			temp += s[k]
		s = temp
		n = len(s)
		t = t ^ 1
	print(ans[0])


from sys import stdout, stdin

def substring_removal(string):
	save = []
	count = 0
	for i in range(len(string)):
		if string[i] == '1':
			count += 1
		elif count != 0:
			save += [count]
			count = 0
	if count != 0:
		save += [count]
	save.sort(reverse=True)
	res = 0
	for i in range(0, len(save), 2):
		res += save[i]
	return res
t = int(stdin.readline().replace('\n', ''))
results = []
for i in range(t):
	string = stdin.readline().replace('\n', '')
	results += [substring_removal(string)]
for r in results:
	print(r)


t = int(input())
for _ in range(t):
	s = input()
	counts = []
	islands = s.split('0')
	for island in islands:
		if len(island) == 0:
			continue
		counts.append(len(island))
	counts.sort()
	total = 0
	for i in range(len(counts) - 1, -1, -2):
		total += counts[i]
	print(total)


t = int(input())
while t > 0:
	s = input()
	newS = ''
	last = ''
	for i in range(len(s)):
		if s[i] != last or s[i] == '1':
			newS += s[i]
			last = s[i]
	s = newS
	ones = []
	count = 0
	for i in range(len(s)):
		if s[i] == '0' and count > 0:
			ones.append(count)
			count = 0
		elif s[i] == '1':
			count += 1
	if count > 0:
		ones.append(count)
	ones.sort(reverse=True)
	ans = 0
	(oddSum, evenSum) = (0, 0)
	for i in range(len(ones)):
		if i % 2 == 0:
			ans += ones[i]
	print(ans)
	t -= 1


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	s = [x for x in input().strip('\n').split('0') if x]
	s.sort(reverse=True)
	print(sum((len(j) for (i, j) in enumerate(s) if i % 2 == 0)))


from collections import Counter
import heapq
from collections import Counter
for _ in range(int(input())):
	s = input()
	ls = []
	cnt = 0
	for i in range(len(s)):
		if s[i] == '1':
			cnt += 1
		else:
			ls.append(cnt)
			cnt = 0
		if i == len(s) - 1 and s[i] == '1':
			ls.append(cnt)
	ls.sort()
	ls = ls[::-1]
	f = 0
	ans = 0
	for i in ls:
		if f == 0:
			ans += i
			f = 1
		else:
			f = 0
	print(ans)


def main():
	t = int(input())
	for _ in range(t):
		s = input()
		score = []
		j = 0
		while j < len(s):
			k = 0
			if s[j] == '1':
				while j < len(s) and s[j] == '1':
					k += 1
					j += 1
				score.append(k)
			j += 1
		if len(score) == 0:
			print(0)
		else:
			score.sort(reverse=True)
			out = 0
			for i in range((len(score) + 1) // 2):
				out += score[2 * i]
			print(out)
main()


for _ in range(int(input())):
	s = input()
	lst = []
	i = 0
	count = 0
	while i < len(s):
		if s[i] == '0':
			if count > 0:
				lst.append(count)
			count = 0
		else:
			count += 1
		i += 1
	if count > 0:
		lst.append(count)
	lst.sort(reverse=True)
	A = 0
	B = 0
	for i in range(len(lst)):
		if i % 2 == 0:
			A += lst[i]
		else:
			B += lst[i]
	print(max(A, B))


t = int(input())
for i in range(t):
	s = input()
	l = []
	a = 0
	for x in s:
		if x == '1':
			a += 1
		else:
			if a != 0:
				l.append(a)
			a = 0
	if a != 0:
		l.append(a)
	l.sort(reverse=True)
	print(sum(l[::2]))


import io
import os
import sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def prdbg(*args, **kwargs):
	print(*args, **kwargs)
	pass

def get_str():
	return input().decode().strip()

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

def oint():
	return int(input())
t = oint()
for _ in range(t):
	s = get_str()
	s += '0'
	cnt = 0
	one = []
	for i in range(len(s)):
		if s[i] == '1':
			cnt += 1
		else:
			one.append(cnt)
			cnt = 0
	one.sort(reverse=True)
	ans = 0
	for i in range(len(one)):
		if i % 2 == 0:
			ans += one[i]
	print(ans)


a = int(input())
for i in range(0, a):
	n = input()
	d = []
	y = 0
	c = 0
	for i in range(0, len(n)):
		if n[i] == '1':
			c = c + 1
			y = 1
		elif y == 1:
			d.append(c)
			y = 0
			c = 0
	if c != 0:
		d.append(c)
	i = len(d) - 1
	g = 0
	d.sort()
	while i >= 0:
		g = g + d[i]
		i = i - 2
	print(g)


import re

def solve(s):
	alice = 0
	if s.count('1') == len(s):
		return len(s)
	if s.count('0') == len(s):
		return 0
	turn = 1
	the_ones = re.findall('1+', s)
	for i in range(len(the_ones)):
		if turn == 1:
			m = max(the_ones, key=len)
			alice = alice + len(m)
			the_ones.remove(m)
			turn = 0
		else:
			m = max(the_ones, key=len)
			the_ones.remove(m)
			turn = 1
	return alice
t = int(input())
for i in range(t):
	s = input()
	print(solve(s))


T = int(input())

def solve():
	str = input()
	lst = []
	comp = 0
	for i in range(len(str)):
		if i > 0 and str[i] == '0' and (str[i - 1] == '1'):
			lst.append(comp)
			comp = 0
		if str[i] == '1':
			comp = comp + 1
	if comp > 0:
		lst.append(comp)
	lst.sort(reverse=True)
	print(sum(lst[::2]))
for t in range(T):
	solve()


for _ in ' ' * int(input()):
	lst = []
	s = input().split('0')
	for i in s:
		if i != '':
			lst.append(int(i))
	lst.sort()
	lst = lst[::-1]
	cnt = 0
	for i in range(len(lst)):
		if i % 2 == 0:
			cnt += len(str(lst[i]))
	print(cnt)


for _ in range(int(input())):
	ones = sorted(input().split('0'), reverse=True)
	alice = 0
	for i in range(0, len(ones), 2):
		if ones[i] != '':
			alice += len(ones[i])
		else:
			break
	print(alice)


import math
import sys

def dict_sort(ans):
	ans = sorted(ans.items(), reverse=True, key=lambda kv: kv[1])

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

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

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

def alphbates():
	return 'abcdefghijklmnopqrstuvwxyz'

def binary_search(ls, n, flag):
	low = 0
	hi = n - 1
	while low <= hi:
		mid = (low + hi) // 2
		if ls[mid] == flag:
			return mid
		elif ls[mid] > flag:
			hi = mid - 1
		else:
			low = mid + 1
	return -1

def inp():
	ls = list(map(int, input().split()))
	return ls

def mult_inp():
	return map(int, input().split())
t = int(input())
for _i in range(t):
	s = input()
	n1 = 0
	ls = []
	for i in range(len(s)):
		if s[i] == '0':
			if n1 > 0:
				ls.append(n1)
			n1 = 0
		else:
			n1 += 1
	if n1 > 0:
		ls.append(n1)
		n1 = 0
	ans = 0
	ls.sort(reverse=True)
	for i in range(len(ls)):
		if i % 2 == 0:
			ans += ls[i]
	print(ans)


def findScore(s):
	i = 0
	ones = []
	while i < len(s):
		c = 0
		while i < len(s) and s[i] == '1':
			c += 1
			i += 1
		if c:
			ones.append(c)
		i += 1
	ones.sort(reverse=True)
	score = 0
	for i in range(len(ones)):
		if i % 2 == 0:
			score += ones[i]
	return score
t = int(input())
for i in range(t):
	s = input()
	print(findScore(s))


T = int(input())
r = ''
for i in range(T):
	s = []
	s = input().split('0')
	s.sort()
	for j in range(s.count('')):
		s.remove('')
	k = 0
	for j in range(len(s) - 1, -1, -2):
		k += len(s[j])
	r += str(k) + '\n'
print(r)


T = int(input())
for I in range(0, T):
	X = input().split('0')
	Array = []
	for J in X:
		if J != '':
			Array.append(len(J))
	Array = sorted(Array)
	Sum = 0
	for J in Array[-1::-2]:
		Sum += J
	print(Sum)


import sys
from itertools import groupby
N = int(input())
for _ in range(N):
	s = sys.stdin.readline().rstrip()
	one = sorted((len(list(v)) for (k, v) in groupby(s) if k == '1'), reverse=True)
	print(sum(one[::2]))


def alice_score(s):
	points = []
	current = 0
	for letter in s:
		if letter == '0':
			if current != 0:
				points.append(current)
			current = 0
		else:
			current += 1
	if current > 0:
		points.append(current)
	points.sort(reverse=True)
	return sum(points[::2])
for _ in range(int(input())):
	s = input()
	print(alice_score(s))


n = int(input())
for i in range(n):
	a = str(input())
	b = a.split('0')
	c = 0
	d = [0] * len(b)
	for j in range(len(b)):
		d[j] = len(b[j])
	d.sort(reverse=True)
	for j in range(len(d)):
		if j % 2 == 0:
			c += d[j]
	print(c)


import sys
input = sys.stdin.readline

def prog():
	for _ in range(int(input())):
		s = input().strip() + '0'
		ones = []
		last = -1
		for i in range(len(s) - 1):
			if s[i] == '0' and s[i + 1] == '1':
				last = i
			if s[i] == '1' and s[i + 1] == '0':
				ones.append(i - last)
		ones.sort(reverse=True)
		ans = 0
		for i in range(0, len(ones), 2):
			ans += ones[i]
		print(ans)
prog()


for _ in range(int(input())):
	s = input()
	ans = []
	z = 0
	while z < len(s):
		if s[z] == '0':
			z += 1
		else:
			f = 0
			while z < len(s):
				if s[z] == '1':
					f += 1
					z += 1
					if z == len(s):
						ans.append(f)
				else:
					ans.append(f)
					break
	score = 0
	ans.sort(reverse=True)
	for z in range(0, len(ans), 2):
		score += ans[z]
	print(score)


query = int(input())
somador = 0
array = []
for x in range(query):
	jogo = list(map(int, input()))
	jogo.append(0)
	saida = 0
	pula = False
	for i in range(len(jogo)):
		if jogo[i] == 0 and somador > 0:
			array.append(somador)
			somador = 0
		elif jogo[i] == 1:
			somador += 1
	array.sort(reverse=True)
	for k in range(len(array)):
		if not pula:
			saida += array[k]
			pula = True
		else:
			pula = False
	print(saida)
	array.clear()


from sys import stdin

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

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

def linput():
	return list(map(int, stdin.readline().split()))
from math import ceil
t = iinput()
while t:
	t -= 1
	s = input()
	block = []
	i = 0
	temp = 0
	while i < len(s):
		if s[i] == '1':
			temp += 1
		else:
			if temp:
				block.append(temp)
			temp = 0
		i += 1
	block.append(temp)
	block.sort(reverse=True)
	print(sum(block[::2]))


cases = int(input())
for _ in range(cases):
	high_points = sorted(list(map(lambda num: len(num), input().split('0'))), reverse=True)
	points = 0
	for i in range(len(high_points)):
		if i % 2 != 0:
			continue
		points += high_points[i]
	print(points)


t = int(input())
for xxx in range(t):
	s = input()
	arr = s.split('0')
	arr2 = [len(pp) for pp in arr]
	arr2 = sorted(arr2, reverse=True)
	sum = 0
	for i in range(len(arr2)):
		if i % 2 == 0:
			sum += arr2[i]
	print(sum)


def readn():
	return int(input())

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

def readnos():
	return map(int, input().split())
t = readn()
for _ in range(t):
	s1 = input()
	n = len(s1)
	s = []
	for i in range(n):
		s.append(s1[i])
	c = []
	i = 0
	while i < n:
		if s[i] == '0':
			i += 1
		else:
			j = i
			while i < n and s[i] == '1':
				i += 1
			c.append(i - j)
		if i >= n:
			break
	c.sort(reverse=True)
	ans = 0
	for i in range(0, len(c), 2):
		ans += c[i]
	print(ans)


t = int(input())
for i in range(t):
	s = list(input())
	n = len(s)
	l = []
	count = 0
	for j in range(0, n + 1):
		if j == n:
			if count != 0:
				l.append(count)
		elif s[j] == '0':
			if count != 0:
				l.append(count)
			count = 0
		elif s[j] == '1':
			count += 1
	l.sort(reverse=True)
	tot = 0
	for j in range(0, len(l), 2):
		tot += l[j]
	print(tot)


import os
os_input = os.read(0, int(10000000.0)).split()
os_input_pos = -1
answer_list = []

def read_s():
	global os_input_pos
	os_input_pos += 1
	return os_input[os_input_pos].decode()

def read_i():
	return int(read_s())

def write_s(v):
	answer_list.append(v)

def write_i(v):
	write_s(str(v))

def print_ans():
	os.write(1, '\n'.join(answer_list).encode())
	os.write(1, '\n'.encode())
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)
			else:
				stack.pop()
				if not stack:
					break
				to = stack[-1].send(to)
		return to
	return wrapped_func
from itertools import groupby
T = read_i()
while T:
	T -= 1
	s = read_s()
	cnt = sorted([len(list(g)) for (k, g) in groupby(s) if k == '1'])
	write_i(sum(cnt[-1::-2]))
print_ans()


from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	a = stdin.readline()
	a = a[:-1]
	lis = [0]
	for i in a:
		if i == '1':
			lis[-1] += 1
		elif lis[-1] > 0:
			lis.append(0)
	lis.sort()
	lis.reverse()
	print(sum(lis[0:len(lis):2]))


def process():
	s = input()
	flag = 0
	a = []
	c = 0
	for i in s:
		if i == '1':
			c += 1
		else:
			a.append(c)
			c = 0
	if c != 0:
		a.append(c)
	a.sort(reverse=True)
	ans = 0
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)
tests = int(input())
for i in range(tests):
	process()


t = int(input())
for ii in range(t):
	s = input()
	a = []
	c = 0
	for i in s:
		if i == '1':
			c += 1
		else:
			if c != 0:
				a.append(c)
			c = 0
	if c != 0:
		a.append(c)
	a.sort(reverse=True)
	val = 0
	i = 0
	while i < len(a):
		val += a[i]
		i += 2
	print(val)


def solve(arr):
	temp = []
	n = len(arr)
	i = 0
	while i < n:
		if arr[i] == '1':
			count = 0
			while i < n and arr[i] == '1':
				count += 1
				i += 1
			temp.append(count)
		else:
			i += 1
	temp = sorted(temp, reverse=True)
	n = len(temp)
	res = 0
	for i in range(0, n, 2):
		res += temp[i]
	return res
t = int(input())
for _ in range(t):
	s = input()
	print(solve(s))


for _ in range(int(input())):
	s = input()
	ones = []
	c = 0
	for (i, v) in enumerate(s):
		if v == '1':
			c += 1
		if v == '0' and c:
			ones.append(c)
			c = 0
	if c:
		ones.append(c)
	ones.sort()
	i = len(ones) - 1
	s = 0
	while i >= 0:
		s += ones[i]
		i -= 2
	print(s)


n = int(input())
for i in range(n):
	cadena = [len(x) for x in input().split('0')]
	for i in cadena:
		if i == 0:
			cadena.remove(i)
	cadena.sort()
	alice = 0
	bob = 0
	for i in range(len(cadena) - 1, -1, -2):
		alice += cadena[i]
	for i in range(len(cadena) - 2, -1, -2):
		bob += cadena[i]
	print(alice)


test_cases = int(input())
for _ in range(test_cases):
	s = list(map(str, input().split('0')))
	s.sort(reverse=True)
	for i in s:
		if i == '':
			s.remove(i)
	length = len(s)
	count = 0
	for j in range(length):
		if j % 2 == 0:
			count += s[j].count('1')
	print(count)


n = int(input())
for k in range(n):
	s = input().split('0')
	tam = []
	for e in s:
		tam.append(len(e))
	tam = sorted(tam, reverse=True)
	soma = 0
	for (i, e) in enumerate(tam):
		if i % 2 == 0:
			soma += e
	print(soma)


for t in range(int(input())):
	a = input('')
	b = []
	x = 0
	for i in range(len(a)):
		if a[i] == '1':
			x += 1
		if a[i] == '0':
			if x != 0:
				b.append(x)
			x = 0
	if x != 0:
		b.append(x)
	b.sort()
	s = 0
	for i in range(len(b) - 1, -1, -2):
		s += b[i]
	print(s)


s = int(input())
for i in range(s):
	store = input()
	no_ones = 0
	one = [None]
	for j in store:
		if j == '1':
			no_ones += 1
	temp = 0
	for j in range(len(store)):
		if store[j] == '1':
			temp += 1
		else:
			one.append(temp)
			temp = 0
	if temp:
		one.append(temp)
	one = one[1:]
	one.sort(reverse=True)
	print(sum(one[::2]))


from itertools import groupby
t = int(input())
n = []
for i in range(t):
	z = int(input())
	n.append(z)

def calc(x):
	arr = [int(d) for d in str(x)]
	score = 0
	res = [list(y) for (x, y) in groupby(arr)]
	alice = 1
	while len(res) >= 1:
		large = {'value': 0, 'index': 0}
		for (idx, x) in enumerate(res):
			if x[0] == 1:
				if large['value'] < len(x):
					large['value'] = len(x)
					large['index'] = idx
		res.pop(large['index'])
		res = [j for i in res for j in i]
		res = [list(y) for (x, y) in groupby(res)]
		if alice == 1:
			alice = 0
			score += large['value']
		else:
			alice = 1
	print(score)
for x in n:
	calc(x)


t = int(input())
for i in range(t):
	s = list(input())
	a = []
	n = len(s)
	j = 0
	while j < n:
		x = 0
		if s[j] == '1':
			y = j + 1
			for k in range(j, n):
				y = k + 1
				if s[k] == '0':
					y = k + 1
					break
				else:
					x += 1
			a.append(x)
			j = y
		else:
			j += 1
	a.sort(reverse=True)
	s = 0
	j = 0
	while j < len(a):
		s += a[j]
		j += 2
	print(s)


t = int(input())
for i in range(t):
	s = input()
	a = []
	c = 0
	for j in s:
		if j == '1':
			c += 1
		if j == '0':
			if c > 0:
				a.append(c)
				c = 0
	if c > 0:
		a.append(c)
	a.sort(reverse=True)
	print(sum(a[::2]))


t = int(input())
s = []
for i in range(t):
	s.append(str(input()))
for j in range(t):
	ones = []
	c = 0
	for j in s[j]:
		if j == '1':
			c += 1
		else:
			ones.append(c)
			c = 0
	ones.append(c)
	onesort = sorted(ones, reverse=True)
	print(sum(onesort[0::2]))


results = []
tests = int(input())
for _x in range(tests):
	a = input() + '0'
	onesSequance = []
	ones = 0
	for x in a:
		if x == '1':
			ones += 1
		elif x == '0' and ones != 0:
			onesSequance.append(ones)
			ones = 0
	onesSequance.sort(reverse=True)
	tempScore = 0
	for x in range(0, len(onesSequance), 2):
		tempScore += onesSequance[x]
	results.append(tempScore)
print(*results, sep='\n')


def s(a):
	flag = 0
	g = []
	v = 0
	c = 0
	x = ''
	z = 1
	s = 0
	m = 0
	l = []
	for i in range(0, len(a)):
		l.append(a[i])
	while True:
		for j in range(0, len(l)):
			if l[j] == '1':
				for k in range(j, len(l)):
					if l[k] == '1':
						flag = flag + 1
					if l[k] == '0':
						break
				g.append([j, flag])
				flag = 0
			else:
				m = m + 1
		if m == len(l):
			a = ''
		else:
			for (f, r) in g:
				if r > v:
					v = r
					c = f
			for p in range(0, v):
				del l[c]
			x = ''
			c = 0
			if z % 2 != 0:
				s = s + v
		v = 0
		c = 0
		z = z + 1
		g = []
		if a == '':
			break
		m = 0
	return s
o = input()
h = []
for t in range(0, int(o)):
	e = input()
	h.append(e)
for q in h:
	print(s(q))


t = int(input())
for o in range(t):
	a = list(map(int, input()))
	x = []
	cnt = 0
	for i in range(len(a)):
		if a[i] == 0:
			x.append(cnt)
			cnt = 0
			f = 1
		else:
			cnt += 1
			f = 0
	if f == 0:
		x.append(cnt)
	ans = 0
	x.sort()
	x = x[::-1]
	for i in range(len(x)):
		if i % 2 == 0:
			ans += x[i]
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	scores = []
	count = 0
	n = len(s)
	for j in range(n):
		if s[j] == '1':
			if j < n - 1 and s[j + 1] == '1':
				count += 1
			else:
				scores.append(count + 1)
				count = 0
	aliceScore = 0
	n = len(scores)
	scores.sort(reverse=True)
	for j in range(0, n, 2):
		aliceScore += scores[j]
	print(aliceScore)


for _ in range(int(input())):
	string = input()
	arr = []
	cnt = 0
	for i in range(0, len(string)):
		if string[i] == '1':
			cnt += 1
		elif cnt > 0:
			arr.append(cnt)
			cnt = 0
	if cnt > 0:
		arr.append(cnt)
	arr.sort(reverse=True)
	score = 0
	for i in range(0, len(arr), 2):
		score += arr[i]
	print(score)


import sys
input = sys.stdin.readline
from heapq import *
t = int(input())
for _ in range(t):
	lis = list(map(int, input().strip()))
	i = 0
	ans = []
	while i < len(lis):
		if lis[i] == 1:
			v = i
			while i < len(lis) and lis[i] == 1:
				i += 1
			vv = i - 1
			ans.append(vv - v + 1)
		i += 1
	ans.sort(reverse=True)
	print(sum(ans[::2]))


t = int(input())
for i in range(t):
	s = input()
	ones = s.split('0')
	ones2 = []
	for o in ones:
		if len(o) > 0:
			ones2.append(len(o))
	ones2.sort(reverse=True)
	ans = 0
	for i in range(len(ones2)):
		if i % 2 == 0:
			ans += ones2[i]
	print(ans)


for i in range(int(input())):
	s = input()
	l = []
	j = 0
	while j < len(s):
		if s[j] == '1':
			k = j
			while k + 1 < len(s) and s[k + 1] == '1':
				k += 1
			l.append(k - j + 1)
			j = k
		j += 1
	l.sort(reverse=True)
	s2 = 0
	for i in range(0, len(l), 2):
		s2 += l[i]
	print(s2)


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


for t in range(int(input())):
	s = input().strip()
	re = [0]
	cu = 0
	l = '.'
	for c in s:
		if c == l:
			cu += 1
		else:
			if l == '1':
				re.append(cu)
			l = c
			cu = 1
	if l == '1':
		re.append(cu)
	re.sort(reverse=True)
	print(sum(re[::2]))


def find_remove(bin_string):
	subs = []
	cnt = 0
	sum_alice = 0
	for ind in range(len(bin_string)):
		if bin_string[ind] == '1':
			cnt += 1
		if bin_string[ind] == '0' or ind == len(bin_string) - 1:
			subs.append(cnt)
			cnt = 0
	subs.sort(reverse=True)
	for i in range(0, len(subs), 2):
		sum_alice += subs[i]
	return sum_alice
t = int(input())
for case in range(t):
	s = input()
	print(find_remove(s))


from itertools import groupby as gb

def solve(n):
	array = [int(d) for d in str(n)]
	out = 0
	ans = [list(y) for (x, y) in gb(array)]
	a = 1
	while len(ans) >= 1:
		l = {'value': 0, 'index': 0}
		for (idx, x) in enumerate(ans):
			if x[0] == 1:
				if l['value'] < len(x):
					l['value'] = len(x)
					l['index'] = idx
		ans.pop(l['index'])
		ans = [j for i in ans for j in i]
		ans = [list(y) for (x, y) in gb(ans)]
		if a == 1:
			a = 0
			out += l['value']
		else:
			a = 1
	print(out)
t = int(input())
for i in range(t):
	n = int(input())
	solve(n)


testcases = int(input())
for testcase in range(testcases):
	strs = input()
	countconseq1 = []
	alice = 0
	bob = 0
	count1 = 0
	for i in strs:
		if i == '0' and count1 == 0:
			continue
		if i == '1':
			count1 += 1
		else:
			countconseq1.append(count1)
			count1 = 0
	if count1 > 0:
		countconseq1.append(count1)
	countconseq1 = sorted(countconseq1)
	countconseq1 = countconseq1[::-1]
	nn = len(countconseq1)
	for i in range(0, nn, 2):
		alice += countconseq1[i]
	print(alice)


PI = 3.141592653589793
INF = float('inf')
MOD = 1000000007

def add(x, y):
	return (x + y) % MOD

def sub(x, y):
	return (x - y + MOD) % MOD

def mul(x, y):
	return x * y % MOD

def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)

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

def power(x, y):
	res = 1
	x %= MOD
	while y != 0:
		if y & 1:
			res = mul(res, x)
		y >>= 1
		x = mul(x, x)
	return res

def mod_inv(n):
	return power(n, MOD - 2)

def prob(p, q):
	return mul(p, power(q, MOD - 2))

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

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

def ls():
	return [i for i in input().split()]
for t in range(ii()):
	t += 1
	s = input()
	n = len(s)
	store = []
	cnt = 0
	for i in s:
		if i == '1':
			cnt += 1
		else:
			store.append(cnt)
			cnt = 0
	store.append(cnt)
	store.sort()
	store.reverse()
	ans = 0
	for i in range(0, len(store), 2):
		ans += store[i]
	print(ans)


def i1():
	return int(input())

def s1():
	return input().rstrip()

def redir(s):
	import sys
	sys.stdin = open(sys.argv[0] + f'/../in-{s}.txt')
t = i1()
for _ in range(t):
	s = s1()
	prev = '0'
	cnt = []
	cont = 0
	for ch in s:
		if ch == '1':
			cont += 1
		elif cont > 0:
			cnt.append(cont)
			cont = 0
	if cont > 0:
		cnt.append(cont)
	score = sum(sorted(cnt, reverse=True)[::2])
	print(score)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(str(n))
	res = [0] * len(l)
	count = 0
	result = 0
	for i in range(len(l) - 1):
		if l[i] == l[i + 1] and l[i] == '1':
			count += 1
		elif l[i] == '1':
			res[i] = count + 1
			count = 0
	if l[-1] == '1':
		res[-1] = count + 1
	res.sort(reverse=True)
	for i in range(0, len(res), 2):
		result += res[i]
	print(result)


t = int(input())

def solve(s):
	a = list(map(len, s.split('0')))
	a.sort(reverse=True)
	return sum(a[::2])
for _ in range(t):
	s = input()
	print(solve(s))


tc = int(input())
for _ in range(tc):
	s = input()
	res = []
	count = 0
	l = s.split('0')
	while '' in l:
		l.remove('')
	for x in l:
		res.append(len(x))
	res.sort(reverse=True)
	for i in range(0, len(res), 2):
		count += res[i]
	print(count)


for _ in range(int(input())):
	st = list(input())
	st.append('0')
	c = 0
	ans = []
	for i in range(len(st)):
		if st[i] == '1':
			c += 1
		else:
			ans.append(c)
			c = 0
	ans = sorted(ans, reverse=True)
	a = 0
	for i in range(0, len(ans), 2):
		a += ans[i]
	print(a)


t = int(input(''))
for i in range(0, t):
	s = input('')
	r = 0
	l = list(s.split('0'))
	for j in range(0, len(l)):
		y = max(l)
		r = r + y.count('1')
		l[l.index(y)] = ''
		l[l.index(max(l))] = ''
	print(r)


for _ in range(int(input())):
	n = input()
	lst = []
	c1 = 0
	n1 = len(n)
	for i in range(0, n1):
		if n[i] == '1':
			c1 += 1
		elif c1 >= 1:
			lst.append(c1)
			c1 = 0
	lst.append(c1)
	lst.sort(reverse=True)
	ans = 0
	for i in range(0, len(lst), 2):
		ans += lst[i]
	print(ans)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	ones = []
	s = [int(x) for x in input()]
	c = 0
	for x in range(len(s)):
		if s[x]:
			c += 1
		else:
			if c:
				ones.append(c)
			c = 0
	if c:
		ones.append(c)
	ans = 0
	ones.sort(reverse=True)
	for x in range(len(ones)):
		if x % 2 == 0:
			ans += ones[x]
	print(ans)


for testcases in range(int(input())):
	a = input()
	count = 0
	ans = []
	for i in range(len(a)):
		if a[i] == '1':
			count += 1
		else:
			if count > 0:
				ans.append(count)
			count = 0
	if count > 0:
		ans.append(count)
	ans.sort(reverse=True)
	anis = 0
	if len(ans) % 2 == 0:
		for i in range(int(len(ans) / 2)):
			anis += ans[2 * i]
	else:
		for i in range(len(ans) // 2 + 1):
			anis += ans[2 * i]
	print(anis)


n = int(input())
for i in range(n):
	s = input()
	k = 0
	l = []
	for x in s:
		if x == '0':
			if k > 0:
				l.append(k)
				k = 0
		else:
			k += 1
	if k > 0:
		l.append(k)
	ans = 0
	l = sorted(l, reverse=True)
	for j in range(0, len(l), 2):
		ans += l[j]
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	arr = []
	temp = 0
	for i in range(len(s)):
		if s[i] == '1':
			temp += 1
		else:
			arr.append(temp)
			temp = 0
	arr.append(temp)
	arr = sorted(arr, reverse=True)
	ans = 0
	for i in range(0, len(arr), 2):
		ans += arr[i]
	print(ans)


for _ in range(int(input())):
	s = input()
	co = 0
	num = []
	for i in s:
		if i == '1':
			co += 1
		else:
			num.append(co)
			co = 0
	if co != 0:
		num.append(co)
	num.sort()
	num.reverse()
	ca = 0
	k = 0
	for i in num:
		if k % 2 == 0:
			ca += i
		k += 1
	print(ca)


def solve(s):
	a = []
	cnt = 0
	for i in range(len(s)):
		if s[i] == '1':
			cnt += 1
		else:
			a.append(cnt)
			cnt = 0
	if s[-1] == '1':
		a.append(cnt)
	a.sort(reverse=True)
	ans = 0
	for i in range(0, len(a), 2):
		ans += a[i]
	return ans
t = int(input())
for i in range(t):
	s = input()
	print(solve(s))


T = int(input())
for _ in range(T):
	arr = list(map(int, list(input())))
	i = 0
	n = len(arr)
	ls = []
	while i < n:
		curr = arr[i]
		if curr == 1:
			count = 1
			while i + 1 < n and arr[i + 1] == curr:
				i += 1
				count += 1
			ls.append(count)
		i += 1
	ls.sort(reverse=True)
	alice = 0
	bob = 0
	for i in range(len(ls)):
		if i % 2 == 0:
			alice += ls[i]
		else:
			bob += ls[i]
	print(alice)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = input().strip('\n')
	s = list(s)
	s = [int(i) for i in s]
	s.append(0)
	i = 0
	ans = 0
	start = -1
	while any(s):
		i += 1
		con = []
		for x in range(len(s)):
			if s[x] == 1 and start == -1:
				start = x
			if s[x] == 0 and start != -1:
				con.append((start, x - 1, x - start))
				start = -1
		con.sort(key=lambda x: x[2])
		(a, b, c) = con[-1]
		s = s[:a] + s[b + 1:]
		if i % 2:
			ans += c
	print(ans)


num = int(input())
for i in range(num):
	ans = 0
	s = input()
	a = s.split('0')
	arr = []
	for each in a:
		if '1' in each:
			arr.append(len(each))
	arr.sort(reverse=True)
	for i in range(len(arr)):
		if i % 2 == 0:
			ans += arr[i]
	print(ans)


def ans(a):
	ones = []
	count = 0
	for i in a:
		if i == '1':
			count += 1
		else:
			if count != 0:
				ones.append(count)
			count = 0
	if count != 0:
		ones.append(count)
	if ones == []:
		return 0
	ones.sort()
	ones.reverse()
	i = 0
	ans = 0
	while i < len(ones):
		ans += ones[i]
		i += 2
	return ans
m = int(input())
for i in range(m):
	arr = input()
	print(ans(arr))


for _ in range(int(input())):
	s = input()
	n = len(s)
	i = 0
	prev = 0
	count = 0
	arr = []
	while i < n:
		if s[i] == '1':
			if prev == 0:
				prev = 1
			count += 1
		elif prev == 1:
			arr.append(count)
			count = 0
			prev = 0
		i += 1
	arr.append(count)
	arr.sort(reverse=True)
	i = 0
	alice = 0
	while i < len(arr):
		if i % 2 == 0:
			alice += arr[i]
		i += 1
	print(alice)


t = int(input())
for i in range(t):
	new = sorted([len(i) for i in input().split('0')], reverse=True)
	print(sum(new[::2]))


for _ in range(int(input())):
	ans = 0
	q = []
	m = 0
	s = input()
	for j in range(len(s)):
		if s[j] == '0':
			q.append(m)
			m = 0
		elif j == len(s) - 1:
			q.append(m + 1)
		else:
			m += 1
	q.sort(reverse=True)
	for i in q[::2]:
		ans += i
	if ans < 0:
		print(0)
	elif s.count('1') == len(s):
		print(s.count('1'))
	else:
		print(ans)


import sys

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

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

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

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
for _ in range(iinput()):
	arr = list(input())
	ans = []
	n = len(arr)
	i = 0
	while i < n:
		if arr[i] == '0':
			i += 1
		else:
			l = 0
			while i < n and arr[i] == '1':
				i += 1
				l += 1
			ans.append(l)
	ans.sort(reverse=True)
	res = 0
	for i in range(0, len(ans), 2):
		res += ans[i]
	print(res)


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

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

def S_():
	return input()

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

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

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

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

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

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

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

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

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

def RA():
	return map(int, open(0).read().split())

def RLI(n=8, a=1, b=10):
	return [random.randint(a, b) for i in range(n)]

def RI(a=1, b=10):
	return random.randint(a, b)

def Rtest(T):
	(case, err) = (0, 0)
	for i in range(T):
		inp = INP()
		(a1, ls) = naive(*inp)
		a2 = solve(*inp)
		if a1 != a2:
			print((a1, a2), inp)
			err += 1
		case += 1
	print('Tested', case, 'case with', err, 'errors')

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

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

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()
show_flg = False
show_flg = True
ans = 0
for _ in range(I()):
	s = S_()
	t = sorted([len(list(g)) for (k, g) in groupby(s) if k == '1'])
	a = 0
	while t:
		a += t.pop()
		if t:
			t.pop()
	print(a)


def solve(string):
	s = string.split('0')
	string = sorted(s, reverse=True)
	count = 0
	for i in range(0, len(string), 2):
		count += len(string[i])
	print(count)
for _ in range(int(input())):
	string = input()
	solve(string)


for _ in range(int(input())):
	str1 = input()
	n = len(str1)
	temp = []
	cnt = 0
	if str1[0] == '1':
		cnt += 1
	for i in range(1, n):
		if str1[i] == '1':
			cnt += 1
		elif cnt != 0:
			temp.append(cnt)
			cnt = 0
	if cnt != 0:
		temp.append(cnt)
	temp.sort(reverse=True)
	if len(temp) == 0:
		print(0)
	else:
		summ = 0
		for i in range(0, len(temp)):
			if i % 2 == 0:
				summ += temp[i]
		print(summ)


T = int(input())
for _ in range(T):
	st = input()
	counts = [int(st[0])]
	for i in range(1, len(st)):
		if st[i] == '0':
			if counts[-1] != 0:
				counts.append(0)
		elif st[i] == '1':
			if counts[-1] != 0:
				counts[-1] += 1
			else:
				counts.append(1)
	a = 0
	while counts:
		a += max(counts)
		counts.remove(max(counts))
		if counts:
			counts.remove(max(counts))
	print(a)


t = int(input())
for i in range(t):
	s = input()
	(soma, j) = (0, 0)
	somas = []
	while True:
		if j >= len(s):
			if soma != 0:
				somas.append(soma)
			break
		while j < len(s) and s[j] == '1':
			soma += 1
			j += 1
		if j < len(s) and s[j] == '0':
			if soma != 0:
				somas.append(soma)
				soma = 0
			j += 1
	somas = sorted(somas, reverse=True)
	(j, pontos) = (0, 0)
	for j in range(0, len(somas), 2):
		pontos += somas[j]
	print(pontos)


for _ in range(int(input())):
	ans = 0
	x = [0]
	s = input()
	f = 1
	for i in s:
		if i == '1':
			if f:
				f = 0
				x.append(1)
			else:
				x[-1] += 1
		else:
			f = 1
	x.sort()
	x = x[1:]
	x = x[::-1]
	for i in range(0, len(x), 2):
		ans += x[i]
	print(ans)


t = int(input())
lst = []
for i in range(t):
	s = list(input())
	lst.append(s)
for s in lst:
	cnt_lst = []
	cnt = 0
	for i in range(len(s)):
		if s[i] == '1':
			cnt += 1
			if i == len(s) - 1:
				cnt_lst.append(cnt)
		elif s[i] == '0':
			cnt_lst.append(cnt)
			cnt = 0
	cnt_lst = sorted(cnt_lst)[::-1]
	ans = 0
	for i in range(len(cnt_lst)):
		if i % 2 == 0:
			ans += cnt_lst[i]
	print(ans)


for _ in range(int(input())):
	b = input()
	count = 1
	result = list()
	pre = b[0]
	if len(b) == 1:
		if pre == '1':
			result.append(1)
		else:
			result.append(0)
	for i in range(1, len(b)):
		if b[i] == '1':
			if pre == '1':
				count = count + 1
			else:
				count = 1
		else:
			if pre == '1':
				result.append(count)
			count = 0
		if i == len(b) - 1:
			result.append(count)
		pre = b[i]
	alice = 0
	bob = 0
	result.sort(reverse=True)
	for j in range(len(result)):
		if j % 2 == 0:
			alice = alice + result[j]
		else:
			bob = bob + result[j]
	print(alice)


for _ in range(int(input())):
	s = '0' + input() + '0'
	(n, t) = (0, False)
	ll = [0]
	for x in s:
		if x == '1':
			if t:
				n += 1
			else:
				t = True
				n = 1
		elif t:
			t = False
			ll.append(n)
			n = 0
	ll.sort()
	ll.reverse()
	sol = 0
	for i in range(len(ll)):
		if i % 2 == 0:
			sol += ll[i]
	print(sol)


from queue import PriorityQueue
t = int(input())
for i in range(t):
	S = str(input()) + '0'
	H = PriorityQueue()
	count = False
	x = 0
	k = 0
	for j in range(len(S)):
		s = int(S[j])
		if count:
			if s == 1:
				x -= 1
			if s == 0:
				count = False
				H.put(x)
				k += 1
				x = 0
		elif s == 1:
			count = True
			x -= 1
		else:
			continue
	A = 0
	B = 0
	for y in range(k):
		if y % 2 == 0:
			A += H.get()
		else:
			B += H.get()
	print(-A)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

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():
	for t in range(I()):
		lis = []
		s = input()
		v = s.find('0')
		n = len(s)
		if v == -1:
			print(n)
		else:
			if v > 0:
				lis.append(v)
			for i in range(v + 1, n):
				if s[i] == '0':
					if i - v - 1 != 0:
						lis.append(i - v - 1)
					v = i
			if n - v - 1 != 0:
				lis.append(n - v - 1)
			val = sorted(lis, reverse=True)
			sm = 0
			for i in range(0, len(lis), 2):
				sm += val[i]
			print(sm)
main()


from bisect import bisect_left, bisect_right
from itertools import combinations
from itertools import permutations
from bisect import bisect_left
from math import ceil
from math import radians
from heapq import heapify, heappush, heappop
import bisect
from math import pi
from collections import deque
from math import factorial
from math import log, ceil
from collections import defaultdict
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 li1():
	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 and i % 2 == 1:
			s.add(i)
			n = n // i
	if n > 2 and n % 2 == 1:
		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

def readTree(n):
	adj = [set() for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		adj[u - 1].add(v - 1)
		adj[v - 1].add(u - 1)
	return adj

def treeOrderByDepth(n, adj, root=0):
	parent = [-2] + [-1] * (n - 1)
	ordered = []
	q = deque()
	q.append(root)
	depth = [0] * n
	while q:
		c = q.popleft()
		ordered.append(c)
		for a in adj[c]:
			if parent[a] == -1:
				parent[a] = c
				depth[a] = depth[c] + 1
				q.append(a)
	return (ordered, parent, depth)

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def nextPowerOf2(n):
	count = 0
	if n and (not n & n - 1):
		return n
	while n != 0:
		n >>= 1
		count += 1
	return 1 << count

def cou(n):
	c = 0
	while n > 1:
		c += 1
		n //= 2
	return c

def sortsec(l):
	return sorted(l, key=lambda x: x[1])

def BinarySearch(a, x):
	i = bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def subarray(A):
	r = set()
	p = {0}
	for x in A:
		p = {x | y for y in p} | {x}
		r |= p
	return len(r)
for _ in range(ii()):
	s = list(si().split('0'))
	count = 0
	for i in s:
		if i == '':
			s.remove('')
	s = sorted(s)[::-1]
	for i in range(0, len(s), 2):
		count += len(s[i])
	print(count)


t = int(input())
for _ in range(t):
	s = input()
	new = []
	sums = 0
	array = s.split('0')
	for i in range(len(array)):
		new.append(len(list(array[i])))
	new.sort(reverse=True)
	for i in range(0, len(new), 2):
		sums = sums + new[i]
	print(sums)


def my_sum(lista):
	soma = 0
	for i in range(0, len(lista), 2):
		soma += lista[i]
	return soma
quant_testes = int(input())
for i in range(quant_testes):
	seq = input()
	lista = list()
	soma_atual = 0
	for char in seq:
		if char == '1':
			soma_atual += 1
		elif char == '0' and soma_atual != 0:
			lista.append(soma_atual)
			soma_atual = 0
	if soma_atual > 0:
		lista.append(soma_atual)
	lista.sort(reverse=True)
	print(my_sum(lista))


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, Counter
import math

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

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

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

def stringIn():
	return stdin.readline().strip()
t = intIn()
while t > 0:
	t -= 1
	s = stringIn()
	di = defaultdict(str)
	n = len(s)
	li = []
	cnt = 0
	for i in range(n):
		if s[i] == '1':
			cnt += 1
		else:
			if cnt != 0:
				li.append(cnt)
			cnt = 0
	if cnt != 0:
		li.append(cnt)
	ans = 0
	li.sort(reverse=True)
	for i in range(0, len(li), 2):
		ans += li[i]
	print(ans)


for y in range(int(input())):
	a = input()
	b = a.split('0')
	c = sorted(b, reverse=True)
	x = '1'
	for i in range(0, len(c), 2):
		x = x + c[i]
	print(len(x) - 1)


t = int(input())
for _ in range(t):
	s = input()
	l = []
	lp = len(s)
	i = 0
	while i < lp:
		c = 0
		if i < len(s) and s[i] == '1':
			while i < len(s) and s[i] == '1':
				c += 1
				i += 1
			l.append(c)
		else:
			i += 1
	l.sort(reverse=True)
	ans = 0
	bb = 98
	nu = len(l)
	for i in range(nu):
		if i % 2 != 1:
			ans += l[i]
	print(ans - 98 + bb)


def main():
	for _ in range(int(input())):
		print(sum(sorted(map(len, input().split('0')))[::-2]))
main()


from collections import defaultdict
from math import *
import os
import sys
from io import BytesIO, IOBase
from heapq import nlargest
from bisect import *
import copy
import itertools
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def input():
	return sys.stdin.readline().rstrip('\r\n')
t = int(input())
while t:
	t -= 1
	s = input()
	arr = list(s)
	check = []
	isavailable = True
	while len(arr) > 0 and isavailable:
		count = 0
		ans = 0
		pos = -1
		test = True
		for i in range(len(arr)):
			if arr[i] == '1':
				count += 1
				test = False
			else:
				count = 0
			if ans < count:
				ans = count
				pos = i
		check.append(ans)
		if test:
			break
		else:
			arr = arr[0:pos - ans + 1] + arr[pos + 1:]
	pr = 0
	for i in range(len(check)):
		if i % 2 == 0:
			pr += check[i]
	print(pr)


t = int(input())
while t > 0:
	t = t - 1
	s = input()
	l = 0
	a = []
	i = 0
	while i < len(s):
		if s[i] == '1':
			k = 0
			while s[i] == '1' and i < len(s) - 1:
				i += 1
				k += 1
			a.append(k)
			if i >= len(s):
				break
		i += 1
	if s[-1] == '1':
		a[-1] = a[-1] + 1
	a.sort(reverse=True)
	d = 0
	for i in range(0, len(a), 2):
		d += a[i]
	print(d)


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


t = int(input())
while t > 0:
	su = 0
	s = input()
	n = len(s)
	l = []
	i = 0
	while i < n:
		if s[i] == '1':
			count = 1
			if i + 1 != n:
				while s[i] == s[i + 1]:
					i += 1
					count += 1
					if i + 1 == n:
						break
			l.append(count)
		i += 1
	l.sort(reverse=True)
	for j in range(len(l)):
		if j % 2 == 0:
			su += l[j]
	print(su)
	t -= 1


for i in range(int(input())):
	binary_digit = str(input())
	score = 0
	scores = []
	j = 0
	output = 0
	while j < len(binary_digit):
		if binary_digit[j] == '0':
			scores.append(score)
			score = 0
			j += 1
		else:
			score += 1
			j += 1
	scores.append(score)
	scores = sorted(scores)
	scores.reverse()
	for d in range(0, len(scores), 2):
		output += scores[d]
	print(output)


testes = int(input())
respostas = []
for _ in range(testes):
	jogadas = list(filter(None, sorted(input().split('0'), reverse=True)))
	soma = 0
	for x in range(0, len(jogadas), 2):
		soma += len(jogadas[x])
	respostas.append(soma)
for elem in respostas:
	print(elem)


tc = int(input())
for t in range(tc):
	s = input()
	c = 0
	li = []
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
		elif s[i] == '0':
			li.append(c)
			c = 0
	if s[len(s) - 1] == '1':
		li.append(c)
	li.sort()
	li.reverse()
	total = 0
	for i in range(0, len(li), 2):
		total = total + li[i]
	print(total)


import time
from collections import deque

def inpt():
	return int(input())

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

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

def solve():
	s = input()
	l = sorted([i.count('1') for i in list(s.split('0'))])[::-1]
	print(sum(l[::2]))

def main():
	m = 10 ** 9 + 7
	t = int(input())
	while t:
		t -= 1
		solve()
main()


def func(lst):
	global index
	max_rep = 0
	for i in range(len(lst)):
		rep = 0
		if lst[i] == 1:
			j = i
			while lst[j] != 0:
				rep += 1
				j += 1
				if j == len(lst):
					break
			if rep > max_rep:
				max_rep = rep
				index = i
	return (max_rep, index)
t = int(input())
while t != 0:
	s = list(map(int, [c for c in input()]))
	alice_score = 0
	while sum(s) != 0:
		(max_rep, idx) = func(s)
		alice_score += max_rep
		del s[idx:idx + max_rep]
		(max_rep, idx) = func(s)
		del s[idx:idx + max_rep]
	print(alice_score)
	t = t - 1


import sys
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def slv(S):
	p = 'a'
	pi = -1
	s = []
	for (i, c) in enumerate(S):
		if c == p:
			pass
		else:
			s.append((i - pi, p))
			pi = i
			p = c
	else:
		s.append((i - pi + 1, p))
		pi = i
		p = c
	s = list(filter(lambda x: x[1] == '1', s))
	s.sort()
	a = 0
	b = 0
	while s:
		a += s.pop()[0]
		if s:
			b += s.pop()[0]
	return a

def main():
	for _ in range(read_int()):
		S = read_str()
		print(slv(S))
main()


for _ in range(int(input())):
	s = input()
	l = list(s.split('0'))
	i = 0
	while i < len(l):
		if l[i] == '':
			del l[i]
			i -= 1
		i += 1
	l = [int(x) for x in l]
	alcie = 0
	while len(l) != 0:
		a = max(l)
		alcie += len(str(a))
		l.remove(a)
		if len(l) != 0:
			a = max(l)
			l.remove(a)
	print(alcie)


t = int(input())
for _ in range(t):
	s = input()
	dictionary = {}
	n = len(s)
	str_list = []
	x = ''
	for (i, e) in enumerate(s):
		if e == '1':
			x += '1'
			if i == n - 1:
				if x not in dictionary:
					dictionary[x] = 1
					str_list.append(x)
				else:
					dictionary[x] += 1
		elif i != 0 and len(x) != 0:
			if x not in dictionary:
				dictionary[x] = 1
				str_list.append(x)
			else:
				dictionary[x] += 1
			x = ''
	str_list.sort(reverse=True)
	alice = 0
	str_len = len(str_list)
	contingency = True
	while str_len:
		p = str_list[0]
		if dictionary[p] == 0:
			str_list.pop(0)
			str_len -= 1
			if str_len:
				p = str_list[0]
			else:
				break
		if contingency:
			alice += len(p)
			dictionary[p] -= 1
			contingency = False
		else:
			dictionary[p] -= 1
			contingency = True
	print(alice)


t = int(input())
l = []
for i in range(t):
	s = input()
	l.append(s)
for j in l:
	s = 0
	l2 = []
	for k in range(len(j) - 1):
		if j[k] == '1':
			s += 1
			if j[k + 1] == '0':
				l2.append(s)
				s = 0
	if j[-1] == '1':
		l2.append(s + 1)
	l2.sort()
	y = l2[::-1]
	ans = 0
	for n in range(0, len(y), 2):
		ans += y[n]
	print(ans)


import sys

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

def input_split():
	return [int(i) for i in input().split()]
testCases = int(input())
answers = []
for _ in range(testCases):
	s = input()
	groups = []
	current = 0
	for a in s:
		if a == '0':
			if current != 0:
				groups.append(current)
				current = 0
		else:
			current += 1
	if current != 0:
		groups.append(current)
	groups.sort()
	groups.reverse()
	ans = 0
	for i in range((len(groups) + 1) // 2):
		ans += groups[2 * i]
	answers.append(ans)
print(*answers, sep='\n')


def solution(nums):
	alice = 0
	segments = [0]
	index = 0
	one = False
	for c in nums:
		if c == 1:
			one = True
			segments[index] += 1
		else:
			if one:
				segments.append(0)
				index += 1
			one = False
	segments = sorted(segments, reverse=True)
	alice = sum(segments[::2])
	return alice
tests = int(input().strip())
for _ in range(tests):
	nums = list(map(int, list(input().strip())))
	print(solution(nums))


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def solve():
	a = input().strip()
	ans = []
	c = 0
	n = len(a)
	for i in range(n):
		if a[i] == '1':
			c += 1
		else:
			if c:
				ans.append(c)
			c = 0
	if c:
		ans.append(c)
	ans.sort(reverse=True)
	s = 0
	for i in range(0, len(ans), 2):
		s += ans[i]
	print(s)
for _ in range(I()):
	solve()


t = int(input())
for i in range(t):
	n = input()
	start = 0
	z = []
	check = 0
	length = 0
	c = 0
	for i in range(1, len(n) + 1):
		if set(n[start:i]) == {'1'}:
			length = len(n[start:i])
			if i == len(n):
				z.append(length)
		else:
			start = i
			if length > 0:
				z.append(length)
				length = 0
	l1 = sorted(z)
	l1 = l1[::-1]
	if len(l1) <= 0:
		print(0)
	else:
		print(sum(l1[::2]))


import string
t = int(input())
for _ in range(t):
	s = input()
	l = []
	one_started = False
	count = 0
	for i in range(len(s)):
		if one_started == False and s[i] == '1':
			one_started = True
			count += 1
		elif one_started == True and s[i] == '1':
			count += 1
		elif one_started == True and s[i] == '0':
			l.append(count)
			count = 0
	if one_started == True:
		l.append(count)
	l.sort()
	l.reverse()
	ans = 0
	for i in range(len(l)):
		if i % 2 == 0:
			ans += l[i]
	print(ans)


for _ in range(int(input())):
	s = input()
	l = []
	c = 0
	for x in s:
		if x == '0':
			l.append(c)
			c = 0
			continue
		c += 1
	l.append(c)
	l = sorted(l, reverse=True)
	ls = [l[i] for i in range(len(l)) if i % 2 == 0]
	print(sum(ls))


from audioop import reverse
t = int(input())
for case in range(t):
	s = input()
	ones = 0
	ans = []
	rslt = 0
	101010101
	if not '1' in s:
		print(0)
		continue
	for i in s:
		if i == '1':
			ones += 1
		else:
			ans.append(ones)
			ones = 0
			continue
	ans.append(ones)
	ans.sort(reverse=True)
	if len(ans) % 2 == 0:
		for i in range(0, len(ans) - 1, 2):
			rslt += ans[i]
	else:
		for i in range(0, len(ans), 2):
			rslt += ans[i]
	print(rslt)


for _ in range(int(input().strip())):
	inp = input().strip()
	i = 0
	ans = []
	temp = ''
	while i < len(inp):
		if inp[i] == '1':
			temp += '1'
		else:
			if temp != '':
				ans.append(temp)
			temp = ''
		i += 1
	if temp != '':
		ans.append(temp)
	ans.sort(reverse=True)
	co = 0
	for j in range(0, len(ans), 2):
		co += len(ans[j])
	print(str(co))


t = int(input())
while t:
	t -= 1
	s = input()
	n = len(s)
	i = 0
	l = []
	curr = 0
	while i < n:
		if s[i] == '1':
			curr += 1
		elif curr != 0:
			l.append(curr)
			curr = 0
		i += 1
	if curr != 0:
		l.append(curr)
	l.sort(reverse=True)
	ans = 0
	i = 0
	while i < len(l):
		ans += l[i]
		i += 2
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	arr1 = []
	now = -1
	prev = s[0]
	if prev == '1':
		counter = 1
	else:
		counter = 0
	for j in range(1, len(s)):
		now = s[j]
		if prev == '1' and now == '1':
			counter += 1
		elif prev == '1' and now == '0':
			arr1.append(counter)
			counter = 0
			prev = now
		elif prev == '0' and now == '0':
			pass
		elif prev == '0' and now == '1':
			counter = 1
			prev = now
	arr1.append(counter)
	arr1.sort(reverse=True)
	count = 0
	for j in range(len(arr1)):
		if j % 2 == 0:
			count += arr1[j]
	print(count)


def B():
	s = list(input().split('0'))
	s.sort(key=len, reverse=True)
	n = len(s)
	x = s[0]
	if x == '':
		return 0
	if n < 2:
		return len(x)
	for i in range(2, n, 2):
		x = x + s[i]
	return len(x)
t = int(input())
for i in range(t):
	ans = B()
	print(ans)


import sys
import math

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

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

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

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	s = SI()
	a = []
	count = 0
	for i in range(len(s)):
		if s[i] == '1':
			count += 1
		else:
			a.append(count)
			count = 0
	a.append(count)
	a.sort(reverse=True)
	print(sum(a[0:len(a):2]))


import sys
input = sys.stdin.readline
T = int(input())
for t in range(T):
	s = input()[:-1]
	counts = []
	current = 0
	for c in s:
		if c == '1':
			current += 1
		else:
			counts.append(current)
			current = 0
	if current:
		counts.append(current)
	res = 0
	counts = sorted(counts, reverse=True)
	for i in range(len(counts)):
		if 2 * i >= len(counts):
			break
		res += counts[2 * i]
	print(res)


for _ in range(int(input())):
	string = str(input())
	tamanho_das_sequencias = []
	for sequencia in string.split('0'):
		if sequencia:
			tamanho_das_sequencias.append(len(sequencia))
	tamanho_das_sequencias.sort(reverse=True)
	pontuacao_alice = 0
	for i in range(len(tamanho_das_sequencias)):
		if i % 2 == 0:
			pontuacao_alice += tamanho_das_sequencias[i]
	print(pontuacao_alice)


try:
	for _ in range(int(input())):
		s = input()
		arr = []
		tmp = ''
		for i in s:
			if i == '1':
				tmp += i
			elif tmp:
				arr.append(tmp)
				tmp = ''
		if tmp:
			arr.append(tmp)
		arr.sort(reverse=True)
		c = 0
		if not arr:
			print(0)
		else:
			for i in range(0, len(arr), 2):
				c += len(arr[i])
			print(c)
except EOFError:
	pass


t = int(input())
for i in range(t):
	bin_str = input()
	count = 0
	arr = []
	for ch in bin_str:
		if ch == '1':
			count += 1
		else:
			if count > 0:
				arr.append(count)
			count = 0
	if count > 0:
		arr.append(count)
	count = 0
	arr.sort(reverse=True)
	score = 0
	for i in range(0, len(arr), 2):
		score += arr[i]
	print(score)


def cons(lst1):
	len1 = 0
	ans = 0
	idx = -10
	for k in range(len(lst1)):
		if lst1[k] == 1:
			len1 += 1
		else:
			if ans < len1:
				idx = k - 1
				ans = len1
			len1 = 0
	if ans < len1:
		ans = len1
		idx = len(lst1) - 1
	return [ans, idx]
t = int(input())
for i in range(t):
	s = list(map(int, list(input())))
	a = 0
	ans1 = 0
	while 1:
		lst1 = cons(s)
		if lst1[1] == -10:
			break
		k = lst1[1] - lst1[0] + 1
		for j in range(lst1[0]):
			s.pop(k)
			j += 1
		if a % 2 == 0:
			ans1 += lst1[0]
		a += 1
	print(ans1)


t = int(input())
for _ in range(t):
	s = input()
	count = 0
	a = []
	for c in s:
		if c == '1':
			count += 1
		else:
			a.append(count)
			count = 0
	if count > 0:
		a.append(count)
	a.sort(reverse=True)
	r = 0
	for i in range(len(a)):
		if i % 2 == 0:
			r += a[i]
	print(r)


import itertools
for _ in range(int(input())):
	s = str(input())
	x = itertools.groupby(s)
	l = []
	for (k, d) in x:
		if k == '1':
			l.append(len(list(d)))
	l.sort(reverse=True)
	sum1 = 0
	for x in range(len(l)):
		if x % 2 == 0:
			sum1 += l[x]
	print(sum1)


t = int(input())
for _ in range(t):
	s = input()
	arr = []
	flag = 0
	this = 0
	for i in range(len(s)):
		if s[i] == '0' and flag == 1:
			arr.append(this)
			this = 0
			flag = 0
			continue
		elif s[i] == '1' and flag == 0:
			flag = 1
			this = 1
			continue
		elif s[i] == '1' and flag == 1:
			this += 1
			continue
	if this > 0:
		arr.append(this)
	arr.sort(reverse=True)
	ans = 0
	for i in range(len(arr)):
		if i % 2 == 0:
			ans += arr[i]
	print(ans)


for test in range(int(input())):
	st = input() + '0'
	lt = []
	c = 0
	for i in st:
		if i == '1':
			c += 1
		elif c > 0 and i == '0':
			lt.append(c)
			c = 0
	lt = sorted(lt, reverse=True)
	ans = 0
	for j in range(0, len(lt), 2):
		ans += lt[j]
	print(ans)


t = int(input())
for i in range(t):
	m = input()
	a = 0
	b = 0
	r = list()
	z = ''
	for i in m:
		if i == '0':
			r.append(z)
			z = ''
		if i == '1':
			z += i
	r.append(z)
	for i in r:
		if i == '':
			r.remove(i)
	for i in range(len(r)):
		r[i] = len(r[i])
	r.sort(reverse=True)
	for i in range(len(r)):
		if i % 2 == 0:
			a += r[i]
	print(a)


for _ in range(int(input())):
	s = input()
	score = 0
	turn = 1
	while s.count('1') != 0:
		x = '1' * len(s)
		z = len(s)
		while x not in s:
			z = z - 1
			x = '1' * z
		if x in s and x != '':
			if turn % 2:
				score += len(x)
			s = s.replace(x, '', 1)
		turn += 1
	print(score)


from decimal import *
getcontext().prec = 16
from math import sqrt

def countmaxone(string):
	actual = False
	first_index = 0
	actual_index = 0
	count = 0
	best_first = 0
	best_end = 0
	best_count = 0
	for i in range(len(string)):
		if string[i] == '1':
			if actual:
				actual_index += 1
				count += 1
			else:
				actual_index = i
				first_index = i
				actual = True
				count = 1
		elif string[i] == '0':
			if actual:
				actual = False
				if count > best_count:
					best_first = first_index
					best_end = actual_index
					best_count = count
		if string[i] == '1' and i == len(string) - 1:
			if count > best_count:
				best_first = first_index
				best_end = actual_index
				best_count = count
	return (best_count, string[:best_first] + string[best_end + 1:])
t = int(input())
answer = []
for test in range(t):
	string = input()
	alice = 0
	bob = 0
	while '1' in string:
		(tempo, string) = countmaxone(string)
		alice += tempo
		(bob, string) = countmaxone(string)
	answer.append(str(alice))
print('\n'.join(answer))


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	s = inp()
	a = []
	start = 0
	ans = 0
	for i in range(1, len(s)):
		if s[i] != s[i - 1]:
			if s[i - 1] == '1':
				a.append(i - start)
			start = i
	if s[-1] == '1':
		a.append(len(s) - start)
	a.sort(reverse=True)
	for i in range(len(a)):
		if i % 2 == 0:
			ans += a[i]
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for t1 in range(t):
	s = input()
	s = s.strip()
	l = []
	n = len(s)
	if s[0] == '1':
		l.append(1)
	for i in range(1, n):
		if s[i] == s[i - 1] and s[i] == '1':
			l[-1] += 1
		elif s[i] != s[i - 1] and s[i] == '1':
			l.append(1)
	l.sort()
	l = l[::-1]
	ans = 0
	for i in range(0, len(l), 2):
		ans += l[i]
	print(ans)


for _ in range(int(input())):

	def fun(s):
		return max(map(len, s.split('0')))
	s = input()
	a = 0
	b = 0
	c = []
	if '1' not in s:
		print(0)
	elif '0' not in s:
		print(len(s))
	else:
		while '1' in s:
			x = fun(s)
			a += x
			s = s.replace('1' * x, '', 1)
			y = fun(s)
			b += y
			s = s.replace('1' * y, '', 1)
		print(a)


t = int(input())
for _ in range(t):
	s = list(input())
	s.append('0')
	n = len(s)
	for i in range(len(s)):
		if s[i] == '1':
			break
	l = []
	c = 0
	for j in range(i, n):
		if s[j] == '1':
			c += 1
		else:
			l.append(c)
			c = 0
	co = 0
	l.sort(reverse=True)
	for i in range(len(l)):
		if i % 2 == 0:
			co += l[i]
	print(co)


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

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

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

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

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

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

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

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

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

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

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
t = int(inp())
for _ in range(t):
	s = inp()
	count = []
	temp = 0
	for i in range(len(s) - 1):
		if s[i] == '1' and s[i + 1] == '0':
			count.append(temp + 1)
			temp = 0
		elif s[i] == '1':
			temp += 1
	if s[-1] == '1':
		temp += 1
	count.append(temp)
	count.sort(reverse=True)
	ans = 0
	for i in range(0, len(count), 2):
		ans += count[i]
	print(ans)


query = int(input())
for i in range(query):
	str = input()
	length = len(str)
	new_str_arr = []
	j = 0
	while j < length:
		new_str = ''
		if str[j] == '1':
			k = j
			while k < length:
				if str[k] != '1':
					j = k
					if new_str != '':
						new_str_arr.append(new_str)
						new_str = ''
					break
				else:
					new_str += str[k]
				k += 1
		j += 1
	if new_str != '':
		new_str_arr.append(new_str)
	if str[length - 1] == '1':
		new_str_arr.pop(len(new_str_arr) - 1)
	count = 0
	for j in range(length - 1, -1, -1):
		if str[j] == '1':
			count += 1
		else:
			break
	new_str_arr.append('1' * count)
	ans = 0
	new_str_arr.sort(key=len, reverse=True)
	for j in range(len(new_str_arr)):
		if j % 2 == 0:
			ans += len(new_str_arr[j])
	print(ans)


t = int(input())

def max_sub(s, a):
	ind = 0
	global_l = 0
	local_l = 0
	for j in range(len(s)):
		if s[j] == a:
			local_l += 1
		else:
			local_l = 0
		if local_l > global_l:
			ind = j
		global_l = max(global_l, local_l)
	return (ind, global_l)
for i in range(t):
	arr = list(input())
	n = len(arr)
	flag = 1
	alice = 0
	bob = 0
	if arr.count('0') == n:
		print(0)
	elif arr.count('1') == n:
		print(n)
	else:
		while n > 0:
			typ = 1
			(ind, count) = max_sub(arr, '1')
			if count == 0:
				typ = 0
				(ind, count) = max_sub(arr, '0')
			if flag and typ == 1:
				alice += count
			elif not flag and typ == 1:
				bob += count
			flag = not flag
			del arr[ind - count + 1:ind + 1]
			n = len(arr)
		print(alice)


for _ in range(int(input())):
	s = input()
	l = s.split('0')
	l.sort(reverse=True)
	su = 0
	for (j, i) in enumerate(l):
		if j % 2 == 0:
			su += len(i)
	print(su)


for _ in range(int(input())):
	p = input().split('0')
	l = []
	if p == []:
		print(0)
	else:
		for i in p:
			l.append(len(i))
	q = sorted(l, reverse=True)
	c = 0
	for i in range(0, len(q), 2):
		c += q[i]
	print(c)


n = int(input())
for i in range(n):
	tmp_str = input()
	arr = []
	tmp = 0
	for i in range(len(tmp_str)):
		if tmp_str[i] == '0':
			if tmp != 0:
				arr.append(tmp)
			tmp = 0
		else:
			tmp += 1
	if tmp != 0:
		arr.append(tmp)
	arr = sorted(arr, reverse=True)
	new_arr = arr[0::2]
	print(sum(new_arr))


def partition(T, p, r):
	pivot = T[r]
	i = p - 1
	for j in range(p, r):
		if T[j] >= pivot:
			i += 1
			(T[j], T[i]) = (T[i], T[j])
	(T[i + 1], T[r]) = (T[r], T[i + 1])
	return i + 1

def quicksort(T, p, r):
	while p < r:
		q = partition(T, p, r)
		if q - p <= r - q:
			quicksort(T, p, q - 1)
			p = q + 1
		else:
			quicksort(T, q, r)
			r = q - 1
T = int(input())
for _ in range(T):
	s = list(map(int, input()))
	result = 0
	A = list()
	alice = 0
	for i in range(len(s)):
		if s[i] == 1:
			result += 1
		elif result > 0 and s[i] != 1:
			A.append(result)
			result = 0
	if result > 0:
		A.append(result)
		result = 0
	quicksort(A, 0, len(A) - 1)
	for j in range(len(A)):
		if j % 2 == 0:
			alice += A[j]
	print(alice)
	A.clear()


for _ in range(int(input())):
	str1 = input()
	str1 = list(str1)
	list1 = []
	i = 0
	while i < len(str1):
		if str1[i] == '1':
			x = 0
			while i < len(str1) and str1[i] == '1':
				x += 1
				i += 1
			list1.append(x)
		i += 1
	if len(list1):
		s = 0
		list1.sort(reverse=True)
		for i in range(len(list1)):
			if i % 2 == 0:
				s += list1[i]
		print(s)
	else:
		print(0)


n = int(input())
A = [input() for i in range(n)]
for i in range(n):
	B = [0]
	for j in range(len(A[i])):
		if A[i][j] == '1':
			B[-1] += 1
		else:
			B.append(0)
	B.sort(reverse=True)
	ans = 0
	for i in range(0, len(B), 2):
		ans += B[i]
	print(ans)


t = int(input())

def calc(s):
	answer = [0]
	result = 0
	for i in s:
		if i == '1':
			result += 1
		if i == '0':
			answer.append(result)
			result = 0
	answer.append(result)
	return max(answer)
for i in range(t):
	s = input()
	turn = 0
	alice = 0
	while calc(s) > 0:
		if turn == 0:
			alice += calc(s)
			turn = 1
		elif turn == 1:
			turn = 0
		s = s.replace('1' * calc(s), '', 1)
	print(alice)


t = int(input())
for _ in range(t):
	s = input()
	a = []
	c = 0
	for i in range(0, len(s)):
		if s[i] == '1':
			c += 1
		elif s[i] == '0':
			a.append(c)
			c = 0
	if c != 0:
		a.append(c)
	a.sort(reverse=True)
	sum1 = 0
	for i in range(0, len(a), 2):
		if a[i] == 0:
			break
		sum1 += a[i]
	print(sum1)


for _ in range(int(input())):
	s = input()
	a = 0
	lengths = []
	start = 0
	for i in range(1, len(s)):
		if s[i - 1] == '0' and s[i] == '1':
			start = i
		if s[i - 1] == '1' and s[i] == '0':
			end = i
			lengths.append(end - start)
	if s[-1] == '1':
		lengths.append(len(s) - start)
	lengths.sort(reverse=True)
	for i in range(len(lengths)):
		if i % 2 == 0:
			a += lengths[i]
	print(a)


import sys
import os.path
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
	sys.stdout = open('out.txt', 'w')
for _ in range(int(input())):
	s = input()
	li = []
	i = 0
	while i < len(s):
		if s[i] == '0':
			i += 1
			continue
		else:
			ans = 0
			while i < len(s) and s[i] == '1':
				ans += 1
				i += 1
			i -= 1
			li.append(ans)
		i += 1
	li = sorted(li)[::-1]
	ans = 0
	for i in range(0, len(li), 2):
		ans += li[i]
	print(ans)


from sys import stdin, stdout
from collections import defaultdict
input = lambda : stdin.readline().strip()
for _ in range(int(input())):
	s = input()
	i = 0
	lst = []
	n = len(s)
	nd = 0
	while i < n:
		if s[i] == '1':
			nd += 1
		else:
			lst.append(nd)
			nd = 0
		i += 1
	lst.append(nd)
	lst.sort(reverse=True)
	j = 0
	sum1 = 0
	for i in lst:
		if j % 2 == 0:
			sum1 += i
		j += 1
	print(sum1)


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 Counter
for _ in range(ii()):
	a = si()
	n = len(a)
	c = 0
	k = []
	for i in range(0, n):
		if a[i] == '1':
			c = c + 1
		else:
			if c != 0:
				k.append(c)
			c = 0
	if c != 0:
		k.append(c)
	if len(k) == 0:
		print(0)
	else:
		k.sort(reverse=True)
		ans = 0
		for i in range(0, len(k), 2):
			ans = ans + k[i]
		print(ans)


n = int(input())
for _ in range(n):
	string = sorted(input().split('0'), reverse=True)
	alice_points = 0
	for seq in string[::2]:
		alice_points += len(seq)
	print(alice_points)


n = int(input())
for _ in range(n):
	a = input()
	ab = []
	l = len(a)
	for i in range(l):
		if i == 0:
			if a[i] == '1':
				ab.append(1)
			else:
				ab.append(0)
		elif a[i - 1] == '1' and a[i] == '1':
			ab.append(ab[-1] + 1)
		elif a[i] == '1':
			ab.append(1)
		else:
			ab.append(0)
	for i in range(l - 1):
		if ab[i] < ab[i + 1]:
			ab[i] = 0
	aaa = []
	for i in ab:
		if i > 0:
			aaa.append(i)
	aaa.sort()
	alice = 0
	for i in range(len(aaa) - 1, -1, -2):
		alice += aaa[i]
	print(alice)


def main():
	for _ in range(int(input())):
		s = input()
		l = s.split('0')
		a = 0
		b = 0
		for i in range(len(l)):
			if i % 2 == 0:
				a += len(max(l))
				l.remove(max(l))
			else:
				b += len(max(l))
				l.remove(max(l))
		print(a)
main()


for _ in range(int(input())):
	s = input()
	arr = []
	lastindex = -1
	for (index, i) in enumerate(s):
		if i == '1':
			if lastindex == index - 1 and lastindex != -1:
				arr[-1] += 1
				lastindex = index
			else:
				arr.append(1)
				lastindex = index
	arr.sort(reverse=True)
	print(sum(arr[::2]))


def za_warudo(s):
	l = []
	y = 0
	if s[0] == '1':
		x = 1
	else:
		x = 0
	for i in s:
		if i == '1':
			y += 1
			if x == 0:
				x = 1
		else:
			if x == 1:
				l.append(y)
				x = 0
			y = 0
	l.append(y)
	return l

def dio(l):
	al = 0
	l = sorted(l)[::-1]
	for i in range(len(l)):
		if i % 2 == 0:
			al += l[i]
	return al
for _ in range(int(input())):
	s = input()
	print(dio(za_warudo(s)))


t = int(input())
for _ in range(t):
	a = input()
	size = 0
	l = []
	for j in a:
		if j == '1':
			size += 1
		elif j == '0' and size == 0:
			continue
		else:
			l.append(size)
			size = 0
	l.append(size)
	l.sort(reverse=True)
	n = len(l)
	i = 0
	sum = 0
	while i < n:
		sum += l[i]
		i += 2
	print(sum)


for i in range(int(input())):
	a = input().split('0')
	a.sort(key=lambda x: -len(x))
	s1 = 0
	s2 = 0
	for (i, val) in enumerate(a):
		if len(val) == 0:
			break
		elif i % 2 == 0:
			s1 += len(val)
		else:
			s2 += len(val)
	print(s1)


for i in range(int(input())):
	s = input()
	l = []
	j = 0
	k = 0
	while j < len(s):
		if s[j] == '1':
			k += 1
		else:
			if k > 0:
				l.append(k)
			k = 0
		j += 1
	if k > 0:
		l.append(k)
	l.sort()
	l = l[::-1]
	print(sum(l[::2]))


t = int(input())
for _ in range(t):
	s = input()
	q = []
	c = 0
	for i in s:
		if i == '1':
			c += 1
			f = 1
		elif c > 0:
			q.append(c)
			c = 0
	if c > 0:
		q.append(c)
	q.sort(reverse=True)
	ans = 0
	for i in range(len(q)):
		if i % 2 == 0:
			ans += q[i]
	print(ans)


try:
	for _ in range(int(input())):
		a = input()
		b = [0]
		for i in range(len(a)):
			if a[i] == '1':
				b[-1] = b[-1] + 1
			elif b[-1] != 0:
				b.append(0)
		b.sort()
		b.reverse()
		ans = 0
		for i in range(0, len(b), 2):
			ans += b[i]
		print(ans)
except Exception as e:
	print(e)


def find_longest_1s(s):
	longest = 0
	x = s.find('1')
	longest = 1
	curr = 1
	start = int(x)
	curr_start = int(x)
	end = int(x)
	for j in range(x + 1, len(s)):
		if s[j] == '1':
			if curr == 0:
				curr_start = j
			curr += 1
		else:
			if curr > longest:
				longest = max(curr, longest)
				start = curr_start
				end = j - 1
			curr = 0
	if curr > longest:
		longest = curr
		start = curr_start
		end = j
	return (start, end, longest)

def solve(s):
	x = -1
	A = 0
	while s:
		x *= -1
		if '1' in s:
			(i, j, longest) = find_longest_1s(s)
			s = s[:i] + s[j + 1:]
			if x == 1:
				A += longest
		else:
			return A
	return A
T = int(input())
for t in range(1, T + 1):
	s = input()
	ans = solve(s)
	print(ans)


def onecount(s):
	count = 0
	arr = []
	for i in range(len(s)):
		if s[i] == '0':
			if count != 0:
				arr.append(count)
				count = 0
		if s[i] == '1':
			count += 1
	if count != 0:
		arr.append(count)
	return sorted(arr)[::-1]
t = int(input())
for _ in range(t):
	s = input()
	a = onecount(s)
	print(sum(a[::2]))


for _ in range(int(input())):
	s = str(input())
	arr = []
	if '1' not in s:
		print(0)
	else:
		cnt = 0
		for i in range(len(s)):
			if s[i] == '1':
				cnt += 1
			else:
				arr.append(cnt)
				cnt = 0
		if cnt != 0:
			arr.append(cnt)
		arr.sort(reverse=True)
		su = 0
		for i in range(0, len(arr), 2):
			su += arr[i]
		print(su)


import sys
input = sys.stdin.readline
from bisect import bisect_left
from bisect import bisect_right
from math import ceil, factorial

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

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

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	s = input().strip()
	n = len(s)
	ones = []
	x = 0
	for i in s:
		if i == '1':
			x += 1
		elif x:
			ones.append(x)
			x = 0
	if x:
		ones.append(x)
	ones.sort(reverse=1)
	ans = 0
	for i in range(0, len(ones), 2):
		ans += ones[i]
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = input()
	point = []
	cnt = 0
	for i in s:
		if i == '1':
			cnt += 1
		elif cnt > 0:
			point.append(cnt)
			cnt = 0
	if cnt > 0:
		point.append(cnt)
	point.sort(reverse=True)
	ans = 0
	for i in range(0, len(point), 2):
		ans += point[i]
	print(ans)


T = int(input())
l = []
for k in range(T):
	N = input()
	a = N.split('0')
	d = []
	s = 0
	for p in a:
		if p != '':
			d.append(p)
	d.sort(reverse=True)
	if len(d) == 0 and int(N) < 1:
		l.append(0)
	elif len(d) == 0 and int(N) >= 1:
		l.append(len(N))
	else:
		for i in range(0, len(d), 2):
			s = s + len(d[i])
		l.append(s)
for k in range(T):
	print(l[k])


for t in range(int(input())):
	s = input()
	s += '0'
	su = sum = 0
	l = []
	for i in s:
		if int(i) == 0:
			l.append(su)
			su = 0
			continue
		else:
			su += int(i)
	for i in l:
		if i == 0:
			l.remove(i)
	l.sort(reverse=True)
	for i in range(len(l)):
		if i % 2 == 0:
			sum += l[i]
	print(sum)


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

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

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

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

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

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

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

def Hash():
	return dict()

def Mod():
	return 1000000007

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

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

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

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

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

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

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

def solution():
	for _ in range(Int()):
		a = Lstr()
		c = 0
		ans = []
		for i in range(len(a)):
			if a[i] == '0':
				ans.append(c)
				c = 0
			else:
				c += 1
		else:
			ans.append(c)
		ans.sort(reverse=True)
		s = 0
		for i in range(0, len(ans), 2):
			s += ans[i]
		print(s)
solution()


for i in range(int(input())):
	S = input()
	X = S.split('0')
	X = [len(l) for l in X]
	X = sorted(X, reverse=True)
	V = 0
	for i in range(0, len(X), 2):
		V += X[i]
	print(V)


from itertools import groupby
for i in range(int(input())):
	a = input()
	b = []
	for (k, j) in groupby(a):
		if k == '1':
			b.append(len(list(j)))
	b.sort(reverse=True)
	c = 0
	if len(b) % 2 == 0:
		for j in range(0, len(b) - 1, 2):
			c += b[j]
	else:
		for j in range(0, len(b), 2):
			c += b[j]
	print(c)


T = int(input())
res = list()
for _ in range(T):
	x = input()
	r = list()
	s = ''
	for i in range(len(x)):
		if int(x[i]) == 0:
			if len(s) > 0:
				r.append(s)
				s = ''
			continue
		else:
			s += x[i]
	if len(s) > 0:
		r.append(s)
	r.sort()
	r = r[::-1]
	ans = 0
	for i in range(0, len(r), 2):
		ans += len(r[i])
	res.append(ans)
for i in res:
	print(i)


import sys

class BSubstringRemovalGame:

	def solve(self, tc=0):
		for _ in range(int(input())):
			s = input().strip()
			score = 0
			alice = True
			while '1' in s:
				n = len(s)
				zeros = [-1] + [i for i in range(n) if s[i] == '0'] + [n]
				mx = 0
				(l, r) = (-1, -1)
				for k in range(1, len(zeros)):
					if zeros[k] - zeros[k - 1] - 1 > mx:
						(l, r) = (zeros[k - 1] + 1, zeros[k] - 1)
						mx = zeros[k] - zeros[k - 1] - 1
				if alice:
					score += mx
					alice = False
				else:
					alice = True
				s = ''.join((s[i] for i in range(n) if i < l or i > r))
			print(score)
solver = BSubstringRemovalGame()
input = sys.stdin.readline
solver.solve()


for _ in range(int(input())):
	s = input().split('0')
	p = sorted(s, reverse=True)
	ans = 0
	for i in range(0, len(p), 2):
		ans += len(p[i])
	print(ans)


def solve(arr):
	aux = []
	i = 0
	n = len(arr)
	while i < n:
		count = 0
		while i < n and arr[i] == '1':
			i += 1
			count += 1
		if count > 0:
			aux.append(count)
		i += 1
	aux.sort(reverse=True)
	ans = 0
	for i in range(0, len(aux), 2):
		ans += aux[i]
	print(ans)
t = int(input())
for _ in range(t):
	arr = input()
	solve(arr)


for _ in range(int(input())):
	s = input()
	l = []
	s1 = set()
	for i in range(len(s)):
		if s[i] == '1' and i not in s1 and (i != len(s) - 1):
			for j in range(i + 1, len(s)):
				if s[j] != s[i]:
					l.append(j - i)
					break
				else:
					s1.add(j)
			else:
				l.append(len(s) - i)
		elif i == len(s) - 1 and i not in s1 and (s[i] == '1'):
			l.append(1)
	l = sorted(l, reverse=True)
	count = 0
	for i in range(0, len(l), 2):
		count += l[i]
	print(count)


import sys
input = sys.stdin.readline

def solve():
	s = list(map(int, input()[:-1]))
	n = len(s)
	blocks = []
	i = 0
	while i < n:
		while i < n and s[i] == 0:
			i += 1
		if i == n:
			break
		j = i + 1
		while j < n and s[j] == 1:
			j += 1
		blocks.append(j - i)
		i = j
	blocks.sort(reverse=True)
	print(sum(blocks[::2]))

def main():
	T = int(input())
	while T > 0:
		solve()
		T -= 1
main()


t = int(input())
for _ in range(t):
	s = str(input())
	d = {}
	c = 0
	for x in s:
		if x == '1':
			c += 1
		else:
			if c > 0:
				if c in d:
					d[c] += 1
				else:
					d[c] = 1
			c = 0
	if c in d:
		d[c] += 1
	else:
		d[c] = 1
	ks = list(d.keys())
	ks.sort(reverse=True)
	alice = 0
	r = 0
	for k in ks:
		if r == 0:
			alice += d[k] // 2 * k + d[k] % 2 * k
		else:
			alice += d[k] // 2 * k
		r = (r + d[k]) % 2
	print(alice)


for _ in range(int(input())):
	s = input()
	l = []
	x = False
	c = 0
	ans = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
			x = True
		else:
			if x == True:
				l.append(c)
				x = False
			c = 0
	if s[-1] == '1' and x == True:
		l.append(c)
	l.sort(reverse=True)
	for (i, val) in enumerate(l):
		if i % 2 == 0:
			ans += val
	print(ans)


from functools import reduce

def get_indices_of(b_str, ch):
	length = len(b_str)

	def get_indices(idx, idx_lst):
		if idx == length:
			return idx_lst
		elif b_str[idx] == ch:
			idx_lst.append(idx)
			return get_indices(idx + 1, idx_lst)
		else:
			return get_indices(idx + 1, idx_lst)
	return get_indices(0, [])

def get_indices_of_1(b_str):
	return get_indices_of(b_str, '1')

def calculate_score(indices_lst):

	def add_score(score, idx):
		[scores, prevIdx] = score
		if prevIdx == -1:
			scores.append(1)
			return [scores, idx]
		if prevIdx + 1 == idx:
			scores[-1] += 1
			return [scores, idx]
		else:
			scores.append(1)
			return [scores, idx]
	return reduce(lambda score, idx: add_score(score, idx), indices_lst, [[], -1])

def even(x):
	return x % 2 == 0

def compute_total_score(scores):
	length = len(scores)

	def score(scores, idx, player):
		if length == idx:
			return player[0]
		else:
			if even(idx):
				player[0] += scores[idx]
			else:
				player[1] += scores[idx]
			return score(scores, idx + 1, player)
	return score(scores, 0, [0, 0])

def main():
	test_case = int(input())
	for i in range(test_case):
		b_str = input()
		scores = calculate_score(get_indices_of_1(b_str))[0]
		scores.sort(reverse=True)
		print(compute_total_score(scores))
main()


t = int(input())
for _ in range(t):
	s = list(input())
	n = len(s)
	ans = []
	i = 0
	while i < n:
		if s[i] == '1':
			j = i
			while j < n and s[j] == '1':
				j += 1
			ans.append(j - i)
			i = j
		else:
			i += 1
	ans.sort(reverse=True)
	new_n = len(ans)
	i = 0
	score = 0
	while i < new_n:
		score += ans[i]
		i += 2
	print(score)


while True:
	try:
		t = eval(input())
		for i in range(t):
			s = input()
			cnt = k = 0
			list0 = []
			for j in s:
				if j == '1':
					cnt += 1
				else:
					list0.append(cnt)
					cnt = 0
			list0.append(cnt)
			list0.sort(reverse=True)
			len1 = len(list0)
			ans = 0
			for j in range(0, len1, 2):
				ans += list0[j]
			print(ans)
	except:
		break


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
for case in range(int(input())):
	s = input().strip().split('0')
	s = [len(x) for x in s]
	s.sort(reverse=True)
	print(sum(s[::2]))


import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
input = stdin.readline
letters = ascii_letters[:26]
for _ in range(int(input())):
	arr = list(map(int, input().strip()))
	lens = []
	count = 0
	for i in arr:
		if i == 0:
			if count > 0:
				lens.append(count)
			count = 0
		else:
			count += 1
	if count > 0:
		lens.append(count)
	lens.sort(reverse=True)
	res = 0
	for i in range(0, len(lens), 2):
		res += lens[i]
	print(res)


import sys
import bisect
t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	l1 = []
	cnt = 0
	for i in range(n):
		if s[i] == '1':
			cnt += 1
		else:
			l1.append(cnt)
			cnt = 0
	l1.append(cnt)
	l1.sort(reverse=True)
	ans = 0
	ch = 0
	for i in range(len(l1)):
		if ch % 2 == 0:
			ans += l1[i]
		ch += 1
	print(ans)


t = int(input())
for _ in range(t):
	a = input().split('0')
	a = [len(i) for i in a if i]
	a.sort()
	a = a[::-1]
	score = 0
	n = len(a)
	for i in range(0, n, 2):
		score += a[i]
	print(score)


t = int(input())
for _ in range(t):
	s = sorted(input().split('0'), reverse=True)[::2]
	res = sum(list(map(len, s)))
	print(res)


n = int(input())
for j in range(n):
	g = input()
	k = list(g)
	k.append('2')
	k.append('2')
	v = []
	l = []
	for i in range(len(k) - 1):
		if k[i] == k[i + 1] and k[i] == '1':
			l.append(k[i])
		elif k[i] != k[i + 1] and k[i] == '1':
			l.append(k[i])
		else:
			v.append(l)
			l = []
	a = []
	for i in range(len(v)):
		if len(v[i]) != 0:
			a.append(len(v[i]))
	a.sort()
	q = 0
	for i in range(len(a) - 1, -1, -2):
		q = q + a[i]
	print(q)


for i in range(int(input())):
	s = input().split('0')
	l = [len(i) for i in s if len(i) != 0]
	l.sort(reverse=True)
	charcount = 0
	for i in range(0, len(l), 2):
		charcount += l[i]
	print(charcount)


for _ in range(int(input())):
	s = input()
	o = sorted(map(len, filter(None, s.split('0'))))
	a = 0
	while o:
		a += o.pop()
		if o:
			o.pop()
	print(a)


t = int(input())
for _ in range(t):
	s = input()
	con = []
	c = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
		else:
			if c > 0:
				con.append(c)
			c = 0
	if c > 0:
		con.append(c)
	con.sort(reverse=True)
	i = 0
	ans = 0
	while i < len(con):
		ans += con[i]
		i += 2
	print(ans)


def main():
	t = int(input())
	for i in range(t):
		s = input()
		count = []
		for i in range(len(s)):
			if s[i] == '1':
				if i == 0 or s[i - 1] == '0':
					count.append(1)
				else:
					count[-1] += 1
		count.sort(key=lambda x: -x)
		answer = 0
		for i in range(len(count)):
			if i % 2 == 0:
				answer += count[i]
		print(answer)
main()


for ii in range(int(input())):
	s = input()
	ans = 0
	z = []
	i = 0
	while i < len(s):
		if s[i] == '1':
			x = 1
			j = i + 1
			while j < len(s):
				if s[j] == '1':
					x += 1
					j += 1
				else:
					break
			z.append(x)
			i = j
		else:
			i += 1
	j = 2
	z.sort(reverse=True)
	for i in z:
		if j % 2 == 0:
			ans += i
		j += 1
	print(ans)


import sys
input = sys.stdin.readline

def solve():
	s = input().strip()
	lis = []
	count = 0
	for i in range(len(s)):
		if s[i] == '0':
			if count != 0:
				lis.append(count)
				count = 0
		if s[i] == '1':
			count += 1
	if count != 0:
		lis.append(count)
	lis = sorted(lis, reverse=True)
	print(sum([lis[i] for i in range(0, len(lis), 2)]))
for _ in range(int(input())):
	solve()


import random

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

def lcm(a, b):
	return a * b / gcd(a, b)
for _ in range(int(input())):
	s = input()
	a = []
	c = 0
	for i in s:
		if i == '1':
			c += 1
		else:
			a.append(c)
			c = 0
	if c != 0:
		a.append(c)
	a.sort()
	ans = 0
	for i in range(len(a) - 1, -1, -2):
		ans += a[i]
	print(ans)


t = int(input())
while t:
	s = input()
	i = 0
	flag = 0
	count_arr = []
	while i < len(s) and flag == 0:
		if s[i] == '1':
			count = 0
			while s[i] == '1':
				count += 1
				if i + 1 < len(s):
					i += 1
				else:
					flag = 1
					break
			count_arr.append(count)
		else:
			i += 1
	count_arr.sort(reverse=True)
	alice = 0
	for i in range(0, len(count_arr), 2):
		alice += count_arr[i]
	print(alice)
	t -= 1


t = int(input())
for _ in range(t):
	arr = input()
	ans = []
	con = 0
	for i in arr:
		if i == '0' and con != 0:
			ans.append(con)
			con = 0
		elif i == '1':
			con += 1
	if con:
		ans.append(con)
	ans.sort(reverse=True)
	result = 0
	for i in range(len(ans)):
		if i % 2 == 0:
			result += ans[i]
	print(result)


for i in range(int(input())):
	s = [len(e) for e in input().split('0')]
	s.sort(reverse=True)
	counter = 0
	x = s[::2]
	print(sum(x))


for i in range(int(input())):
	a = input()
	b = []
	j = 0
	while j < len(a):
		if a[j] == '1':
			count = 0
			while a[j] == '1':
				count += 1
				j += 1
				if j == len(a):
					break
			b.append(count)
		else:
			j += 1
		if j == len(a):
			break
	b.sort()
	b.reverse()
	sum = 0
	for k in range(len(b)):
		if k % 2 == 0:
			sum += b[k]
	print(sum)


t = int(input())
for _ in range(t):
	s = [int(i) for i in input()]
	s += [0]
	ones = []
	count = 0
	for i in range(len(s)):
		if s[i] == 1:
			count += 1
		elif count > 0:
			ones.append(count)
			count = 0
	ones = sorted(ones, reverse=True)
	ans = 0
	for i in range(0, len(ones), 2):
		ans += ones[i]
	print(ans)


for _ in range(int(input())):
	s = input()
	s = s.split('0')
	arr = []
	for i in s:
		if i:
			arr.append(len(i))
	arr.sort()
	l = len(arr)
	if l % 2 == 0:
		print(sum(arr[1:l:2]))
	else:
		print(sum(arr[0:l:2]))


t = int(input())

def count_max_consecutive_ones(sequence):
	max_consecutive = 0
	current = 0
	for c in sequence:
		if c == '1':
			current += 1
		else:
			max_consecutive = max(max_consecutive, current)
			current = 0
	return max(max_consecutive, current)
for i in range(0, t):
	sequence = input()
	ans = 0
	alice = True
	while True:
		count = count_max_consecutive_ones(sequence)
		if count == 0:
			break
		if alice:
			ans += count
		index = sequence.find('1' * count)
		sequence = sequence[:index] + sequence[index + count:]
		alice = not alice
	print(ans)


import array

def conta_rodadas(array, rodadas):
	num_uns = 1
	for indice in range(len(array) - 1):
		if array[indice] == '0':
			continue
		if array[indice + 1] == '1':
			num_uns += 1
		else:
			insere(rodadas, num_uns)
			num_uns = 1
	if array[len(array) - 1] == '1':
		insere(rodadas, num_uns)

def insere(lista, numero):
	lista.append(numero)
	for indice in range(len(lista) - 1, 0, -1):
		if lista[indice] <= lista[indice - 1]:
			break
		temp = lista[indice]
		lista[indice] = lista[indice - 1]
		lista[indice - 1] = temp
T = int(input())
for _ in range(T):
	rodadas = []
	s = array.array('u', input())
	conta_rodadas(s, rodadas)
	pontos_alice = 0
	indice = 0
	while indice < len(rodadas):
		pontos_alice += rodadas[indice]
		indice += 2
	print(pontos_alice)


for _ in range(int(input())):
	s = input().split('0')
	b = []
	for i in s:
		if len(i) > 0:
			b.append(int(i))
	b.sort()
	b.reverse()
	cnt = 0
	for i in range(0, len(b), 2):
		cnt += len(str(b[i]))
	print(cnt)


for _ in range(int(input())):
	s = input()
	alist = []
	count = 0
	for i in s:
		if i == '0':
			alist.append(count)
			count = 0
			continue
		count += 1
	alist.append(count)
	alist.sort(reverse=True)
	a = 0
	for j in range(0, len(alist), 2):
		a += alist[j]
	print(a)


t = int(input())
anss = []
for _ in range(t):
	elements = list(map(int, list(input())))
	elements.append(0)
	blocks = []
	curr_cnt = 0
	for i in elements:
		if i == 1:
			curr_cnt += 1
		else:
			blocks.append(curr_cnt)
			curr_cnt = 0
	ans = 0
	blocks.sort()
	for i in range(0, len(blocks), 2):
		ans += blocks[::-1][i]
	anss.append(ans)
for i in anss:
	print(i)


from re import findall
for _ in range(int(input())):
	match = findall('1+', input())
	if not match:
		print(0)
		continue
	match.sort(reverse=True)
	result = 0
	for i in range(0, len(match), 2):
		result += len(match[i])
	print(result)


import re
t = int(input())
for i in range(t):
	s = input()
	y = re.findall('1+', s)
	for i in y:
		i = int(i)
	y.sort()
	i = len(y) - 1
	ans = 0
	while i >= 0:
		ans = ans + len(y[i])
		i -= 2
	print(ans)


for _ in range(int(input())):
	s = input()
	cnt_tou = 0
	lis = []
	for i in s:
		if i == '0':
			lis.append(cnt_tou)
			cnt_tou = 0
		else:
			cnt_tou += 1
	if cnt_tou != 0:
		lis.append(cnt_tou)
	lis.sort(reverse=True)
	tot = 0
	for u in range(len(lis)):
		if u % 2 == 0:
			tot += lis[u]
	print(tot)


for _ in range(int(input())):
	s = input()
	arr = []
	count = 0
	for c in s:
		if c == '0' and count > 0:
			arr.append(count)
			count = 0
		elif c == '1':
			count += 1
	if count:
		arr.append(count)
	res = 0
	arr.sort(reverse=True)
	for i in range(0, len(arr), 2):
		res += arr[i]
	print(res)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = input().strip()
	a = s.split('0')
	a.sort(key=lambda x: len(x), reverse=True)
	ans = 0
	for i in range(0, len(a), 2):
		ans += len(a[i])
	print(ans)


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	s = sys.stdin.readline().strip() + '0'
	list_one = []
	now = 0
	for i in range(len(s)):
		if s[i] == '0' and now:
			list_one.append(now)
			now = 0
		elif s[i] == '1':
			now += 1
	list_one.sort(reverse=True)
	print(sum([list_one[i] for i in range(len(list_one)) if not i % 2]))


for _ in range(int(input())):
	s = input()
	blocks = []
	count = 0
	for c in s:
		if c == '1':
			count += 1
		else:
			blocks.append(count)
			count = 0
	if count:
		blocks.append(count)
	blocks.sort()
	answer = 0
	blocks = blocks[::-1]
	for i in range(0, len(blocks), 2):
		answer += blocks[i]
	print(answer)


n = int(input())
for i in range(n):
	s = str(input())
	c = []
	r = -1
	t = 0
	for j in range(len(s)):
		if s[j] == '1':
			if r + 1 == j:
				t = t + 1
				r = j
			else:
				if t != 0:
					c.append(t)
				t = 0
				r = j
				t = t + 1
	if t != 0:
		c.append(t)
	c = sorted(c, reverse=True)
	su = 0
	for j in range(len(c)):
		if j % 2 == 0:
			su = su + c[j]
	print(su)


for _ in range(int(input())):
	napis = input().split('0')
	i_1 = []
	for x in napis:
		if x != '':
			i_1.append(len(x))
	i_1.sort(reverse=True)
	wynik = 0
	for x in range(0, len(i_1), 2):
		wynik += i_1[x]
	print(wynik)


t = int(input())
for i in range(t):
	s = input()
	counts = []
	count = 0
	for j in s:
		if j == '1':
			count += 1
		else:
			counts.append(count)
			count = 0
	counts.append(count)
	counts.sort(reverse=True)
	score1 = 0
	score2 = 0
	for j in range(len(counts)):
		if j % 2 == 0:
			score1 += int(counts[j])
		else:
			score2 += int(counts[j])
	print(score1)


for _ in range(int(input())):
	s = str(input())
	l = []
	i = 0
	while i < len(s):
		tt = 0
		if s[i] == '1':
			tt = 1
			count = 0
			for j in range(i, len(s)):
				if s[j] == '1':
					count += 1
				else:
					l.append(count)
					i += j - i - 1
					break
				if j == len(s) - 1:
					l.append(count)
					count = 0
					i += j - i
					break
		i += 1
	if len(l) != 0:
		l.sort()
	c = 0
	for i in range(len(l) - 1, -1, -2):
		c += l[i]
	print(c)


t = int(input())
for i in range(0, t):
	l = input()
	l = l + '9'
	x = []
	c = 1
	for i in range(0, len(l) - 1):
		if l[i] == '1' and l[i] == l[i + 1]:
			c = c + 1
		elif l[i] != l[i + 1] and l[i] == '1':
			x.append(c)
			c = 1
	t = 0
	x.sort(reverse=True)
	for i in range(0, len(x), 2):
		t = t + x[i]
	print(t)


def score(s):
	scores = []
	startIndex = None
	for (i, ch) in enumerate(s):
		if s[i] == '1':
			if startIndex is None:
				startIndex = i
		elif startIndex is not None:
			scores.append(i - startIndex)
			startIndex = None
	if startIndex is not None:
		scores.append(len(s) - startIndex)
	scores.sort(reverse=True)
	ans = 0
	for i in range(0, len(scores), 2):
		ans += scores[i]
	return ans
t = int(input())
for _ in range(t):
	s = input()
	print(score(s))


t = int(input())
for i in range(t):
	arr = list(map(int, input()))
	a = []
	count = 0
	i = 0
	for i in range(len(arr)):
		if arr[i] == 1:
			count += 1
		else:
			a.append(count)
			count = 0
	a.append(count)
	a = sorted(a)[::-1]
	ans = 0
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)


n = int(input())
saida = []
for i in range(n):
	s = 0
	binario = input()
	aux = []
	cont = 0
	for j in binario:
		if j == '1':
			cont += 1
		elif cont > 0:
			aux.append(cont)
			cont = 0
	if cont > 0:
		aux.append(cont)
	aux.sort()
	for k in range(len(aux) - 1, -1, -2):
		s += aux[k]
	saida.append(s)
for l in saida:
	print(l)


for _ in range(int(input())):
	s = input().split('0')
	s = sorted(s, reverse=True)
	a = 0
	for i in range(0, len(s), 2):
		a += s[i].count('1')
	print(a)


n = int(input())
for _ in range(n):
	n1 = input()
	f = []
	sum1 = 0
	for i in n1:
		if i == '1':
			sum1 += 1
		else:
			f.append(sum1)
			sum1 = 0
	f.append(sum1)
	f = sorted(f)[::-1]
	a = 0
	for i in range(0, len(f), 2):
		a += f[i]
	print(a)


t = int(input())
while t:
	ans = 0
	s = input()
	x = [i for i in s.split('0') if len(i) > 0]
	x.sort(reverse=True)
	for i in x[0::2]:
		ans += len(i)
	print(ans)
	t -= 1


t = int(input())
for i in range(t):
	s = input()
	l = []
	count = 0
	for j in range(len(s)):
		if s[j] == '1':
			count += 1
		if s[j] == '0' and count > 0:
			l.append(count)
			count = 0
	l.append(count)
	l.sort(reverse=True)
	j = 0
	alice = 0
	while j < len(l):
		alice += l[j]
		j += 2
	print(alice)


from sys import stdin

def readline():
	return stdin.readline()
tests = int(readline())

def solve(s):
	i = 0
	arr = []
	for k in s:
		if k == 0:
			if i > 0:
				arr.append(i)
				i = 0
			continue
		i += 1
	if i > 0:
		arr.append(i)
	ans = 0
	arr.sort(reverse=True)
	for i in range(0, len(arr)):
		if i % 2 == 0:
			ans += arr[i]
	return ans
for t in range(0, tests):
	s = list(map(int, readline().rstrip('\n')))
	print(solve(s))


T = int(input())
for _ in range(T):
	st = input()
	lst = []
	cnt = 0
	for i in st:
		if i == '1':
			cnt += 1
		else:
			if cnt != 0:
				lst.append(cnt)
			cnt = 0
	if cnt != 0:
		lst.append(cnt)
	lst.sort(reverse=True)
	answer = 0
	for i in range(0, len(lst), 2):
		answer += lst[i]
	print(answer)


t = int(input())
while t > 0:
	curc = 1
	a = input()
	b = []
	for i in range(len(a) - 1):
		if a[i] == '1':
			if a[i] == a[i + 1]:
				curc += 1
			else:
				b.append(curc)
				curc = 1
	if a[len(a) - 1] == '1':
		b.append(curc)
	b.sort(reverse=True)
	als = 0
	for i in range(0, len(b), 2):
		als += b[i]
	print(als)
	t -= 1


import sys, itertools
cases_skipped = False
for line in sys.stdin:
	line = line.strip()
	if not cases_skipped:
		cases_skipped = True
		continue
	n = len(line)
	G = [len(list(item[1])) for item in itertools.groupby(line) if item[0] == '1']
	G.sort(reverse=True)
	score = 0
	for i in range(len(G)):
		if i % 2 == 0:
			score += G[i]
	print(score)


import re

def solve(string):
	alice = 0
	matches = [len(match) for match in re.findall('1+', string)]
	matches = sorted(matches, reverse=True)
	for i in range(0, len(matches), 2):
		alice += matches[i]
	return alice
tries = input()
for i in range(int(tries)):
	string = input()
	print(solve(string))


for _ in range(int(input())):
	l = list(input())
	n = len(l)
	c = 0
	res = []
	for i in range(n):
		if l[i] == '1':
			c += 1
		elif c:
			res.append(c)
			c = 0
	if c:
		res.append(c)
	res.sort()
	res = res[::-1]
	(c1, c2) = (0, 0)
	for i in range(len(res)):
		if i & 1:
			c1 += res[i]
		else:
			c2 += res[i]
	print(max(c1, c2))


for nt in range(int(input())):
	s = input()
	n = len(s)
	if s[0] == '1':
		count = 1
	else:
		count = 0
	groups = []
	for i in range(1, n):
		if s[i] == '1':
			count += 1
		else:
			if count:
				groups.append(count)
			count = 0
	if count:
		groups.append(count)
	groups.sort(reverse=True)
	ans = 0
	for i in range(0, len(groups), 2):
		ans += groups[i]
	print(ans)


for _ in range(int(input())):
	s = input()
	l = []
	cnt = 0
	for i in s:
		if i == '1':
			cnt += 1
		else:
			l.append(cnt)
			cnt = 0
	a = 0
	if cnt > 0:
		l.append(cnt)
	l.sort(reverse=True)
	i = 0
	while i < len(l):
		if i % 2 == 0:
			a = a + l[i]
		i = i + 1
	print(a)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	a = sys.stdin.readline()
	count = 0
	if a[0] == '1':
		count = 1
	carr = []
	i = 0
	while i < len(a):
		if a[i] == '1':
			count = 1
			i = i + 1
			while i < len(a) and a[i] == '1':
				i += 1
				count += 1
			carr.append(count)
			count = 0
		i += 1
	carr.sort(reverse=True)
	Al = 0
	for i in range(len(carr)):
		if i % 2 == 0:
			Al += carr[i]
	print(Al)


t = int(input())
for i in range(t):
	s = input()
	st = []
	c = 0
	sm = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
		else:
			st.append(c)
			c = 0
		if i == len(s) - 1:
			st.append(c)
	st = list(filter(lambda x: x != 0, st))
	st = sorted(st, reverse=True)
	i = 0
	while i < len(st):
		sm += st[i]
		i = i + 2
	print(sm)


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 collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
t = ip()
for _ in range(t):
	s = ips()
	ch = []
	ct = 0
	for i in s:
		if i == '0':
			if ct != 0:
				ch.append(ct)
				ct = 0
		else:
			ct += 1
	if ct != 0:
		ch.append(ct)
	ch.sort(reverse=True)
	ans = 0
	for i in range(0, len(ch), 2):
		ans += ch[i]
	print(ans)


n = int(input())
for _ in range(n):
	x = input()
	i = 0
	s = []
	while i < len(x):
		if x[i] == '1':
			j = i
			while j < len(x) and x[j] == '1':
				j += 1
			s.append(j - i)
			i = j
		i += 1
	s.sort(reverse=True)
	ans = 0
	for i in range(0, len(s), 2):
		ans += s[i]
	print(ans)


import sys

def main():
	t = int(sys.stdin.readline())
	for _ in range(t):
		s = sys.stdin.readline().rstrip()
		l = [len(c) for c in s.split('0') if len(c) > 0]
		l.sort()
		print(sum(l[::-2]))
main()


for _ in range(int(input())):
	s = input()
	a = []
	i = 0
	c = 0
	while i < len(s):
		if s[i] == '1':
			c += 1
		else:
			a.append(c)
			c = 0
		i += 1
	if c > 0:
		a.append(c)
	a.sort(reverse=True)
	print(sum(a[::2]))


t = int(input())
while t:
	l = list(input().split('0'))
	l1 = []
	for i in l:
		x = len(i)
		l1.append(x)
	l1.sort(reverse=True)
	a = 0
	for i in range(len(l1)):
		if i % 2 == 0:
			a += l1[i]
	print(a)
	t -= 1


t = int(input())
for i in range(t):
	s = input()
	s1 = list(s)
	if '1' not in s1:
		print('0')
	elif '0' in s1:
		s2 = s.split('0')
		a = []
		for i in s2:
			c = len(i)
			a.append(c)
		a.sort(reverse=True)
		su = 0
		for j in range(0, len(a), 2):
			su = su + a[j]
		print(su)
	else:
		print(len(s1))


import collections
from functools import lru_cache

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

def readInt():
	return int(input().strip())

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

def solve(s):
	totalOnes = sum(s)
	turn = 1
	ans = 0
	N = len(s)
	while totalOnes:
		i = 0
		(maxOneSize, l, r) = (0, -1, -1)
		while i < N:
			while i < N and s[i] == 0:
				i += 1
			j = i + 1
			while j < N and s[i] == s[j]:
				j += 1
			le = j - i
			if maxOneSize < le:
				maxOneSize = le
				l = i
				r = j
			i = j
		if maxOneSize:
			for k in range(l, r):
				s[k] = 0
		if turn:
			ans += maxOneSize
		totalOnes -= maxOneSize
		turn = turn ^ 1
	return ans
t = readInt()
for i in range(t):
	s = [int(ch) for ch in read()]
	print(solve(s))


t = int(input())
while t:
	s = input()
	p = 0
	a = []
	for i in s:
		if i == '0':
			if p != 0:
				a.append(p)
			p = 0
		else:
			p += 1
	if s[-1] == '1':
		a.append(p)
	a.sort(reverse=True)
	res = 0
	i = 0
	while i < len(a):
		res = res + a[i]
		i += 2
	print(res)
	t -= 1


t = int(input())
for i in range(t):
	x = input()
	c = 0
	a = []
	ans = 0
	for j in range(len(x)):
		if x[j] == '0' and c != 0:
			a.append(c)
			c = 0
		elif x[j] == '1' and j != len(x) - 1:
			c += 1
		elif j == len(x) - 1 and x[j] == '1':
			c += 1
			a.append(c)
	if len(a) == 0:
		print(0)
		continue
	else:
		a.sort(reverse=True)
		for k in range(0, len(a), 2):
			ans += a[k]
		print(ans)


t = int(input())
for i in range(t):
	string = input()
	seq = []
	contador = 0
	for j in range(len(string)):
		if string[j] == '1':
			contador += 1
			if j == len(string) - 1:
				if contador > 0:
					seq.append(contador)
		else:
			if contador > 0:
				seq.append(contador)
			contador = 0
	seq.sort()
	j = len(seq) - 1
	answer = 0
	while j >= 0:
		answer += seq[j]
		j -= 2
	print(answer)


import sys
for t in range(0, int(sys.stdin.readline())):
	bs = sys.stdin.readline()
	streak = 0
	onedups = []
	for i in bs:
		if i == '1':
			streak += 1
		else:
			onedups.append(streak)
			streak = 0
	onedups.sort(reverse=True)
	A = 0
	for i in range(0, len(onedups)):
		if i % 2 == 0:
			A += onedups[i]
	sys.stdout.write(str(A) + '\n')


t = int(input())
for _ in range(t):
	s = input()
	x = s.split('0')
	l = [len(i) for i in x]
	l.sort(reverse=True)
	a = l[::2]
	print(sum(a))


from itertools import groupby
T = int(input())
for _ in range(T):
	S = list(input())
	G = groupby(S)
	C = []
	for (k, v) in G:
		if k == '1':
			C.append(len(list(v)))
	C.sort()
	ans = 0
	i = 0
	while C:
		if i % 2 == 0:
			ans += C.pop()
		else:
			C.pop()
		i += 1
	print(ans)


n = int(input())
for q in range(n):
	s = input()
	a = 0
	while True:
		i = s.find('1')
		if i == -1:
			break
		xi = xl = l = 0
		for i in range(len(s)):
			if s[i] == '1':
				l += 1
			else:
				if l > xl:
					xl = l
					xi = i - l
				l = 0
		if l > xl:
			xl = l
			xi = len(s) - l
		a += xl
		s = s[:xi] + s[xi + xl:]
		i = s.find('1')
		if i == -1:
			break
		xi = xl = l = 0
		for i in range(len(s)):
			if s[i] == '1':
				l += 1
			else:
				if l > xl:
					xl = l
					xi = i - l
				l = 0
		if l > xl:
			xl = l
			xi = len(s) - l
		s = s[:xi] + s[xi + xl:]
	print(a)


t = int(input())
for tt in range(t):
	s = input().split('0')
	sn = []
	for x in s:
		if x:
			sn.append(len(x))
	sn.sort(reverse=True)
	a = 0
	b = 0
	for i in range(len(sn)):
		if i % 2 == 0:
			a += sn[i]
		else:
			b += sn[i]
	print(a)


t = int(input())
for i in range(t):
	s = input()
	l = s.split('0')
	m = []
	for each in l:
		if len(each) > 0:
			m.append(len(each))
	m = sorted(m, reverse=True)
	alice = 0
	bob = 0
	for i in range(len(m)):
		if i % 2:
			bob += m[i]
		else:
			alice += m[i]
	print(alice)


for tt in range(int(input())):
	s = input()
	i = 0
	ans = []
	while i < len(s):
		if s[i] == '1':
			j = i
			c = 0
			while j < len(s) and s[j] == '1':
				j += 1
				c += 1
			i = j
			ans.append(c)
		else:
			i += 1
	ans.sort(reverse=True)
	alice = 0
	for i in range(len(ans)):
		if (i + 1) % 2 != 0:
			alice += ans[i]
	print(alice)


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

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

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
from collections import defaultdict as dc
for _ in range(N()):
	s = input()
	l = []
	tmp = 0
	for c in s:
		if c != '1':
			l.append(tmp)
			tmp = 0
		else:
			tmp += 1
	l.append(tmp)
	l = [i for i in l if i > 0]
	l.sort(reverse=True)
	print(sum(l[::2]))


def func(s):
	for i in range(s):
		n = input()
		alice = 0
		ans = ''
		l = []
		for i in n:
			if i == '1':
				ans += '1'
			elif i == '0' and len(ans) >= 1:
				l.append(ans)
				ans = ''
			else:
				continue
		l.append(ans)
		l.sort(reverse=True)
		l = l[::2]
		for i in l:
			alice += len(i)
		print(alice)
s = int(input())
func(s)


n = int(input())
for i in range(n):
	a = input()
	b = 0
	puntaje = 0
	tests = [int(x) for x in a.split('0') if x != '']
	while len(tests) > 0:
		maximo = str(max(tests))
		if b % 2 == 0:
			puntaje = puntaje + len(str(max(tests)))
		a = a.replace(maximo, '', 1)
		b = b + 1
		tests = [int(x) for x in a.split('0') if x != '']
	print(puntaje)


tests = int(input())
for t in range(tests):
	ls = input()
	count = 0
	one_list = []
	res = 0
	for item in ls:
		if item == '1':
			count += 1
		else:
			one_list.append(count)
			count = 0
	if count > 0:
		one_list.append(count)
	one_list = sorted(one_list)
	for (idx, item) in enumerate(one_list[::-1]):
		if idx % 2 == 0:
			res += item
	print(res)


test_cases = int(input())
for _ in range(test_cases):
	s = sorted([len(x) for x in input().split('0') if x], reverse=True)
	print(sum((x for x in s[::2])))


t = input()
for _ in range(int(t)):
	ts = input()
	result = 0
	string = ts.split('0')
	string = [i for i in string if i != '']
	string = sorted(string, key=lambda x: len(x), reverse=True)
	for j in string[0::2]:
		result += len(j)
	print(result)


t = int(input())
for _ in range(0, t):
	a = input()
	a = list(a)
	count = 1
	s = 0
	count = 0
	count2 = 0
	d = 1
	b = []
	flag = 0
	for i in range(0, len(a)):
		if a[i] == '1' and d == 1:
			count += 1
			count2 = 0
			flag = 0
			l = 0
		elif a[i] == '1' and d == 0:
			count2 += 1
			count = 0
			flag = 0
			l = 1
		else:
			if count2 > count:
				b.append(count2)
				count2 = 0
				d = 1
			elif count > count2:
				b.append(count)
				count = 0
				d = 0
			flag = 1
	if flag == 0:
		if l == 0:
			b.append(count)
		else:
			b.append(count2)
	b.sort(reverse=True)
	sum = 0
	for i in range(0, len(b), 2):
		sum = sum + b[i]
	print(sum)


for t in range(int(input())):
	s = input()
	(arr, j, n) = ([], 0, len(s))
	while j < n:
		if s[j] == '1':
			temp = 0
			for i in range(j, n):
				if s[i] == '1':
					j += 1
					temp += 1
				else:
					break
			arr.append(temp)
		else:
			j += 1
	arr = sorted(arr, reverse=True)
	count = 0
	for j in range(len(arr)):
		if j % 2 == 0:
			count += arr[j]
	print(count)


Q = int(input())
for q in range(Q):
	s = '0' + input() + '0'
	s = s.split('0')
	L = [0]
	for i in range(len(s)):
		if len(s[i]) >= 1:
			L.append(len(s[i]))
	L.sort(reverse=True)
	ans = 0
	for i in range(len(L)):
		if i % 2 == 0:
			ans += L[i]
	print(ans)


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


t = int(input())
for _ in range(t):
	a = input()
	n = len(a)
	c = 0
	l = []
	i = 0
	while i < n:
		while i < n and a[i] == '1':
			i += 1
			c += 1
		l.append(c)
		c = 0
		i += 1
	l.sort(reverse=True)
	alice = 0
	n1 = len(l)
	for i in range(n1):
		if i & 1 == 0:
			alice += l[i]
	print(alice)


t = int(input(''))
ans = []
for i in range(t):
	str_bin = input('')
	s = []
	idx = 0
	last_num = 0
	for i in str_bin:
		if i == '1':
			last_num = 1
			idx += 1
		else:
			if last_num == 1:
				s.append(idx)
				idx = 0
			last_num = 0
	else:
		s.append(idx)
		idx = 0
		last_num = 0
	swapped = True
	while swapped:
		swapped = False
		for i in range(len(s) - 1):
			if s[i] < s[i + 1]:
				(s[i], s[i + 1]) = (s[i + 1], s[i])
				swapped = True
	for i in range(0, len(s), 2):
		idx += s[i]
	ans.append(idx)
for i in ans:
	print(i)


import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

def solve(res):
	console('----- solving ------')
	arr = [len(segment) for segment in res.split('0') if len(segment) > 0]
	arr = sorted(arr)[::-1]
	return sum(arr[::2])

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	return
for case_num in range(int(input())):
	strr = input()
	res = solve(strr)
	print(res)


t = int(input())
for i in range(t):
	s = list(input())
	ones = []
	temp = 0
	temp = True
	counter = 0
	for i in range(len(s)):
		if temp and s[i] == '1':
			counter += 1
			temp = False
		elif not temp and s[i] == '1':
			counter += 1
		elif not temp and s[i] == '0':
			temp = True
			ones.append(counter)
			counter = 0
	if s[i] == '1':
		ones.append(counter)
	if ones == []:
		print(0)
	else:
		ones = sorted(ones, reverse=True)
		ones = [ones[i] for i in range(len(ones)) if i % 2 == 0]
		print(sum(ones))


def calcTest(test):
	accumList = []
	accum = 0
	for n in test:
		if n == '1':
			accum += 1
		elif n == '0' and accum != 0:
			accumList.append(accum)
			accum = 0
	if accum != 0:
		accumList.append(accum)
	accumList = sorted(accumList, reverse=True)
	maximum = 0
	for i in range(0, len(accumList), 2):
		maximum += accumList[i]
	return maximum
t = int(input())
result = ''
for i in range(t):
	test = input()
	res = calcTest(test)
	result += str(res) + '\n'
print(result)


import sys
import math
from collections import Counter, defaultdict
input = sys.stdin.readline
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()

def case():
	s = S()
	c = 0
	a = []
	d = s.split('0')
	for i in d:
		v = i.count('1')
		if v:
			a += [i.count('1')]
	a.sort(reverse=True)
	for i in range(0, len(a), 2):
		c += a[i]
	print(c)
for _ in range(IN()):
	case()


from sys import stdin, stdout
from collections import Counter, OrderedDict
import math
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))

def chars():
	s = cin()
	return list(s[:len(s) - 1])

def pl(a):
	for val in a:
		cout(str(val) + ' ')
	cout('\n')
(t,) = mp()
for _ in range(t):
	s = chars()
	l = []
	temp = f = 0
	for ch in s:
		if ch == '1':
			temp += 1
		else:
			if temp:
				l += [temp]
			temp = 0
	if temp:
		l += [temp]
	sum = 0
	l.sort(reverse=True)
	for i in range(0, len(l), 2):
		sum += l[i]
	pl([sum])


t = int(input())
while t:
	t -= 1
	l = list(input())
	a = 0
	c = 2
	while '1' in l:
		ar = []
		pr = []
		for i in range(len(l)):
			if l[i] == '1':
				ar.append(i)
			else:
				if len(ar) > len(pr):
					pr = ar[:]
				ar = []
		if len(ar) > len(pr):
			pr = ar[:]
		for i in pr[::-1]:
			l.pop(i)
		if c % 2 == 0:
			a += len(pr)
		c += 1
	print(a)


import sys
input = sys.stdin.readline
for kek in range(int(input())):
	s = input()
	a = list()
	x = 0
	for i in s:
		if i == '1':
			x += 1
		else:
			a.append(x)
			x = 0
	a.sort(reverse=True)
	ans = 0
	for j in range(0, len(a), 2):
		ans += a[j]
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	counts = []
	current = 0
	for c in s:
		if c == '1':
			current += 1
		else:
			counts.append(current)
			current = 0
	counts.append(current)
	counts = sorted(counts, reverse=True)
	print(sum(counts[::2]))


def solve(s):
	ones = []
	count = 0
	for i in s:
		if i == '1':
			count += 1
		else:
			if count >= 0:
				ones.append(count)
			count = 0
	if count > 0:
		ones.append(count)
	ones.sort(reverse=True)
	count = 0
	for i in range(0, len(ones), 2):
		count += ones[i]
	return count
n = int(input())
for i in range(n):
	s = input()
	print(solve(s))


t = int(input())
for _ in range(t):
	s = input()
	lst = [str for str in s.split('0') if str]
	lst.sort()
	ans = 0
	for i in range(len(lst) - 1, -1, -2):
		ans += len(lst[i])
	print(ans)


from sys import *
input = stdin.readline
t = int(input())
for _ in range(t):
	s = input()
	l = []
	c = 0
	for i in range(len(s)):
		if i == 0 and s[i] == '1':
			c += 1
		elif s[i] == '1' and s[i - 1] == '1':
			c += 1
		elif s[i] == '1':
			l.append(c)
			c = 1
	l.append(c)
	l.sort(reverse=True)
	c = 0
	for i in range(len(l)):
		if i % 2 == 0:
			c += l[i]
	print(c)


import math
import time
from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import PriorityQueue
import sys
t = 1
t = int(input())
for _ in range(t):
	s = input()
	ans = []
	i = 0
	temp = 0
	while i < len(s):
		if s[i] == '0':
			if temp > 0:
				ans.append(temp)
			temp = 0
		else:
			temp += 1
		i += 1
	if temp > 0:
		ans.append(temp)
	ans.sort(reverse=True)
	final = 0
	for i in range(0, len(ans), 2):
		final += ans[i]
	print(final)


from sys import stdin, stdout
import bisect
import math
from collections import deque
mod = 10 ** 9 + 7

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

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

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

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

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

def DFS(dictionary, vertex, visited):
	visited[vertex] = True
	stack = [vertex]
	print(vertex)
	while stack:
		a = stack.pop()
		for i in dictionary[a]:
			if not visited[i]:
				print(i)
				visited[i] = True
				stack.append(i)

def BFS(dictionary, vertex, visited):
	visited[vertex] = True
	q = deque()
	q.append(vertex)
	while q:
		a = q.popleft()
		for i in dictionary[a]:
			if not visited[i]:
				visited[i] = True
				q.append(i)
				print(i)

def soe(limit):
	l = [1] * (limit + 1)
	l[0] = 0
	l[1] = 0
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

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

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
		a *= a
		n = n >> 1
	return r

def solve():
	s = st()
	x = []
	c = 0
	i = 0
	while i < len(s):
		if s[i] == '1':
			c = 1
			j = i + 1
			while j < len(s) and s[j] == '1':
				c += 1
				j += 1
			x.append(c)
			i = j
		else:
			i += 1
	x.sort()
	ans1 = 0
	ans2 = 0
	for i in range(len(x)):
		if i & 1:
			ans1 += x[i]
		else:
			ans2 += x[i]
	print(max(ans1, ans2))
for _ in range(inp()):
	solve()


def solve(a):
	i = 0
	s = []
	while i < len(a):
		if a[i] == '0':
			i += 1
			continue
		j = i
		while j < len(a) and a[j] == '1':
			j += 1
		s.append(j - i)
		i = j
	s.sort(reverse=True)
	print(sum([x for (i, x) in enumerate(s) if i % 2 == 0]))

def main():
	inp = lambda : [int(x) for x in input().split()]
	tc = int(input())
	for _ in range(tc):
		a = input()
		solve(a)
main()


try:
	t = int(input())
	for i in range(t):
		n = input()
		l = list(n)
		l = [int(x) for x in l]
		l1 = []
		ans = 0
		i = 0
		le = len(l)
		while i < len(l):
			if l[i] == 1:
				ans = 0
				for j in range(i, len(l)):
					if l[j] == 1:
						ans += 1
					else:
						l1.append(ans)
						ans = 0
						i = j - 1
						break
				l1.append(ans)
				if j == le - 1:
					break
			i += 1
		l1.sort()
		l1.reverse()
		l2 = []
		for i in range(len(l1)):
			if l1[i] > 0:
				l2.append(l1[i])
		fa = 0
		for i in range(0, len(l2), 2):
			fa += l2[i]
		print(fa)
except:
	pass


for _ in range(int(input())):
	s = input()
	n = len(s)
	ls = []
	f = False
	cnt = 0
	for i in range(n):
		if s[i] == '1':
			cnt += 1
			f = True
		elif f:
			ls.append(cnt)
			cnt = 0
			f = False
	ls.append(cnt)
	ls.sort(reverse=True)
	cnt = 0
	for i in range(len(ls)):
		if i % 2 == 0:
			cnt += ls[i]
	print(cnt)


t = int(input())
while t:
	s = input()
	ss = list(s)
	c = 0
	p = []
	for i in range(len(ss)):
		if ss[i] == '1':
			c += 1
		elif ss[i] == '1' and ss[i - 1] == '1':
			c += 1
		else:
			p.append(c)
			c = 0
			f = 0
		f = 1
	if f == 1:
		p.append(c)
	b = 0
	p.sort()
	p.reverse()
	for i in range(0, len(p), 2):
		b += p[i]
	print(b)
	t -= 1


def sub():
	N = int(input())
	for i in range(N):
		a = input()
		b = []
		c = 1
		d = 0
		for j in range(1, len(a)):
			if a[j] == a[j - 1] == '1':
				c += 1
			elif a[j] != a[j - 1] and a[j - 1] == '1':
				b += [c]
				c = 1
			else:
				c = 1
		if a[len(a) - 1] == '0':
			c = 0
		b += [c]
		for k in range(len(b)):
			if k % 2 == 0:
				d += int(max(b))
			b.remove(max(b))
		print(str(d))
sub()


tests = int(input())
for test in range(tests):
	s = list(input())
	z = []
	f = False
	for i in range(len(s)):
		if s[i] == '1':
			if f:
				z[-1] += 1
			else:
				z.append(1)
				f = True
		else:
			f = False
	z.sort(reverse=True)
	a = sum(z[::2])
	print(a)


test = int(input())
while test:
	s = input()
	arr = s.split('0')
	arr.sort(reverse=True)
	ans = 0
	for i in range(0, len(arr)):
		if i % 2 == 0:
			ans = ans + len(arr[i])
	print(ans)
	test = test - 1


t = int(input())
for i in range(t):
	s = input()
	al = 0
	bo = 0
	c = 0
	count = []
	i = 0
	while i < len(s):
		if s[i] == '1':
			while i < len(s) and s[i] == '1':
				c = c + 1
				i = i + 1
			count.append(c)
			c = 0
		else:
			while i < len(s) and s[i] == '0':
				i = i + 1
	a = 0
	while len(count):
		if a == 0:
			al = al + max(count)
			count.remove(max(count))
			a = 1
		else:
			bo = bo + max(count)
			count.remove(max(count))
			a = 0
	print(al)


for _ in range(int(input())):
	a = input()
	b = []
	ss = 0
	for i in a:
		if i == '0':
			if ss:
				b.append(ss)
				ss = 0
		else:
			ss += 1
	if ss:
		b.append(ss)
	b.sort(reverse=True)
	print(sum(b[::2]))


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

def gift():
	for _ in range(t):
		string = input()
		n = len(string)
		moves = []
		curr = 0
		if string[0] == '1':
			curr += 1
		for i in range(1, n):
			if string[i] == '1':
				curr += 1
			else:
				if curr:
					moves.append(curr)
				curr = 0
		if curr:
			moves.append(curr)
		moves.sort(reverse=True)
		m = len(moves)
		if m == 0:
			yield 0
		else:
			ans = 0
			for i in range(0, m, 2):
				ans += moves[i]
			yield ans
t = int(input())
ans = gift()
print(*ans, sep='\n')


for _ in range(int(input())):
	s = input()
	ans = []
	t = 0
	for i in s:
		if i == '1':
			t += 1
		else:
			if t:
				ans.append(t)
			t = 0
	ans.append(t)
	ans.sort(reverse=True)
	m = 0
	for i in range(0, len(ans), 2):
		m += ans[i]
	print(m)


for _ in range(int(input())):
	s = input()
	t = 0
	count = 0
	alice = 0
	lis = []
	while t < len(s):
		if s[t] == '1':
			count += 1
		else:
			if count > 0:
				lis.append(count)
			count = 0
		t += 1
	lis.append(count)
	lis.sort(reverse=True)
	for z in range(len(lis)):
		if z % 2 == 0:
			alice += lis[z]
	print(alice)


t = int(input())
for _ in range(t):
	l1 = [len(x) for x in list(input().split('0')) if x]
	l1.sort(reverse=True)
	i = 0
	ans = 0
	while i < len(l1):
		ans += l1[i]
		i += 2
	print(ans)


from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007
tc = ii1()
for _ in range(tc):
	s = is1()
	count = []
	cur = 0
	flag = False
	for i in s:
		if i == '1':
			if not flag:
				flag = True
				cur += 1
			else:
				cur += 1
		elif flag:
			count.append(cur)
			cur = 0
			flag = False
	if cur > 0:
		count.append(cur)
	count.sort(reverse=True)
	ans = 0
	for i in range(len(count)):
		if i % 2 == 0:
			ans += count[i]
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	count = 0
	ls = []
	for j in range(len(s)):
		if s[j] == '1':
			count += 1
		else:
			ls.append(count)
			count = 0
	ls.append(count)
	ls.sort()
	sum1 = 0
	for j in range(len(ls) - 1, -1, -2):
		sum1 += ls[j]
	print(sum1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = list(input().rstrip().split('0'))
	res = []
	for a in s:
		if a != '':
			res.append(len(a))
	res.sort()
	n = len(res)
	ans = 0
	for i in range(n - 1, -1, -2):
		ans += res[i]
	print(ans)


a = int(input())
for i in range(a):
	(l, i) = ([], 0)
	t = input()
	while i < len(t):
		if t[i] == '1':
			count = 0
			while i < len(t) and t[i] != '0':
				count += 1
				i += 1
			l.append(count)
		else:
			i += 1
	sumi = 0
	l.sort(reverse=True)
	for j in range(0, len(l), 2):
		sumi += l[j]
	print(sumi)


for _ in range(int(input())):
	s = input()
	n = len(s)
	arr = []
	curr = 0
	i = 0
	while i < n:
		if s[i] == '1':
			curr += 1
			if i == n - 1:
				arr.append(curr)
		else:
			arr.append(curr)
			curr = 0
		i += 1
	arr.sort(reverse=True)
	ans = 0
	for i in range(0, len(arr), 2):
		ans += arr[i]
	print(ans)


for _ in range(int(input())):
	s = input()
	a = s.split('0')
	l = []
	for i in range(len(a)):
		l.append(len(a[i]))
	l.sort(reverse=True)
	total = 0
	for j in range(len(l)):
		if j % 2 == 0:
			total += l[j]
	print(total)


def solve():
	a = input()
	q = a.split('0')
	w = [i for i in q if i != '']
	w.sort(reverse=True)
	ans = 0
	for i in range(0, len(w), 2):
		ans += len(w[i])
	return ans
t = int(input())
ans = []
while t:
	ans.append(str(solve()))
	t -= 1
print('\n'.join(ans))


T = int(input())
for case in range(T):
	s = input()
	ones = []
	flag = False
	for c in s:
		if c == '1':
			if flag:
				new_one += 1
			else:
				new_one = 1
				flag = True
		elif flag:
			ones.append(new_one)
			new_one = 1
			flag = False
	if flag:
		ones.append(new_one)
	ones.sort()
	n = len(ones)
	a = 0
	for i in range((n + 1) // 2):
		a += ones[-(2 * i) - 1]
	print(a)


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
import math
import heapq
i_m = 9223372036854775807

def inin():
	return int(input())

def stin():
	return input()

def spin():
	return map(int, stin().split())

def lin():
	return list(map(int, stin().split()))

def matrix(n):
	return [list(map(int, input().split())) for i in range(n)]

def calculate_sum(a, N):
	m = N / a
	sum = m * (m + 1) / 2
	ans = a * sum
	return ans

def series(N):
	return N * (N + 1) // 2

def count2Dmatrix(i, list):
	return sum((c.count(i) for c in list))

def modinv(n, p):
	return pow(n, p - 2, p)

def GCD(x, y):
	x = abs(x)
	y = abs(y)
	if min(x, y) == 0:
		return max(x, y)
	while y:
		(x, y) = (y, x % y)
	return x

def LCM(x, y):
	return x * y // GCD(x, y)

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 isprime(n):
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True
prime = []

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j
for _ in range(inin()):
	s = list(stin())
	c = []
	(i, temp) = (0, 0)
	while i < len(s):
		if s[i] == '1':
			temp += 1
			if i == len(s) - 1:
				c.append(temp)
		else:
			if temp > 0:
				c.append(temp)
			temp = 0
		i += 1
	c = sorted(c)[::-1]
	s = 0
	for i in range(0, len(c), 2):
		s += c[i]
	print(s)


def solve():
	s = input()
	clusters = [0]
	for i in range(len(s)):
		if s[i] == '0':
			if clusters[-1] != 0:
				clusters.append(0)
		else:
			clusters[-1] += 1
	clusters.sort(reverse=True)
	ans = sum((clusters[i] for i in range(0, len(clusters), 2)))
	return ans
tn = int(input())
for _ in range(tn):
	print(solve())


for _ in range(int(input())):
	s = input()
	s = s.split('0')
	ar = []
	for i in s:
		if i == '':
			s.remove(i)
	for i in s:
		t = i.count('1')
		ar.append(t)
		t = 0
	ar = sorted(ar, reverse=True)
	print(sum(ar[0::2]))


def next_index_of(line, start, char):
	for index in range(start, len(line)):
		if line[index] == char:
			return index
	return len(line)

def find_ones(line):
	res = []
	left = -1
	right = -1
	start = 0
	while True:
		right = next_index_of(line, left + 1, '0')
		if right - left - 1 > 0:
			res.append(right - left - 1)
		left = right
		if right == len(line):
			break
	return res
	print(res)
for _ in range(int(input())):
	line = input()
	ones = find_ones(line)
	ones.sort(reverse=True)
	print(sum((ones[x] for x in range(len(ones)) if x % 2 == 0)))


t = int(input())
for i in range(t):
	s = input()
	l = []
	cnt = 0
	for i in range(len(s)):
		if s[i] == '1':
			cnt += 1
		elif cnt != 0:
			l.append(cnt)
			cnt = 0
	if cnt != 0:
		l.append(cnt)
	l.sort(reverse=1)
	s = 0
	for i in range(0, len(l), 2):
		s = s + l[i]
	print(s)


for i in range(int(input())):
	n = list(input())
	if n.count('1') == n:
		print(n)
	elif n.count('1') == 0:
		print(0)
	else:
		final = []
		count = 0
		fuck = 0
		ans = []
		for i in range(len(n)):
			if n[i] == '1':
				count += 1
			if n[i] == '0':
				ans.append(count)
				count = 0
		ans.append(count)
		for i in ans:
			if i != 0:
				final.append(i)
		final.sort(reverse=True)
		for i in range(len(final)):
			if i % 2 == 0:
				fuck += final[i]
		print(fuck)


t = int(input())
for _ in range(t):
	s = input()
	arr = []
	count = 0
	s = s + '0'
	for i in range(len(s)):
		if s[i] == '1':
			count += 1
		if s[i] == '0':
			arr.append(count)
			count = 0
	arr = sorted(arr, reverse=True)
	ans = 0
	if len(arr) == 0:
		print('0')
		continue
	for i in range(0, len(arr), 2):
		ans += arr[i]
	print(ans)


n = int(input())
for i in range(n):
	l = []
	s = str(input())
	e = 0
	for j in range(0, len(s)):
		if s[j] == '1':
			e = e + 1
		else:
			l.append(e)
			e = 0
	l.append(e)
	g = 0
	f = 0
	while len(l) >= 1:
		c = max(l)
		f = f + c
		l.remove(c)
		if len(l) > 0:
			d = max(l)
			g = g + d
			l.remove(d)
	print(max(f, g))


for test in range(0, int(input())):
	s = input()
	arr = s.split('0')
	arr = sorted(arr, reverse=True)
	count = 0
	for i in range(0, len(arr), 2):
		if arr[i] != '':
			count += arr[i].count('1')
	print(count)


def f(s):
	print(s)
	a = 0
	b = 0
	turn = 1
	m = 0
	ind = 0
	while len(s) and s.count('1'):
		r = []
		l = 0
		start = 0
		for i in range(len(s)):
			if s[i] == '1':
				if l == 0:
					start = i
				l += 1
			else:
				if l != 0:
					r.append([l, start])
					if m < l:
						m = l
						ind = start
				l = 0
		if l != 0:
			r.append([l, start])
			if m < l:
				m = l
				ind = start
	return a

def fun(s):
	a = 0
	r = []
	l = 0
	for i in range(len(s)):
		if s[i] == '1':
			l += 1
		else:
			if l != 0:
				r.append(l)
			l = 0
	if l != 0:
		r.append(l)
	r = sorted(r, reverse=True)
	for i in range(0, len(r), 2):
		a += r[i]
	return a
for _ in range(int(input())):
	s = input()
	print(fun(s))


def largest_sub(li, a, b):
	i = 0
	res = 0
	j = 0
	while i < len(li):
		j = i
		if li[i] == '1' and (not (i == a and i == b)):
			k = j
			while li[j] == '1' and (not (i == a and i == b)):
				j = j + 1
				if j >= len(li):
					break
			if j - k > res:
				res = j - k
				a = k
				b = j
		if i == j:
			i = i + 1
		else:
			i = j
	return (a, b, res)

def bit_game(li):
	h = 0
	a = -1
	b = -2
	c1 = 0
	c2 = 0
	while li.count('1') > 0:
		if h % 2 == 0:
			(a, b, n) = largest_sub(li, a, b)
			c1 = c1 + n
		else:
			(a, b, n) = largest_sub(li, a, b)
			c2 = c2 + n
		li = li[:a] + li[b:]
		h = h + 1
	print(c1)
t = int(input())
for i in range(t):
	li = str(input())
	bit_game(li)


for vishal in range(int(input())):
	s = input()
	nums = []
	i = 0
	while i < len(s):
		j = i + 1
		while j < len(s) and s[j] == s[i]:
			j += 1
		if s[i] == '1':
			nums.append(j - i)
		i = j
	nums.sort()
	nums.reverse()
	print(sum([nums[i] for i in range(len(nums)) if i % 2 == 0]))


for _ in range(int(input())):
	s = [int(i) for i in input()]
	a = 1
	count = 0
	lis = []
	for i in range(len(s)):
		if s[i] == a:
			count += 1
		elif a == 1:
			lis.append(count)
			a = 0
			count = 0
		else:
			count = 1
			a = 1
	if a == 1:
		lis.append(count)
	lis.sort()
	lis.reverse()
	ans = 0
	for i in range(0, len(lis), 2):
		ans += lis[i]
	print(ans)


for i in range(int(input())):
	a = input()
	count = []
	k = -1
	for (z, x) in enumerate(a):
		if x == '1':
			if z == 0 or a[z - 1] == '0':
				k += 1
				count.append(1)
			else:
				count[k] += 1
	count.sort(reverse=True)
	sum = 0
	for z in range(0, len(count), 2):
		sum += count[z]
	print(sum)


import math

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

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

def bs(arr, l, r, x):
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return arr[mid]
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def swap(list, pos1, pos2):
	(list[pos1], list[pos2]) = (list[pos2], list[pos1])
	return list

def subarrayBitwiseOR(A):
	res = set()
	pre = {0}
	for x in A:
		pre = {x | y for y in pre} | {x}
		res |= pre
	return len(res)
t = int(input())
for _ in range(t):
	s = input()
	a = []
	c = 0
	for i in s:
		if i == '1':
			c += 1
		else:
			a.append(c)
			c = 0
	if c > 0:
		a.append(c)
	a.sort(reverse=True)
	al = 0
	for i in range(0, len(a), 2):
		al += a[i]
	print(al)


t = int(input())
for test in range(t):
	s = input()
	s = list(s)
	for item in s:
		item = int(item)
	n = len(s)
	for i in range(n):
		s[i] = int(s[i])
	ones = []
	i = 0
	while i < n:
		if s[i] == 1:
			count = 0
			while i < n and s[i] == 1:
				count += 1
				i += 1
			ones.append(count)
		else:
			while i < n and s[i] == 0:
				i += 1
	ones.sort()
	ones.reverse()
	delta = len(ones)
	ans = 0
	for i in range(0, delta, 2):
		ans += ones[i]
	print(ans)


from itertools import groupby
t = int(input())
for _ in range(t):
	s = input()
	groups = groupby(s)
	result = [(label, sum((1 for _ in group))) for (label, group) in groups if label == '1']
	b = []
	for i in range(len(result)):
		b.append(result[i][1])
	b.sort(reverse=True)
	if len(b) == 0:
		print(0)
	else:
		print(sum(b[::2]))


test = int(input())
while test > 0:
	test = test - 1
	num = input()
	li = num.split('0')
	li.sort(reverse=True)
	(i, c, cnt) = (0, 0, 0)
	while i <= len(li) - 1:
		if li[i] == '':
			break
		else:
			cnt = li[i].count('1')
			c = c + cnt
			i = i + 2
	print(c)


T = int(input())
for case in range(T):
	s = list(map(int, list(input())))
	blockLengths = []
	n = len(s)
	length = 0
	for i in range(n):
		if s[i] == 0:
			if length > 0:
				blockLengths.append(length)
				length = 0
		else:
			length += 1
	if length > 0:
		blockLengths.append(length)
	n = len(blockLengths)
	alice = 0
	for i in range(n):
		maxBlockLength = max(blockLengths)
		blockLengths.remove(maxBlockLength)
		if i % 2 == 0:
			alice += maxBlockLength
	print(alice)


t = int(input())
for _ in range(t):
	s = input()
	result = []
	index = 0
	while index < len(s):
		if s[index] == '0':
			index += 1
		else:
			left = index
			while index < len(s) and s[index] == '1':
				index += 1
			result.append(index - left)
	result.sort(reverse=True)
	answer = sum((result[i] for i in range(len(result)) if i % 2 == 0))
	print(answer)


t = int(input())
total = list()
for i in range(t):
	s = list(input())
	s.append('0')
	s.append('0')
	total.clear()
	j = 0
	while j < len(s) - 1:
		if s[j] == '1':
			total.append(int(1))
			while s[j + 1] == '1':
				total[-1] = total[-1] + 1
				j = j + 1
		j = j + 1
	total.sort()
	sum = 0
	if len(total) % 2 == 1:
		for k in range(len(total)):
			if k % 2 == 0:
				sum = sum + total[k]
	else:
		for k in range(len(total)):
			if k % 2 == 1:
				sum = sum + total[k]
	print(sum)


for _ in range(int(input())):
	s = input()
	t = s.split('0')
	t.sort(reverse=True, key=len)
	alice = 0
	for i in range(len(t)):
		if i % 2 == 0 and t[i] != '':
			alice += len(t[i])
	print(alice)


t = int(input())
for _ in range(t):
	s = [int(i) for i in input().strip()]
	n = len(s)
	bckt = []
	ct = 0
	for i in range(n):
		if s[i]:
			ct += 1
		elif ct:
			bckt.append(ct)
			ct = 0
	if ct:
		bckt.append(ct)
	bckt.sort(reverse=True)
	print(sum(bckt[::2]))


from sys import stdin, stdout
from math import sqrt, gcd, ceil, floor, log2, log10, factorial, cos, acos, tan, atan, atan2, sin, asin, radians, degrees, hypot
from bisect import insort, insort_left, insort_right, bisect_left, bisect_right, bisect
from array import array
from functools import reduce
from itertools import combinations, combinations_with_replacement, permutations
from fractions import Fraction
from random import choice, getrandbits, randint, random, randrange, shuffle
from re import compile, findall, escape
from statistics import mean, median, mode
from heapq import heapify, heappop, heappush, heappushpop, heapreplace, merge, nlargest, nsmallest
for test in range(int(stdin.readline())):
	s = input()
	l = findall('1+', s)
	lengths = [len(i) for i in l]
	lengths.sort(reverse=True)
	alice = 0
	for i in range(0, len(lengths), 2):
		alice += lengths[i]
	print(alice)


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	a = []
	(i, cur) = (0, 0)
	while i < n:
		if s[i] == '1':
			cur += 1
		elif cur != 0:
			a.append(cur)
			cur = 0
		i += 1
	if cur:
		a.append(cur)
	a.sort(reverse=True)
	print(sum((ai for (i, ai) in enumerate(a) if i % 2 == 0)))


t = int(input())
for _ in range(t):
	r = input()
	r = list(r)
	a = []
	k = 0
	for i in range(len(r)):
		if r[i] == '1':
			k += 1
		else:
			a.append(k)
			k = 0
	a.append(k)
	a.sort(reverse=True)
	ans = 0
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)


for _ in range(int(input())):
	string = input()
	if string.count('1') == len(string):
		print(len(string))
	elif string.count('1') == len(string):
		print('0')
	else:
		c = 1
		total = 0
		arr = string.split('0')
		lst = []
		for i in arr:
			if i != '':
				lst.append(i)
		while len(lst) != 0:
			pos = 0
			for i in lst:
				if len(i) == max(map(len, lst)):
					if c == 1:
						total += len(i)
						lst.pop(pos)
						c = 0
						break
					else:
						lst.pop(pos)
						c = 1
						break
				else:
					pos += 1
		print(total)


t = int(input())
while t:
	n = input()
	ones_list = []
	i = 0
	while i < len(n):
		if n[i] == '1':
			temp = str(n[i])
			if i + 1 < len(n):
				while n[i + 1] == '1':
					i = i + 1
					temp = temp + str(n[i])
					if i + 1 == len(n):
						break
			ones_list.append(temp)
		i = i + 1
	ones_list.sort(reverse=True)
	i = 0
	solution = 0
	while i < len(ones_list):
		solution = solution + len(ones_list[i])
		if i + 2 < len(ones_list):
			i = i + 2
		else:
			break
	print(solution)
	t = t - 1


t = int(input())
for _ in range(t):
	s = str(input())
	X = []
	cnt = 0
	for i in range(len(s)):
		if s[i] != '1':
			if cnt:
				X.append(cnt)
				cnt = 0
		else:
			cnt += 1
	else:
		if cnt != 0:
			X.append(cnt)
	X.sort(reverse=True)
	ans = 0
	for (i, e) in enumerate(X):
		if i % 2 == 0:
			ans += e
	print(ans)


for i in range(int(input())):
	s = list(filter(lambda x: x != '', input().split('0')))
	s.sort(reverse=True)
	pr = ''
	for i in range(0, len(s), 2):
		pr += s[i]
	print(len(pr))


T = int(input())

def ans(A):
	A = A + '0'
	blocks = []
	last = 0
	for c in A:
		if c == '0':
			if last > 0:
				blocks += [last]
			last = 0
		else:
			last += 1
	blocks = sorted(blocks)[::-1]
	return sum(blocks[::2])
for t in range(T):
	print(ans(input()))


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
stdarr = lambda : map(int, stdstr().split())
mod = 1000000007
for _ in range(stdint()):
	s = input()
	p = [0]
	f = -1
	for i in range(len(s)):
		if s[i] == '1':
			f = i
			break
	if f == -1:
		print(0)
		continue
	for i in range(f, len(s)):
		if i == f:
			l = '1'
			p[-1] += 1
		else:
			if s[i] == l == '1':
				p[-1] += 1
			elif s[i] != l and s[i] == '1':
				p.append(0)
				p[-1] += 1
			elif s[i] == '0':
				l = s[i]
				continue
			l = s[i]
	p = sorted(p, reverse=True)
	res = 0
	for i in range(len(p)):
		if i % 2 == 0:
			res += p[i]
	print(res)


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

class union_find:

	def __init__(self, n):
		self.n = n
		self.rank = [0] * n
		self.parent = [int(j) for j in range(n)]

	def union(self, i, j):
		i = self.find(i)
		j = self.find(j)
		if self.rank[i] == self.rank[j]:
			self.parent[i] = j
			self.rank[j] += 1
		elif self.rank[i] > self.rank[j]:
			self.parent[j] = i
		else:
			self.parent[i] = j

	def find(self, i):
		temp = i
		if self.parent[temp] != temp:
			self.parent[temp] = self.find(self.parent[temp])
		return self.parent[temp]
from math import log2, ceil
from collections import deque, Counter as CC

def main():
	for t in range(int(input())):
		s = input()
		n = len(s)
		l = []
		tmp = 0
		for i in range(n):
			if s[i] == '1':
				tmp += 1
			elif tmp != 0:
				l.append(tmp)
				tmp = 0
		if tmp != 0:
			l.append(tmp)
		l.sort(reverse=True)
		ans = 0
		for i in range(0, len(l), 2):
			ans += l[i]
		print(ans)
main()


def solve():
	T = int(input())
	ans = [0] * T
	for t in range(T):
		S = input()
		lis = [int(S[0])]
		for i in range(1, len(S)):
			if S[i] == '1':
				lis[-1] += 1
			elif S[i] == '0' and S[i - 1] == '1':
				lis.append(0)
		lis.sort(reverse=True)
		ans[t] = sum(lis[0::2])
	return ans
print(*solve(), sep='\n')


import sys
input = sys.stdin.readline
inputLines = sys.stdin.readlines

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

def readStrList():
	return list(map(lambda x: x.strip(), inputLines()))

def indexOf(l: list, elem: int):
	return l.index(elem) if elem in l else -1

def lastIndexOf(l: list, elem: int):
	indexes = [idx for (idx, val) in enumerate(l) if val == elem]
	return max(indexes) if len(indexes) > 0 else -1

def solution():
	for _ in range(int(input())):
		arr = [char for char in input()]
		resArr = []
		counter = 0
		for i in range(len(arr)):
			if arr[i] == '1':
				counter += 1
			else:
				resArr.append(counter)
				counter = 0
			if i == len(arr) - 1 and counter > 0:
				resArr.append(counter)
		resArr.sort(reverse=True)
		print(sum([x for (ind, x) in enumerate(resArr) if ind % 2 == 0]))
solution()


casos = int(input())
for c in range(casos):
	string = input()
	um = []
	aux = 0
	for v in range(len(string)):
		if string[v] == '1':
			aux += 1
		elif aux != 0:
			um.append(aux)
			aux = 0
	um.append(aux)
	vez = True
	alice = 0
	um.sort()
	for v in range(len(um) - 1, -1, -1):
		if vez:
			alice += um[v]
			vez = False
		else:
			vez = True
	print(alice)


t = int(input())
for _ in range(t):
	s = input()
	spans = []
	l = 0
	for i in s:
		if i == '1':
			l += 1
		elif l != 0:
			spans.append(l)
			l = 0
	if l != 0:
		spans.append(l)
	spans.sort(reverse=True)
	n = len(spans)
	alice = 0
	for i in range(0, n, 2):
		alice += spans[i]
	print(alice)


t = int(input())
for _ in range(t):
	s = input()
	f = [len(x) for x in s.replace('0', ' ').split()]
	f.sort(reverse=True)
	res = 0
	for (index, v) in enumerate(f):
		if index % 2 == 0:
			res += v
	print(res)


import re
from sys import stdin
for _ in range(int(stdin.readline())):
	a = sorted(re.split('0+', stdin.readline().rstrip()), reverse=True)
	print(sum([len(x) for x in a[::2]]))


t = int(input())
for r in range(t):
	s = input()
	cnt = 0
	game = 0
	go = True
	while go:
		max = [0, 0]
		ok = False
		i = 0
		j = 0
		while j < len(s) and i < len(s):
			if s[j] == '1':
				ok = True
				j += 1
				if j - i > max[1] - max[0]:
					max = [i, j]
			else:
				if j - i > max[1] - max[0]:
					max = [i, j]
				j += 1
				i = j
		if not ok:
			go = False
		else:
			s = s[:max[0]] + s[max[1]:]
			if game % 2 == 0:
				cnt += max[1] - max[0]
			game += 1
	print(cnt)


T = int(input())
for t in range(1, T + 1):
	lst = input().split('0')
	while '' in lst:
		lst.remove('')
	N = len(lst)
	if lst == []:
		print(0)
		continue
	answer = 0
	for i in range(N):
		for j in range(N - 1):
			if len(lst[j + 1]) > len(lst[j]):
				tmp = lst[j + 1]
				lst[j + 1] = lst[j]
				lst[j] = tmp
	for i in range(N):
		if i % 2 == 0:
			answer += len(lst[i])
	print(answer)


for i in range(int(input())):
	n = list(input().split('0'))
	n.sort(reverse=True)
	print(sum([len(n[x]) for x in range(len(n)) if x % 2 == 0 and n[x] > '']))


t = int(input())
while t > 0:
	s = input()
	arr1 = list(map(int, s))
	b = arr1.count(0)
	if b == 0:
		print(len(arr1))
		t = t - 1
		continue
	arr2 = list()
	arr3 = list()
	arr4 = list()
	n = len(arr1)
	l = 0
	r = 0
	for i in range(1, n + 1):
		if arr1[i - 1] == 0:
			arr2.append(i)
	if len(arr2) == 1:
		if arr2[0] == 1 or arr2[0] == n:
			print(sum(arr1))
		elif arr2[0] != 1 or arr2[0] == n:
			l = arr2[0] - 1
			r = n - arr2[0]
			if l > r:
				print(l)
			else:
				print(r)
	else:
		j = 0
		for j in range(len(arr2) - 1):
			if arr2[0] == 1:
				arr3.append(arr2[j + 1] - arr2[j] - 1)
			elif arr2[0] != 1:
				if j == 0:
					arr3.append(arr2[0] - 1)
				arr3.append(arr2[j + 1] - arr2[j] - 1)
		arr3.append(len(arr1) - arr2[len(arr2) - 1])
		arr4 = sorted(arr3, reverse=True)
		r = 0
		for k in range(len(arr4)):
			if k % 2 == 0:
				r = r + arr4[k]
		print(r)
	t = t - 1


vis = [0]
s = ''
cnt = 0

def dfs(i):
	if i == len(s):
		return 0
	if s[i] == '0' or vis[i] == 1:
		return 0
	vis[i] = 1
	return 1 + dfs(i + 1)
for _ in range(int(input())):
	s = input()
	l = len(s)
	vis = [0] * l
	res = []
	for i in range(l):
		if vis[i] == 0 and s[i] == '1':
			cnt = 0
			cnt = dfs(i)
			res.append(cnt)
	result = 0
	res.sort(reverse=True)
	for i in range(len(res)):
		if i % 2 == 0:
			result += res[i]
	print(result)


import sys
input = sys.stdin.readline

def inInt():
	return int(input())

def inStr():
	return input().strip('\n')

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

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

def solve(s):
	count = 0
	ones = []
	for i in range(len(s)):
		if s[i] == '1':
			count = count + 1
		if s[i] == '0':
			ones.append(count)
			count = 0
	ones.append(count)
	ones = sorted(ones)
	s = 0
	for n in range(len(ones) - 1, -1, -2):
		s = s + ones[n]
	print(s)
tests = inInt()
for t in range(tests):
	s = inStr()
	solve(s)


t = int(input())
for x in range(t):
	a = []
	s = input()
	x = 0
	alice = 0
	while x < len(s):
		temp = 0
		if s[x] == '1':
			y = x + 1
			temp = 1
			while y < len(s) and s[y] == '1':
				temp += 1
				y += 1
			else:
				a.append(temp)
		if temp == 0:
			x += 1
		else:
			x += temp
	a.sort(reverse=True)
	c = 0
	for x in a:
		if c % 2 == 0:
			alice += x
		c += 1
	print(alice)


def main():
	t = int(input())
	for i in range(t):
		s = input().rstrip()
		ones = []
		cur = 0
		prev = ''
		for s_i in s:
			if s_i == '1':
				cur += 1
				prev = '1'
			elif prev == '1':
				ones.append(cur)
				cur = 0
				prev = '0'
		if cur > 0:
			ones.append(cur)
		ones.sort(reverse=True)
		sum = 0
		for j in range(0, len(ones), 2):
			sum += ones[j]
		print(sum)
main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = input()
	lst = []
	dupl = 1
	for i in range(len(s) - 1):
		if s[i] == '1':
			if s[i] == s[i + 1]:
				dupl += 1
			else:
				lst.append(dupl)
				dupl = 1
		else:
			dupl = 1
	lst = sorted(lst, reverse=True)
	summ = 0
	for i in range(0, len(lst), 2):
		summ += lst[i]
	print(summ)


import sys
LI = lambda : list(map(int, sys.stdin.readline().strip('\n').split()))
MI = lambda : map(int, sys.stdin.readline().strip('\n').split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline().strip('\n'))
for _ in range(II()):
	s = SI()
	cnt = []
	num = 0
	for c in s:
		if c == '1':
			num += 1
		else:
			if num:
				cnt.append(num)
			num = 0
	if num:
		cnt.append(num)
	cnt.sort(reverse=True)
	ans = 0
	for (i, v) in enumerate(cnt):
		if i % 2 == 0:
			ans += v
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	c = 0
	x = []
	for j in range(len(s)):
		if s[j] == '1':
			c += 1
		else:
			x.append(c)
			c = 0
	if c != 0:
		x.append(c)
	x.sort()
	x = x[::-1]
	sum = 0
	for k in range(0, len(x), 2):
		sum += x[k]
	print(sum)


t = int(input())
for i in range(t):
	s = input()
	alice = 0
	bob = 0
	s = list(s)
	a = []
	a1 = 0
	for j in range(len(s)):
		if s[j] == '0':
			if a1 == 0:
				a.append(0)
			else:
				a.append(a1)
				a1 = 0
				a.append(0)
		elif s[j] == '1':
			a1 = a1 + int(s[j])
	if a1 != 0:
		a.append(a1)
	while sum(a) > 0:
		alice = alice + max(a)
		a.remove(max(a))
		if sum(a) <= 0:
			break
		bob = bob + max(a)
		a.remove(max(a))
	print(alice)


t = int(input())
for _ in range(t):
	a = input().split('0')
	l = list()
	for i in a:
		if any([i == ' ', i == '']):
			pass
		else:
			l.append(i)
	l.sort(reverse=True, key=lambda x: len(x))
	count = 0
	for i in range(0, len(l), 2):
		count += len(l[i])
	print(count)


import sys
from collections import defaultdict
for i in range(int(input())):
	s = input()
	l = []
	c = 0
	for i in s:
		if i == '1':
			c += 1
		elif c != 0:
			l.append(c)
			c = 0
	if c != 0:
		l.append(c)
	l.sort(reverse=True)
	print(sum(l[::2]))


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def solve():
	for _ in range(ii()):
		s = si()
		n = len(s)
		c = 0
		x = []
		for i in range(n):
			if s[i] == '0':
				if c > 0:
					x.append(c)
				c = 0
			else:
				c += 1
		x.append(c)
		x.sort(reverse=True)
		ans = 0
		f = 1
		for i in x:
			if f:
				ans += i
			f ^= 1
		print(ans)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


for _ in range(int(input())):
	a = input()
	t = []
	l = []
	i = 0
	for i in range(len(a)):
		if a[i] == '0':
			l.append(i)
	for i in range(1, len(l)):
		t.append(l[i] - l[i - 1] - 1)
	if len(l) == 0:
		print(len(a))
	else:
		t.append(len(a) - l[-1] - 1)
		t.append(l[0] - 0)
		t.sort(reverse=True)
		total = 0
		for i in range(len(t)):
			if i % 2 == 0:
				total += t[i]
		print(total)


t = int(input())
for g in range(t):
	a = list(input().split('0'))
	b = []
	for i in a:
		if i:
			b.append(len(i))
	b.sort()
	eve = 0
	odd = 0
	for i in range(len(b)):
		if i % 2 == 0:
			eve += b[i]
		else:
			odd += b[i]
	print(max(eve, odd))


for _ in range(int(input())):
	s = input()
	lis = []
	ctr = 0
	for i in range(len(s)):
		if s[i] == '0':
			lis.append(ctr)
			ctr = 0
		else:
			ctr += 1
	if ctr != 0:
		lis.append(ctr)
	lis.sort(reverse=True)
	total = 0
	for i in range(0, len(lis), 2):
		total += lis[i]
	print(total)


T = int(input())
for _ in range(T):
	s = input()
	s += '0'
	sta = -1
	end = 0
	true = []
	fl = '1'
	t = 0
	for i in range(len(s)):
		if s[i] == fl:
			end = i
			t = 1
		else:
			if t == 1:
				true.append(end - sta)
			t = 0
			sta = i
			continue
	true.sort(reverse=True)
	ans = 0
	for i in range(0, len(true), 2):
		ans += true[i]
	print(ans)


from math import *
from cmath import *
from itertools import *
from decimal import *
from fractions import *
from sys import *
for _ in range(int(input())):
	s = input()
	a = []
	dem = int(s[0] == '1')
	for x in range(1, len(s)):
		if s[x] == s[x - 1]:
			dem += 1
		else:
			if s[x - 1] == '1':
				a.append(dem)
			dem = 1
	if s[len(s) - 1] == '1':
		a.append(dem)
	a.sort(reverse=True)
	print(sum(a[::2]))


t = int(input())
for i in range(t):
	s = input()
	k = 0
	cnt = 0
	while True:
		if k == 0:
			all = s.split('0')
			mx = max(all)
			cnt += len(mx)
			if len(mx) == 0:
				break
			else:
				s = s.replace(mx, '', 1)
		else:
			all = s.split('0')
			mx = max(all)
			if len(mx) == 0:
				break
			else:
				s = s.replace(mx, '', 1)
		k = (k + 1) % 2
	print(cnt)


t = int(input())
for _ in range(t):
	a = list(input())

	def max_one_len():
		res = 0
		c = 0
		for i in range(len(a)):
			if a[i] == '1':
				c += 1
				res = max(res, c)
			else:
				c = 0
		k = 0
		for i in range(len(a)):
			if a[i] == '1':
				k += 1
				if k == res:
					for j in range(i - k + 1, i + 1):
						a[j] = 0
					break
			else:
				k = 0
		return res
	flag = 'A'
	ans = 0
	while '1' in a:
		if flag == 'A':
			ans += max_one_len()
			flag = 'B'
		else:
			max_one_len()
			flag = 'A'
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	s = list(s)
	sc = []
	c = 0
	n = len(s)
	for i in range(n):
		if s[i] == '1':
			c += 1
		else:
			if c > 0:
				sc.append(c)
			c = 0
	if c > 0:
		sc.append(c)
	sc.sort()
	res = 0
	for i in range(len(sc) - 1, -1, -2):
		res += sc[i]
	print(res)


t = int(input())
a = []
for i in range(t):
	s = input()
	t2 = 0
	t3 = 0
	a = []
	for j in range(len(s)):
		if s[j] == '1':
			t2 += 1
		elif t2 > 0:
			a.append(t2)
			t2 = 0
	if t2 > 0:
		a.append(t2)
	a.sort()
	for j in range(len(a) - 1, -1, -2):
		t3 += a[j]
	print(t3)


import math
from collections import *
import sys
from functools import reduce
import time
from itertools import groupby

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

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=' ')
for _test_ in range(int(input())):
	s = input()
	g = groupby(s)
	bits = []
	for (ke, val) in g:
		if ke == '1':
			val = list(val)
			bits.append(len(val))
	bits.sort(reverse=True)
	ans = 0
	for i in range(len(bits)):
		if not i & 1:
			ans += bits[i]
	print(ans)


cases = int(input())
for tests in range(cases):
	string = input()
	one_list = []
	streak = 0
	ans = 0
	for num in string:
		if num == '1':
			streak += 1
		else:
			one_list.append(streak)
			streak = 0
	one_list.append(streak)
	one_list.sort(reverse=True)
	for index in range(len(one_list)):
		if index % 2 == 0:
			ans += one_list[index]
	print(ans)


answers = []
for _ in range(int(input())):
	S = input().split('0')
	l = [len(s) for s in S if len(s) > 0]
	l = sorted(l, reverse=True)
	score = sum(l[0::2])
	answers.append(score)
for score in answers:
	print(score)


from sys import stdin
inf = 1000000001
for _ in range(int(input())):
	s = input()
	c = []
	cur = 0
	for i in s:
		if i == '0':
			if cur:
				c.append(cur)
			cur = 0
		else:
			cur += 1
	if cur:
		c.append(cur)
	c.sort(reverse=True)
	r = 0
	for i in range(0, len(c), 2):
		r += c[i]
	print(r)


import sys
import math, bisect
from collections import defaultdict
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, OrderedDict

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

def Neo():
	return list(map(int, input().split()))
for _ in range(int(input())):
	s = input()
	res = [len(list(j)) for (_, j) in groupby(list(s))]
	if s[0] == '0':
		A = res[1::2]
	else:
		A = res[0::2]
	A.sort(reverse=True)
	B = A[0::2]
	print(sum(B))


t = int(input())
while t:
	t -= 1
	s = input()
	s = [i for i in s]
	count_array = []
	c = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
		elif s[i] == '0':
			if c != 0:
				count_array.append(c)
				c = 0
	if s[-1] == '1':
		count_array.append(c)
	count_array.sort(reverse=True)
	score = 0
	for i in range(0, len(count_array), 2):
		score += count_array[i]
	print(score)


[print(sum((k for k in sorted(map(len, input().split('0')), reverse=1)[::2]))) for t in range(int(input()))]


for _ in range(int(input())):
	s = input()
	temp = []
	i = 0
	while i < len(s):
		if s[i] == '0':
			i += 1
		else:
			j = i + 1
			count = 1
			while j < len(s):
				if s[j] == '1':
					count += 1
				else:
					break
				j += 1
			temp.append(count)
			i = j
	temp.sort(reverse=True)
	ans = 0
	for a in range(len(temp)):
		if a % 2 == 0:
			ans += temp[a]
	print(ans)


import math
import collections
import bisect

def arrPrint(a):
	return ' '.join([str(i) for i in a])

def gridPrint(a):
	return '\n'.join([' '.join([str(j) for j in a[i]]) for i in range(len(a))])

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

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

def solve(s):
	if s == '0' * len(s):
		return 0
	splits = []
	start = s.index('1')
	for i in range(start, len(s)):
		if s[i] == '1' and s[i - 1] == '0':
			start = i
		elif s[i] == '0' and s[i - 1] == '1':
			splits.append(i - start)
	if s[-1] == '1':
		splits.append(len(s) - start)
	splits = sorted(splits, reverse=True)
	return sum([splits[i] for i in range(len(splits)) if i % 2 == 0])
t = int(input())
for _ in range(t):
	s = input()
	print(solve(s))


for t in range(int(input())):
	a = map(len, input().split('0'))
	print(sum(sorted(a, reverse=True)[0::2]))


def check(s):
	s = s.split('0')
	s = [len(i) for i in s]
	s = sorted(s, reverse=True)
	k = [j for (i, j) in enumerate(s) if i % 2 == 0]
	sum = 0
	for i in k:
		sum += i
	print(sum)
t = int(input())
for i in range(t):
	s = input()
	check(s)


def counta(s):
	s = sorted(list(filter(lambda x: x != '', s)), key=lambda x: x.count('1'), reverse=True)
	a = 0
	for i in range(0, len(s), 2):
		a += s[i].count('1')
	return a

def main():
	for _ in range(int(input())):
		s = input().split('0')
		print(counta(s))
main()


t = int(input())
while t:
	s = input()
	arr = []
	k = 0
	for i in s:
		if i == '1':
			k += 1
		else:
			arr.append(k)
			k = 0
	if k:
		arr.append(k)
	arr.sort(reverse=True)
	ans = 0
	for i in range(0, len(arr), 2):
		ans += arr[i]
	print(ans)
	t -= 1


from sys import stdin

def solve(arr):
	alice_score = 0
	alice_turn = True
	while len(arr) > 0:
		best_left = -1
		best_right = -1
		best_len = 0
		cur_len = 0
		i = 0
		while i < len(arr):
			if arr[i] == '1':
				cur_len = 1
				j = i + 1
				while j < len(arr):
					if arr[j] != '1':
						break
					j += 1
				j -= 1
				cur_len = j - i + 1
				if cur_len > best_len:
					best_left = i
					best_right = j
					best_len = cur_len
				i = j + 1
			else:
				i += 1
		if best_len == 0:
			return alice_score
		if alice_turn:
			alice_score += best_right - best_left + 1
		b4 = alice_turn
		alice_turn = not alice_turn
		arr = arr[:best_left] + arr[best_right + 1:]
	return alice_score
t = int(stdin.readline())
for _ in range(t):
	s = list(stdin.readline().rstrip())
	print(solve(s))


n = int(input())
for i in range(n):
	s = input()
	ones = sorted([x for x in s.split('0') if x != ''])[::-1]
	points = 0
	for i in range(len(ones)):
		if i % 2 == 0:
			points += len(ones[i])
	print(points)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	nList = list(input())
	cntList = []
	cnt = 0
	for i in range(len(nList)):
		if nList[i] == '1':
			cnt += 1
		else:
			cntList.append(cnt)
			cnt = 0
	cntList.sort(reverse=True)
	alice = 0
	for i in range(len(cntList)):
		if i % 2 == 0:
			alice += cntList[i]
	print(alice)


t = int(input())
for _ in range(t):
	s = input()
	ids = []
	acc = []
	a = s[0]
	c = 1
	for i in s[1:]:
		if i == a:
			c += 1
		else:
			ids.append(a)
			acc.append(c)
			a = i
			c = 1
	ids.append(a)
	acc.append(c)
	taccs = []
	for i in range(len(ids)):
		if ids[i] == '1':
			taccs.append(acc[i])
	taccs = sorted(taccs)[::-1]
	ans = 0
	for i in range(0, len(taccs), 2):
		ans += taccs[i]
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	d = []
	(count, r) = (0, 1)
	res = 0
	for j in range(len(s)):
		if s[j] == '1':
			count += 1
		elif count > 0:
			d.append(count)
			count = 0
		if j == len(s) - 1:
			d.append(count)
	while d != []:
		if r % 2 == 1:
			res += max(d)
			x = max(d)
			d.remove(x)
			x = 0
			r += 1
		else:
			x = max(d)
			d.remove(x)
			x = 0
			r += 1
	print(res)


from itertools import groupby
for _ in range(int(input())):
	s = input()
	l = sorted([len(list(g)) for (k, g) in groupby(s) if k == '1'], reverse=True)
	print(sum(l[::2]))


import sys
input = sys.stdin.readline
T = int(input())
for testcase in range(T):
	s = list(input())
	num = []
	tmp = 0
	for e in s:
		if e == '1':
			tmp += 1
		else:
			num.append(tmp)
			tmp = 0
	num.append(tmp)
	num.sort(reverse=True)
	res = 0
	for (i, e) in enumerate(num):
		if i % 2 == 0:
			res += e
	print(res)


for _ in range(int(input())):
	s = input()
	lst = []
	cnt = 0
	for i in s:
		if i == '1':
			cnt += 1
		elif i == '0' and cnt > 0:
			lst.append(cnt)
			cnt = 0
	lst.append(cnt)
	lst.sort(reverse=True)
	s = 0
	for i in range(0, len(lst), 2):
		s = s + lst[i]
	print(s)


t = int(input())
while t:
	s = input()
	l1 = []
	check = 0
	count = 0
	for i in s:
		if i == '1':
			check = 1
			count = count + 1
		elif check == 1:
			l1.append(count)
			count = 0
			check = 0
	l1.append(count)
	l1.sort()
	value = 0
	for i in range(len(l1) - 1, -1, -2):
		value = value + l1[i]
	print(value)
	t = t - 1


for _ in range(int(input())):
	s = list(input().split('0'))
	s.sort()
	x = 0
	for i in range(len(s)):
		if s[i]:
			x = i
			break
	s = s[x:]
	total = 0
	for i in range(len(s) - 1, -1, -2):
		total += len(s[i])
	print(total)


import math

def func():
	seq = input().split('0')
	total = 0
	for y in range(math.ceil(len(seq) / 2)):
		sort_seq = sorted(seq, reverse=True)
		if '1' in sort_seq[2 * y]:
			total = total + len(sort_seq[2 * y])
	return total
num_cases = int(input())
for x in range(num_cases):
	print(func())


def ans(S):
	l = len(S)
	Count = []
	c = 0
	for i in range(l):
		if S[i] == '1':
			c += 1
		elif c != 0:
			Count.append(c)
			c = 0
	if c != 0:
		Count.append(c)
	Count.sort(reverse=True)
	return sum(Count[0:l:2])
t = int(input())
L = []
for i in range(t):
	S = input()
	L.append(ans(S))
for l in L:
	print(l)


n = int(input())
for _ in range(n):
	s = input()
	l = []
	count = 0
	for i in range(len(s)):
		if s[i] == '0':
			if count != 0:
				l.append(count)
			count = 0
		else:
			count += 1
	if count != 0:
		l.append(count)
	l.sort(reverse=True)
	total = 0
	for i in range(0, len(l), 2):
		total += l[i]
	print(total)


for _ in range(int(input())):
	a = input()
	n = len(a)
	x = []
	c = 0
	for i in range(n):
		if a[i] == '1':
			c += 1
		else:
			x.append(c)
			c = 0
	if c != 0:
		x.append(c)
	x.sort(reverse=True)
	a = 0
	b = 0
	for i in range(len(x)):
		if i % 2 == 0:
			b += x[i]
		else:
			a += x[i]
	print(max(a, b))


for _ in range(int(input())):
	n = input()
	pre = n[0]
	result = []
	last = 0
	if pre == '1':
		count = 1
	else:
		count = 0
	for i in n[1:]:
		if i == '1' and pre == '0':
			count += 1
		elif i == '1' and pre == '1':
			count += 1
		elif i == '0' and pre == '1':
			result.append(count)
			count = 0
		pre = i
	if n[-1] == '1':
		result.append(count)
	result.sort(reverse=True)
	for i in range(0, len(result), 2):
		last += result[i]
	print(last)


T = int(input())
for _ in range(T):
	a = list(input())
	prev = a[0]
	currlen = 1 if a[0] == '1' else 0
	ones = []
	for i in range(1, len(a)):
		curr = a[i]
		if prev == '1':
			if curr == '1':
				currlen += 1
			else:
				ones.append(currlen)
				currlen = 0
		elif curr == '1':
			currlen = 1
		prev = curr
	if currlen > 0:
		ones.append(currlen)
	ones.sort(reverse=True)
	ans = 0
	for i in range(0, len(ones), 2):
		ans += ones[i]
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	num = len(s)
	kouho = []
	cnt = 0
	for i in range(num):
		if s[i] == '1':
			cnt += 1
		elif cnt:
			kouho.append(cnt)
			cnt = 0
	if cnt:
		kouho.append(cnt)
	kouho.sort(reverse=True)
	print(sum(kouho[::2]))


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

def DecimalToBinary(n):

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

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

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

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

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

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

def main():
	for _ in range(inp()):
		a = input()
		res = []
		i = 0
		while i < len(a):
			if a[i] == '1':
				x = 0
				while i < len(a) and a[i] == '1':
					x += 1
					i += 1
				res.append(x)
			i += 1
		res.sort(reverse=True)
		if len(res):
			s = 0
			for i in range(0, len(res)):
				if i % 2 == 0:
					s += res[i]
			print(s)
		else:
			print(0)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
sys.setrecursionlimit(10 ** 6)
from queue import PriorityQueue
from collections import Counter as cc
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
sys.setrecursionlimit(10 ** 6)
from queue import PriorityQueue
from collections import Counter as cc
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	ans = []
	i = 0
	while i < n:
		if s[i] == '1':
			count = 0
			while s[i] == '1':
				count += 1
				i += 1
				if i == n:
					break
			ans.append(count)
		else:
			i += 1
	ans.sort(reverse=True)
	(final1, final2) = (0, 0)
	for i in range(0, len(ans), 2):
		final1 += ans[i]
	final2 = sum(ans) - final1
	print(max(final1, final2))


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	a = input().rstrip() + '0'
	b = []
	now = 0
	for x in a:
		if x == '1':
			now += 1
		else:
			b.append(now)
			now = 0
	b.sort()
	cnt = 0
	n = len(b)
	for x in range(n - 1, -1, -2):
		cnt += b[x]
	print(cnt)


for t in range(int(input())):
	st = input()
	z = []
	if set(st) == {'1'}:
		print(len(st))
	else:
		for i in range(len(st)):
			if st[i] == '0':
				z.append(i)
		ans = []
		ans.append(z[0])
		for i in range(1, len(z)):
			ans.append(z[i] - z[i - 1] - 1)
		ans.append(len(st) - z[len(z) - 1] - 1)
		ans.sort()
		count = 0
		for i in range(len(ans) - 1, -1, -2):
			count += ans[i]
		print(count)


t = int(input())
for i in range(t):
	a = input()
	a = '0' + a
	ki = -1
	c = []
	for k in range(len(a)):
		if a[k] == '0':
			if k - 1 >= 0 and a[k - 1] == '0':
				continue
			else:
				c.append(0)
				ki += 1
		else:
			c[ki] += 1
	c.sort(reverse=True)
	sum = 0
	for k in range(0, len(c), 2):
		sum += c[k]
	print(sum)


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
t = sInt()
for _ in range(t):
	s = input()
	s = list(s)
	ans = []
	i = 0
	d = 0
	while i < len(s):
		cnt = 0
		while i < len(s) and s[i] == '1':
			cnt += 1
			i += 1
			d = 1
		if d == 0:
			i += 1
		else:
			ans.append(cnt)
			d = 0
		if i == len(s):
			break
	ans.sort()
	ans.reverse()
	if len(ans) == 1:
		print(*ans)
	else:
		final = 0
		for i in range(0, len(ans), 2):
			final += ans[i]
		print(final)


T = int(input())
for i in range(T):
	s = input()
	one = s.count('1')
	alice = 0
	a = True
	while one > 0:
		if s.find('1' * one) != -1:
			if a:
				alice += one
				a = False
			else:
				a = True
			s = s[:s.find('1' * one)] + s[s.find('1' * one) + one:]
		else:
			one -= 1
	print(alice)


for _ in range(int(input())):
	st = input()
	prev = '1'
	ans = []
	cnt = 0
	for i in st:
		if i == '1':
			cnt += 1
		else:
			if cnt != 0:
				ans.append(cnt)
			cnt = 0
	if cnt != 0:
		ans.append(cnt)
	ans.sort()
	s = 0
	ans.reverse()
	for i in range(len(ans)):
		if i % 2 == 0:
			s += ans[i]
	print(s)


for t in range(int(input())):
	s = input()
	temp = []
	pre = s[0]
	s = s[1:]
	count = 1
	for i in s:
		if i != pre:
			if pre == '1':
				temp.append(count)
			count = 1
			pre = i
		else:
			count += 1
	if pre == '1':
		temp.append(count)
	temp.sort()
	out = 0
	while temp:
		out += temp.pop()
		if temp:
			temp.pop()
	print(out)


for i in range(0, int(input())):
	str1 = input()
	c = 0
	list1 = []
	str1 = str1 + '0'
	for i in str1:
		if i == '1':
			c = c + 1
		else:
			if c != 0:
				list1.append(c)
			c = 0
	list1.sort(reverse=True)
	sum1 = 0
	for i in range(0, len(list1), 2):
		sum1 = sum1 + list1[i]
	print(sum1)


import math
from collections import Counter
for test in range(int(input())):
	a = input('')
	ans = []
	count = 0
	for i in a:
		if i == '0':
			if count > 0:
				ans.append(count)
			count = 0
		else:
			count += 1
	if count > 0:
		ans.append(count)
	ans.sort(reverse=True)
	res = 0
	for i in range(0, len(ans), 2):
		res += ans[i]
	print(res)


n = int(input())
for _ in range(n):
	s = input() + '0'
	ls = []
	last = -1
	for c in s:
		if c == '1' and last == '1':
			ls[-1] += 1
		elif c == '1' and last != '1':
			ls.append(1)
		last = c
	ls = sorted(ls)[::-1]
	ans = 0
	for x in range(0, len(ls), 2):
		ans += ls[x]
	print(ans)


t = int(input())
for i in range(t):
	counta = 0
	s = input()
	a = []
	count = 0
	for j in range(0, len(s)):
		if j == len(s) - 1 and s[j] == '1':
			count += 1
			a.append(count)
		elif j == len(s) - 1 and s[j] == '0':
			break
		elif s[j] == s[j + 1] and s[j] == '1':
			count += 1
		elif s[j] == '1' and s[j] != s[j + 1]:
			count += 1
			a.append(count)
			count = 0
		else:
			pass
	a.sort()
	for j in range(len(a) - 1, -1, -2):
		counta += a[j]
	print(counta)


for _ in range(int(input())):
	s = input()
	ones = []
	summ = 0
	for i in range(len(s)):
		if int(s[i]) == 1:
			summ += int(s[i])
		else:
			ones.append(summ)
			summ = 0
		if i == len(s) - 1:
			ones.append(summ)
	ones.sort()
	ones.reverse()
	print(sum(ones[::2]))


n = int(input())
for i in range(0, n):
	no = input()
	counter = 0
	ones = []
	ans = 0
	for j in no:
		if j == '1':
			counter += 1
		else:
			ones.append(counter)
			counter = 0
	ones.append(counter)
	ones.sort(reverse=True)
	for t in range(0, len(ones), 2):
		ans += ones[t]
	print(ans)


def solve():
	a = input()
	n = len(a)
	i = 0
	b = []
	while i < n:
		j = i
		while j < n and a[i] == a[j]:
			j += 1
		if a[i] == '1':
			b.append(j - i)
		i = j
	b.sort(reverse=True)
	ans = 0
	for i in range(0, len(b), 2):
		ans += b[i]
	print(ans)
t = int(input())
for _ in range(t):
	solve()


def f(s):
	s += '0'
	a = []
	curr_len = 0
	curr_char = s[0]
	for c in s:
		if c == curr_char:
			curr_len += 1
		else:
			if curr_char == '1':
				a.append(curr_len)
			curr_char = c
			curr_len = 1
	a = sorted(a, reverse=True)
	return sum([a[i] for i in range(len(a)) if i % 2 == 0])
for _ in range(int(input())):
	print(f(input()))


import math
t = int(input())
while t > 0:
	t -= 1
	a = list(input())
	conse1 = []
	one = 0
	l = len(a)
	if l == 1:
		if a[0] == '1':
			print(1)
		else:
			print(0)
		continue
	i = 0
	cnt = 0
	startcnt = False
	while i < l:
		if a[i] == '1':
			startcnt = True
			cnt += 1
		elif startcnt:
			if cnt == 1:
				one += 1
			else:
				conse1.append(cnt)
			cnt = 0
			startcnt = False
		i += 1
	if startcnt:
		if cnt == 1:
			one += 1
		else:
			conse1.append(cnt)
	ans = 0
	conse1.sort(reverse=True)
	for i in range(0, len(conse1), 2):
		ans += conse1[i]
	if len(conse1) % 2 == 1:
		ans += int(one / 2)
	else:
		ans += math.ceil(one / 2)
	print(ans)


for t in range(int(input())):
	s = input()
	s = s.split('0')
	a = []
	for i in s:
		if i != '':
			a.append(len(i))
	a = sorted(a, reverse=True)
	ans = 0
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)


for _ in range(int(input())):
	temp = input()
	num = 0
	arr = [0]
	for i in range(0, len(temp)):
		if temp[i] == '1':
			arr[num] += 1
		elif temp[i] != temp[i - 1] and temp[i] == '0' and (i != 0):
			num += 1
			arr.append(0)
	arr.sort(reverse=True)
	print(sum(arr[::2]))


for i in range(int(input())):
	lst = list(input().split('0'))
	lst.sort(reverse=True)
	ans = 0
	for i in range(len(lst)):
		if lst[i] == '':
			break
		if i % 2 == 0:
			ans += len(lst[i])
	print(ans)


def delOnes():
	array = str(input())
	location = 0
	loc_array = []
	keepCount = 0
	for x in range(len(array)):
		if array[x] == '1' and keepCount == 0:
			location = x
			keepCount = 1
		elif array[x] == '1' and keepCount != 0:
			keepCount += 1
		elif array[x] == '1':
			keepCount = 1
		elif array[x] == '0' and keepCount > 0:
			loc_array.append([location, keepCount])
			keepCount = 0
		else:
			keepCount = 0
	if keepCount > 0:
		loc_array.append([location, keepCount])
	turn = 1
	totalOnes = 0
	val = 0
	while len(loc_array) > 0:
		checkHighest = 0
		for z in range(len(loc_array)):
			if checkHighest < loc_array[z][1]:
				val = z
				checkHighest = loc_array[z][1]
		if turn % 2 == 1:
			totalOnes += loc_array[val][1]
		del loc_array[val]
		turn += 1
	return totalOnes
total_arr = []
integer = int(input())
while integer > 0:
	total_arr.append(delOnes())
	integer -= 1
for x in total_arr:
	print(x)


n = int(input())
for i in range(n):
	k = input()
	flag = False
	leng = 0
	ans = 0
	a = []
	for i in k:
		if flag and i == '1':
			leng += 1
		elif i == '1':
			leng = 1
			flag = True
		else:
			flag = False
			if leng > 0:
				a.append(leng)
			leng = 0
	if leng > 0:
		a.append(leng)
	a.sort()
	a.reverse()
	for i in range(0, len(a), 2):
		ans += a[i]
	print(ans)


for _ in range(int(input())):
	s = input() + '0'
	A = []
	tr = False
	x = 0
	for i in range(len(s)):
		if s[i] == '1':
			if tr:
				x += 1
			else:
				tr = True
				x = 1
		elif tr:
			tr = False
			A.append(x)
	A.sort(reverse=True)
	Ans = 0
	for i in range(len(A)):
		if i % 2 == 0:
			Ans += A[i]
	print(Ans)


import collections as cc
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	s = list(input())
	ans = []
	cnt = 0
	n = len(s)
	for i in range(n):
		if s[i] == '1':
			cnt += 1
		elif s[i] == '0' and cnt:
			ans.append(cnt)
			cnt = 0
	te = 0
	if cnt:
		ans.append(cnt)
	ans.sort()
	ans = ans[::-1]
	for i in range(0, len(ans), 2):
		te += ans[i]
	print(te)


t = int(input())
while t > 0:
	s = input()
	score = 0
	a = []
	i = 0
	s += '0'
	while i < len(s) - 1:
		k = ''
		if s[i] == '1':
			k += '1'
			for j in range(i + 1, len(s)):
				if s[j] == '1':
					k += '1'
				else:
					break
			i = j + 1
			a.append(k)
		else:
			i += 1
	a.sort()
	a = a[::-1]
	for l in range(len(a)):
		if l % 2 == 0:
			score += len(a[l])
	print(score)
	t -= 1


for i in range(int(input())):
	ip = list(map(int, input()))
	ones = []
	tot = 0
	for i in ip:
		if i == 1:
			tot += 1
		else:
			ones.append(tot)
			tot = 0
	if tot:
		ones.append(tot)
	ones.sort(reverse=True)
	ans = 0
	for i in range(0, len(ones), 2):
		ans += ones[i]
	print(ans)


def getMaxLength(arr, n):
	count = 0
	result = 0
	for i in range(0, n):
		if arr[i] == 0:
			count = 0
		else:
			count += 1
			result = max(result, count)
	return result
T = int(input())
for i in range(T):
	s = input()
	lst = []
	lst = list(s)
	res = 0
	k = 0
	vv = []
	j = 0
	while j < len(lst):
		cc = 0
		while lst[j] == '1':
			if j == len(lst) - 1:
				cc += 1
				break
			j += 1
			cc += 1
		if cc != 0:
			vv.append(cc)
			j += 1
		else:
			j += 1
			continue
	vv.sort(reverse=True)
	if len(vv) == 0:
		print(0)
	else:
		count = 0
		for h in range(len(vv)):
			if h % 2 == 0:
				count += vv[h]
		print(count)


tc = int(input())
for _ in range(tc):
	s = input()
	v = s.split('0')
	ans = []
	for b in v:
		ans.append(len(b))
	ans.sort(reverse=True)
	alice = 0
	for i in range(len(ans)):
		if i % 2 == 0:
			alice += ans[i]
	print(alice)


for ii in range(int(input())):
	n = input().split('0')
	x = sorted(n, reverse=True)
	ans = 0
	for jj in range(0, len(x), 2):
		if x[jj] == '':
			break
		ans += len(x[jj])
	print(ans)


from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
from math import sqrt
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

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

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

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

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	for _ in range(inin()):
		s = sin()
		temp = []
		flag = 0
		ans = 0
		for i in range(len(s)):
			if i != 0:
				if s[i - 1] == '1' and s[i] == '1':
					temp[-1] += 1
				elif s[i] == '1':
					temp.append(1)
			elif s[i] == '1':
				temp.append(1)
		temp.sort(reverse=True)
		for i in range(len(temp)):
			if i & 1 == 0:
				ans += temp[i]
		print(ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

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


def solve(s):
	(alice, bob) = (0, 0)
	count = 0
	while '1' in s:
		max_len = 0
		max_left = 0
		max_right = 0
		first_ind = 0
		while first_ind < len(s):
			while s[first_ind] != '1':
				first_ind += 1
				if first_ind >= len(s):
					break
			if first_ind >= len(s):
				break
			last_ind = first_ind
			while s[last_ind] == '1':
				last_ind += 1
				if last_ind >= len(s):
					break
			if last_ind - first_ind > max_len:
				max_len = last_ind - first_ind
				max_left = first_ind
				max_right = last_ind
			first_ind += 1
		if count % 2 == 0:
			alice += max_len
		else:
			bob += max_len
		s = s[:max_left] + s[max_right:]
		count += 1
	print(alice)
t = int(input())
while t:
	s = input()
	solve(s)
	t -= 1


for _ in range(int(input())):
	s = input().replace('0', '2').split('2')
	lis = []
	for i in s:
		lis.append(len(i))
	lis.sort(reverse=True)
	score = 0
	turn = True
	for i in lis:
		if turn:
			score += i
		turn = not turn
	print(score)


import sys
t = int(input())
while t > 0:
	s = input()
	n = len(s)
	c = []
	for i in range(n, 0, -1):
		if '1' * i in s:
			ss = s.count('1' * i)
			for j in range(ss):
				c.append(i)
			s = s.replace('1' * i, '')
			i += 1
	cost = 0
	c.sort(reverse=True)
	for i in range(len(c)):
		if i % 2 == 0:
			cost += c[i]
	print(cost)
	t -= 1


t = int(input())
for _ in range(t):
	s = input()
	c = 0
	li = []
	for i in s:
		if i == '1':
			c += 1
		elif c > 0:
			li.append(c)
			c = 0
	if c > 0:
		li.append(c)
	li = sorted(li)[::-1]
	print(sum(li[::2]))


t = int(input())
for _ in range(t):
	s = list(input())
	lst = []
	count = 0
	for i in s:
		if i == '1':
			count += 1
		else:
			lst.append(count)
			count = 0
	lst.append(count)
	summ = 0
	for i in lst:
		if i == 0:
			lst.remove(i)
	lst.sort(reverse=True)
	for i in range(0, len(lst), 2):
		summ += lst[i]
	print(summ)


import sys
input = sys.stdin.readline
from collections import *
for _ in range(int(input())):
	s = input()[:-1]
	l = []
	cnt = 1
	for i in range(len(s) - 1):
		if s[i] != s[i + 1]:
			l.append((s[i], cnt))
			cnt = 1
		else:
			cnt += 1
	l.append((s[-1], cnt))
	l2 = []
	for (si, c) in l:
		if si == '1':
			l2.append(c)
	l2.sort(reverse=True)
	ans = 0
	for i in range(len(l2)):
		if i % 2 == 0:
			ans += l2[i]
	print(ans)


import sys
read = lambda : sys.stdin.readline().strip()
for _ in range(int(read())):
	nums = list(read())
	counts = []
	flag = False
	temp_count = 0
	for i in nums:
		if i == '1':
			flag = True
			temp_count += 1
		else:
			if flag:
				counts.append(temp_count)
			flag = False
			temp_count = 0
	counts.append(temp_count)
	counts.sort(reverse=True)
	score = 0
	for i in range(0, len(counts), 2):
		score += counts[i]
	print(score)


def ones(string):
	counts = []
	last = False
	c = 0
	for bit in string:
		if bit == '1':
			if last == False:
				c = 1
			else:
				c += 1
			last = True
		elif last == True:
			counts.append(c)
			last = False
	if last:
		counts.append(c)
	counts = sorted(counts, reverse=True)
	summ = 0
	for i in range(0, len(counts), 2):
		summ += counts[i]
	return summ
t = int(input())
for i in range(t):
	s = input()
	print(ones(s))


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
for _ in range(int(I1())):
	s = I1()
	l = []
	c = 0
	n = len(s)
	for i in range(0, n):
		if s[i] == '1':
			c += 1
		elif c >= 1:
			l.append(c)
			c = 0
	l.append(c)
	l.sort(reverse=True)
	ans = 0
	for i in range(0, len(l), 2):
		ans += l[i]
	print(ans)


t = int(input())
for asd in range(t):
	s = str(input())
	a = []
	if s[0] == '1':
		count = 1
	else:
		count = 0
	for i in range(0, len(s) - 1):
		if s[i + 1] == '1' and s[i] == '0':
			count = 1
		elif s[i + 1] == '1' and s[i] == '1':
			count += 1
		elif s[i + 1] == '0' and s[i] == '1':
			a.append(count)
			count = 0
	a.append(count)
	a.sort()
	count = 0
	for i in range(len(a) - 1, -1, -2):
		count += a[i]
	print(count)


for _ in range(int(input())):
	a = list(input().split('0'))
	a = sorted(a, reverse=True)
	ans = 0
	for i in range(0, len(a), 2):
		ans += len(a[i])
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	score = 0
	lst = [0]
	for j in s:
		if j == '1':
			lst[-1] = lst[-1] + 1
		elif lst[-1] != 0:
			lst.append(0)
	lst.sort(reverse=True)
	for j in range(len(lst)):
		if j % 2 == 0:
			score = score + lst[j]
	print(score)


t = int(input())
for i in range(t):
	s = input()
	a = []
	b = []
	c = []
	for j in range(len(s) - 1):
		if s[j] != s[j + 1]:
			a.append(j + 1)
	a.append(len(s))
	b.append(a[0])
	for j in range(len(a) - 1):
		b.append(a[j + 1] - a[j])
	if s[0] == '1':
		for j in range(0, len(b), 2):
			c.append(b[j])
	else:
		for j in range(1, len(b), 2):
			c.append(b[j])
	c.sort(reverse=True)
	k = 0
	for j in range(0, len(c), 2):
		k = k + c[j]
	print(k)


from sys import stdin
t = int(input())
for _ in range(t):
	s = [i for i in input()]
	s.append('1' if s[-1] == '0' else '0')
	length = 0
	p = []
	for i in range(len(s)):
		if s[i] == '1':
			length += 1
		else:
			p.append(length)
			length = 0
	p.sort(reverse=True)
	ans = 0
	for i in range(0, len(p), 2):
		ans += p[i]
	print(ans)


t = int(input())
for tt in range(t):
	s = input().strip()
	i = 0
	c = 0
	arr = []
	while i < len(s):
		if s[i] == '1':
			c += 1
		else:
			if c > 0:
				arr.append(c)
			c = 0
		i += 1
	if c > 0:
		arr.append(c)
	arr = sorted(arr, reverse=True)
	ans = 0
	for i in range(0, len(arr), 2):
		ans += arr[i]
	print(ans)


def solve():
	a = input().split('0')
	a.sort(key=lambda x: len(x), reverse=True)
	ans = 0
	for i in a[::2]:
		ans += len(i)
	print(ans)
for t in range(int(input())):
	solve()


a = []
for i in [0] * int(input()):
	s = input()
	k = 0
	for j in s:
		if j == '1':
			k += 1
		elif k > 0:
			a.append(k)
			k = 0
	if k > 0:
		a.append(k)
	a.sort()
	a.reverse()
	print(sum(a[::2]))
	a.clear()


t = int(input())
for i in range(t):
	s = input()
	contador = 0
	frequencia = []
	for n in s:
		if n == '1':
			contador += 1
		else:
			frequencia.append(contador)
			contador = 0
	frequencia.append(contador)
	frequencia_ordenada = sorted(frequencia)
	soma = 0
	for e in range(len(frequencia_ordenada) - 1, -1, -2):
		soma += frequencia_ordenada[e]
	print(soma)


def main():
	t = int(input())
	for tt in range(t):
		a = input()
		b = []
		c = 0
		if len(a) == 1 and a[0] == '1':
			print(1)
		elif len(a) == 1 and a[0] == '0':
			print(0)
		for i in range(0, len(a) - 1):
			if a[i] == '0' and a[i + 1] == '1' and (i + 1 == len(a) - 1):
				c = c + 1
				b.append(c)
			elif a[i] == '1' and a[i + 1] == '1':
				if i + 1 == len(a) - 1:
					c = c + 2
					b.append(c)
				else:
					c = c + 1
			elif a[i] == '1' and a[i + 1] == '0':
				c = c + 1
				b.append(c)
				c = 0
		b = sorted(b)
		b.reverse()
		s = 0
		for i in range(0, len(b)):
			if (i + 1) % 2 == 1:
				s = s + b[i]
		if len(a) > 1:
			print(s)
main()


t = int(input())
for _ in range(t):
	s = input()
	arr = []
	for word in s:
		if word != '\r':
			arr.append(word)
	slow = 0
	fast = 1
	n = len(arr)
	x = []
	x.append(-1)
	for i in range(n):
		if arr[i] == '0':
			x.append(i)
	x.append(n)
	y = []
	for i in range(len(x) - 1):
		y.append(x[i + 1] - x[i] - 1)
	y.sort()
	ans = 0
	while len(y) != 0:
		ans = ans + y[-1]
		y.pop()
		if len(y) != 0:
			y.pop()
	print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7

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

def out(var):
	sys.stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	s = data()
	cont = []
	cnt = 0
	for i in range(len(s)):
		if s[i] == '0':
			cont.append(cnt)
			cnt = 0
		else:
			cnt += 1
	cont.append(cnt)
	cont.sort()
	par = 1
	answer = 0
	while cont:
		if par:
			answer += cont.pop()
		else:
			cont.pop()
		par = not par
	out(answer)


T = int(input())
for t in range(T):
	s = input()
	count = 0
	flag = 0
	k = []
	for i in range(len(s)):
		if s[i] == '1' and flag == 0:
			flag = 1
			count = 1
		elif s[i] == '1':
			count += 1
		elif s[i] == '0' and flag == 1:
			k.append(count)
			count = 0
			flag = 0
	if flag == 1:
		k.append(count)
	sum1 = 0
	k.sort(reverse=True)
	for num in range(len(k)):
		if num % 2 == 0:
			sum1 += k[num]
	print(sum1)


try:

	def find(s):
		if all([x == 0 for x in s]):
			return (-1, -1)
		count = 0
		index = 0
		i = 0
		while i < len(s):
			if s[i] == 1:
				temp = 0
				tempindex = i
				while i < len(s) and s[i] == 1:
					temp += 1
					i += 1
				if count < temp:
					count = temp
					index = tempindex
				continue
			else:
				i += 1
				continue
		return (count, index)
	t = int(input())
	for _ in range(t):
		s = list(map(int, input()))
		i = 1
		result = 0
		while s != []:
			(count, index) = find(s)
			if count == -1:
				break
			if i % 2 == 1:
				result += count
			j = 1
			while j <= count:
				s.pop(index)
				j += 1
			i += 1
		print(result)
except:
	pass


def main():
	t = int(input())
	for _ in range(t):
		s = input()
		a = []
		start = -1
		for (i, v) in enumerate(s):
			if v == '1':
				if start == -1:
					start = i
			elif start > -1:
				a.append(i - start)
				start = -1
		if start > -1:
			a.append(len(s) - start)
		a.sort(reverse=True)
		ans = 0
		for i in range(0, len(a), 2):
			ans += a[i]
		print(ans)
	return
main()


t = int(input())
for _ in range(t):
	s = input()
	co = []
	start = 0
	for i in range(len(s)):
		if s[i] == '0':
			co.append(i - start)
			start = i + 1
	co.append(len(s) - start)
	co.sort(reverse=True)
	alice = 0
	for i in range(0, len(co), 2):
		alice += co[i]
	print(alice)


for _ in range(int(input())):
	s = input()
	if '1' not in s:
		print(0)
	elif '0' not in s:
		print(len(s))
	else:
		i = 0
		p = []
		while i < len(s):
			c = 0
			if s[i] == '1':
				temp = i
				c += 1
				if temp + 1 < len(s):
					while s[temp + 1] == '1':
						c += 1
						temp += 1
						if temp + 1 >= len(s):
							break
				p.append(c)
				i = temp + 1
			else:
				i += 1
		p = sorted(p, reverse=True)
		alice = 0
		for i in range(0, len(p), 2):
			alice += p[i]
		print(alice)


t = int(input())
for hh in range(t):
	s = input()
	i = 0
	li = []
	while i < len(s):
		count = 0
		for j in range(i, len(s)):
			if s[j] == '0':
				i = j + 1
				break
			else:
				count += 1
				i += 1
		li.append(count)
	li = sorted(li, reverse=True)
	ans = 0
	for i in range(0, len(li), 2):
		ans += li[i]
	print(ans)


for _ in range(int(input())):
	s = input()
	i = 0
	res = []
	while i < len(s):
		if s[i] == '1':
			count = 1
			while i < len(s) - 1 and s[i] == s[i + 1]:
				count += 1
				i += 1
			res.append(count)
		i += 1
	res_sorted = sorted(res, reverse=True)
	sum = 0
	for i in range(0, len(res_sorted), 2):
		sum += res_sorted[i]
	print(sum)