Limak is a little polar bear.
He is playing a video game and he needs your help.
There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively.
The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells).
The only possible command is choosing a soldier and telling him to move to the right as far as possible.
Choosing a soldier takes 1 second, and a soldier moves with the speed of a cell per second.
The soldier stops immediately if he is in the last cell of the row or the next cell is already occupied.
Limak isn't allowed to choose a soldier that can't move at all (the chosen soldier must move at least one cell to the right).
Limak enjoys this game very much and wants to play as long as possible.
In particular, he doesn't start a new command while the previously chosen soldier moves.
Can you tell him, how many seconds he can play at most?

-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.

The only line of each test case contains a string S describing the row with N cells.
Each character is either '0' or '1', denoting an empty cell or a cell with a soldier respectively.

-----Output-----
For each test case, output a single line containing one integer — the maximum possible number of seconds Limak will play the game.

-----Constraints-----
- 1 ≤ T ≤ 5
- 1 ≤ N ≤ 105 (N denotes the length of the string S)

-----Subtasks-----
- Subtask #1 (25 points): 1 ≤ N ≤ 10
- Subtask #2 (25 points): 1 ≤ N ≤ 2000
- Subtask #3 (50 points): Original constraints.

-----Example-----
Input:
4
10100
1100001
000000000111
001110100011010

Output:
8
10
0
48

-----Explanation-----
Test case 1.
The initial string is 10100.
There are N = 5 cells.
There is one soldier in the first cell, and one soldier in the third cell.
The following scenario maximizes the total time:
- Limak chooses the soldier in the first cell.
This soldier can move only one cell to the right.
It takes 1 second to choose a soldier and 1 second for a soldier to move to the next cell (2 seconds in total).
The string is 01100 now.
- Limak has only one choice.
He must choose the soldier in the third cell because the other soldier can't move at all (the soldier in the second cell can't move to the right because the next cell is already occupied).
Choosing a soldier takes 1 second.
The chosen soldier moves from the third cell to the fifth cell, which takes 2 seconds.
This operation takes 1 + 2 = 3 seconds in total.
The string is 01001 now.
- Limak has only one choice again.
Since the soldier in the last row can't move further to the right, the soldier in the second cell must be chosen.
He will move 2 cells to the right.
This operation takes 1 + 2 = 3 seconds in total.
The string become 00011 and the game is over.
The total time is 2 + 3 + 3 = 8.
Test case 2.
The initial string is 1100001.
There is only one possible scenario:
- 1100001 is changed to 1000011 in 5 seconds (1 second to choose a soldier and 4 seconds for the soldier to move 4 cells to the right).
- 1000011 is changed to 0000111 in 5 seconds.

The total time is 5 + 5 = 10 seconds.
Test case 3.
The game is over immediately because all soldiers occupy rightmost cells already.
The answer is 0.

Difficulty: interview

Starter code:

Solutions:
for _ in range(int(input())):
 l=list(map(int,input().strip()))
 for j in range(len(l)-1,-1,-1):
  if l[j]==1:
   l.pop()
  else:
   break
 if l.count(1):
  time,prev,z,c=0,0,0,0
  for j in range(len(l)-1,-1,-1):
   if l[j]==0:
    z+=1
    continue
   if prev!=z:
    prev=z
    c+=1
   time+=c+z

  print(time)
 else:
  print(0)



for _ in range(int(input())):
 l=list(map(int,input().strip()))
 for i in range(len(l)-1,-1,-1):
  if l[i]==1:
   l.pop()
  else:
   break
 if l.count(1):
  time,prev,z,c=0,0,0,0
  for i in range(len(l)-1,-1,-1):
   if l[i]==0:
    z+=1
    continue
   if prev!=z:
    prev=z
    c+=1
   time+=c+z

  print(time)
 else:
  print(0)



for _ in range(int(input())):
 l=list(map(int,input().strip()))
 for i in range(len(l)-1,-1,-1):
  if l[i]==1:
   l.pop()
  else:
   break
 if l.count(1):
  time,prev,z,c=0,0,0,0
  for i in range(len(l)-1,-1,-1):
   if l[i]==0:
    z+=1
    continue
   if prev!=z:
    prev=z
    c+=1
   time+=c+z

  print(time)
 else:
  print(0)



for _ in range(int(input())):
 a = list(input())
 n = len(a)
 for i in reversed(range(n)):
  if a[i] == '1':
   a.pop()
  else:
   break
 n = len(a)
 zero = 0
 prev = tot =0
 c= 0
 for i in reversed(range(n)):
  if a[i] == '0':
   zero += 1
   continue
  if prev != zero:
   prev = zero
   c += 1
  tot += c + zero
 print(tot)

for _ in range(int(input())):
 
 s = input()
 count = 0
 n = len(s)
 count = 0
 total = 0
 lastindex = n-1
 curr = n-1
 while (curr >= 0 and s[lastindex] == "1"):
  curr -= 1
  lastindex -= 1
 while curr >= 0:
  if s[curr] == "1":
   if s[curr+1] == "0":
    count += 1
   total += count + (lastindex - curr)
   lastindex -= 1
  curr -= 1
 print(total)

import sys
#input = sys.stdin.readline
for _ in range(int(input())):
 #n = int(input())
 s = str(input())
 arr = [int(i) for i in s]
 n = len(arr)
 total = 0
 cnt = 0
 lstindx, curr = n -1, n-1
 while arr[curr] == 1 and curr >= 0:
  curr -= 1
  lstindx -= 1
 while curr >= 0:
  if arr[curr] == 1:
   if arr[curr + 1] == 0:
    cnt += 1
   total += cnt + (lstindx - curr)
   lstindx -= 1
  curr -= 1
 print(total)

t = int(input())

for each in range(t):
 a = input()
 n = len(a)

 picks = [0]*(n+1)
 picks[n-1] = 1 if (a[n-1] == '0') else 0
 i = n-2
 while(i>-1):
  picks[i] = picks[i + 1]
  if (a[i] == '0' and a[i + 1] == '1'):
   picks[i]+=1
  i-=1
 # print(picks)

 disp = [0]*(n+1)
 soldiers = 0;
 i = n-1
 while(i>-1):
  if (a[i] == '1'):
   disp[i] = n - soldiers - 1 - i;
   soldiers+=1;
  i-=1
 # print(disp)

 ans = 0
 for i in range(n):
  if (a[i] == '1'):
   ans += picks[i] + disp[i];
 print(ans)

for _ in range(int(input())):
 string = list(input())
 k = len(string)
 for i in reversed(range(k)):
  if string[i] == '1':
   string.pop()
  else:
   break
 
 time = 0
 n = string.count('1')
 
 
 k = len(string)
 for _ in range(n):
  for i in range(k):
   if(string[i] == '1'):
    if(i == k-1):
     break
    j = i + 1
    while(string[j] != '1'):
     string[j-1] = '0'
     string[j] = '1'
     if(j-i == 1):
      time += 1
     time += 1
     if(j<k-1):
      j+= 1
     
   
   

    
  
 print(time)

for _ in range(int(input())):
 string = list(input())
 
 
 time = 0
 n = string.count('1')
 
 
 k = len(string)
 for _ in range(n):
  for i in range(k):
   if(string[i] == '1'):
    if(i == k-1):
     break
    j = i + 1
    while(string[j] != '1'):
     string[j-1] = '0'
     string[j] = '1'
     if(j-i == 1):
      time += 1
     time += 1
     if(j<k-1):
      j+= 1
     
   
   

    
  
 print(time)

for _ in range(int(input())):
 arr = list(input())
 n = len(arr)
 for i in reversed(range(n)):
  if arr[i] == '1':
   arr.pop()
  else:
   break
 n = len(arr)
 zero = prev = total = cnt = 0
 for i in reversed(range(n)):
  if arr[i] == '0':
   zero += 1
   continue
  if prev != zero:
   prev = zero
   cnt += 1
  total += cnt + zero
 print(total)

t=int(input())
for _ in range(t):
 s=input()
 pre=[]
 n=len(s)
 j=0
 ss={}
 for i in range(n):
  if s[i]=="1":
   pre.append(i)
   ss[i]=j
   j+=1
 pre.append(n)
 suff=[0 for i in range(n+1)]
 tot=0
 duff=[0 for i in range(n+1)]
 for i in range(n-1,-1,-1):
  if s[i]=="0":
   pass
  else:
   
   suff[i]=suff[pre[ss[i]+1]]+max(tot,0)
   duff[i]=max(tot,0)
   tot-=1
  tot+=1
 tot=0
 st=False
 dp=[0]*(n+1)
 for i in range(n-1,-1,-1):
  if s[i]=="0":
   st=True
   continue
  else:
   if st:
    tot+=1
    st=False
   dp[i]=tot+dp[pre[ss[i]+1]]
   
   
 print(suff[pre[0]]+dp[pre[0]])
 


# cook your dish here
# from itertools import groupby
t = int(input())
for _ in range(t):
 s = input()
 n = len(s)
 i = n - 1
 ones = s.count('1')
 c = 0
 ans = 0
 while i >= 0:
  if s[i] == '0':
   c += 1
   i -= 1
  else:
   if c:
    ans += ones * (c + 1)
    c = 0
   while i >= 0 and s[i] == '1':
    ones -= 1
    i -= 1
 print(ans)

# cook your dish here
# from itertools import groupby
t = int(input())
for _ in range(t):
 s = input()
 n = len(s)
 i = n - 1
 ones = s.count('1')
 c = 0
 ans = 0
 while i >= 0:
  if s[i] == '0':
   c += 1
   i -= 1
  else:
   if c:
    ans += ones * (c + 1)
    c = 0
   while s[i] == '1':
    ones -= 1
    i -= 1
 print(ans)