Consider a simplified penalty phase at the end of a football match.

A penalty phase consists of at most 10 kicks, the first team takes the first kick, the second team takes the second kick, then the first team takes the third kick, and so on. The team that scores more goals wins; if both teams score the same number of goals, the game results in a tie (note that it goes against the usual football rules). The penalty phase is stopped if one team has scored more goals than the other team could reach with all of its remaining kicks. For example, if after the 7-th kick the first team has scored 1 goal, and the second team has scored 3 goals, the penalty phase ends — the first team cannot reach 3 goals.

You know which player will be taking each kick, so you have your predictions for each of the 10 kicks. These predictions are represented by a string s consisting of 10 characters. Each character can either be 1, 0, or ?. This string represents your predictions in the following way:

  * if s_i is 1, then the i-th kick will definitely score a goal; 
  * if s_i is 0, then the i-th kick definitely won't score a goal; 
  * if s_i is ?, then the i-th kick could go either way. 



Based on your predictions, you have to calculate the minimum possible number of kicks there can be in the penalty phase (that means, the earliest moment when the penalty phase is stopped, considering all possible ways it could go). Note that the referee doesn't take into account any predictions when deciding to stop the penalty phase — you may know that some kick will/won't be scored, but the referee doesn't.

Input

The first line contains one integer t (1 ≤ t ≤ 1 000) — the number of test cases.

Each test case is represented by one line containing the string s, consisting of exactly 10 characters. Each character is either 1, 0, or ?.

Output

For each test case, print one integer — the minimum possible number of kicks in the penalty phase.

Example

Input


4
1?0???1001
1111111111
??????????
0100000000


Output


7
10
6
9

Note

Consider the example test:

In the first test case, consider the situation when the 1-st, 5-th and 7-th kicks score goals, and kicks 2, 3, 4 and 6 are unsuccessful. Then the current number of goals for the first team is 3, for the second team is 0, and the referee sees that the second team can score at most 2 goals in the remaining kicks. So the penalty phase can be stopped after the 7-th kick.

In the second test case, the penalty phase won't be stopped until all 10 kicks are finished.

In the third test case, if the first team doesn't score any of its three first kicks and the second team scores all of its three first kicks, then after the 6-th kick, the first team has scored 0 goals and the second team has scored 3 goals, and the referee sees that the first team can score at most 2 goals in the remaining kicks. So, the penalty phase can be stopped after the 6-th kick.

In the fourth test case, even though you can predict the whole penalty phase, the referee understands that the phase should be ended only after the 9-th kick.
#Mamma don't raises quitter.................................................
#manan is improving, keep hustling manan bhai ;)
from collections import deque as de
import math
import sys
from math import sqrt as sq
from math import floor as fl
from math import ceil as ce
from sys import getfilesystemencodeerrors, stdin, stdout
sys.setrecursionlimit(10**7)
from collections import Counter as cnt
from functools import  reduce

from itertools import groupby as gb
#from fractions import Fraction as fr
from bisect import bisect_left as bl, bisect_right as br
from typing import Coroutine
sys.setrecursionlimit(10**6)
def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
    
class My_stack():
    def __init__(self):
        self.data = []
    def my_push(self, x):
        return (self.data.append(x))
    def my_pop(self):
        return (self.data.pop())
    def __iter__(self):
        return iter(self.data)
    def my_peak(self):
        return (self.data[-1])
    def my_contains(self, x):
        return (self.data.count(x))
    def my_show_all(self):
        return (self.data)
    def isEmpty(self):
      return len(self.data)==0

arrStack = My_stack() 

class graph():
    def __init__(self):
        self.graphdict = {}
    def add_edge(self, node, neighbor):
        if node not in self.graphdict:
            self.graphdict[node]=[neighbor]
        else:
            self.graphdict[node].append(neighbor)
    def show_edge(self):
        for node in self.graphdict:
            for neighbors in self.graphdict:
                print(node, neighbors)
    def show_graph(self):
        return self.graphdict
gr=graph()

    


    
            

#decimal to binary   
def decimalToBinary(n): 
    return bin(n).replace("0b", "")
#binary to decimal
def binarytodecimal(n):
    return int(n,2)

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 get_prime_factors(number):
    prime_factors = []
    while number % 2 == 0:
        prime_factors.append(2)
        number = number / 2
    for i in range(3, int(math.sqrt(number)) + 1, 2):
        while number % i == 0:
            prime_factors.append(int(i))
            number = number / i

    if number > 2:
        prime_factors.append(int(number))
    return prime_factors

def get_frequency(list):
    dic={}
    for ele in list:
        if ele in dic:
            dic[ele] += 1
        else:
            dic[ele] = 1
    return dic
def Log2(x): 
    return (math.log10(x) / 
            math.log10(2)); 

 
# Function to get product of digits
def getProduct(n):
    product = 1
    while (n != 0):
        product = product * (n % 10)
        n = n // 10
    return product


#function to find LCM of two numbers
def lcm(x,y):
   lcm = (x*y)//math.gcd(x,y)
   return lcm

def isPowerOfTwo(n): 
    return (math.ceil(Log2(n)) == math.floor(Log2(n))); 
#to check whether the given sorted sequnce is forming an AP or not....
def checkisap(list):
    d=list[1]-list[0]
    for i in range(2,len(list)):
        temp=list[i]-list[i-1]
        if temp !=d:
            return False
    return True
        
#seive of erathanos
def primes_method5(n):
    out ={}
    sieve = [True] * (n+1)
    for p in range(2, n+1):
        if (sieve[p]):
            out[p]=1
            for i in range(p, n+1, p):
                sieve[i] = False
    return out

#function to get the sum of digits
def getSum(n): 
      
    strr = str(n)
    list_of_number = list(map(int, strr.strip()))
    return sum(list_of_number)
def checkperfectsquare(n):
    if (ce(sq(n)) == fl(sq(n))):
        return True
    else:
        return False

#ceil  function gives wrong answer after 10^17 so i have to create my own :)
# because i don't want to doubt on my solution of 900-1000 problem set.
def ceildiv(x,y): 
    return (x+y-1)//y 
  
def di():return map(int, input().split())
def ii():return int(input())
def li():return list(map(int, input().split()))
def si():return list(map(str, input()))
def indict():
    dic = {}
    for index, value in enumerate(input().split()):
        dic[int(index)] = int(value)
    return dic
def frqdict(): 
    # by default it is for integer input. :)
    dic={}
    for index, value in enumerate(input()):
        if value not in dic:
            dic[value] =1
        else:
            dic[value] +=1
    return dic

#inp = open("input.txt","r")
#out = open("output.txt","w")
#Here we go......................
#practice like your never won
#perform like you never lost
#dp prblm
t=ii()
while t:
    t-=1
    s=si()
    if "?" in s:
        #for team1=temps:
        #for team2=s:
        temps=s.copy()
        for i in range(10):
            if s[i]=="?":
                if i%2==0:
                    temps[i]="1"
                    s[i]="0"
                else:
                    temps[i]="0"
                    s[i]="1"
                    
                    
                    
        scocre1=0
        chance1=[1,3, 5, 7,9]
        scocre2=0
        chance2=[2, 4,6,8,10]
        for i in range(len(s)):
            
            if i%2==0:
                if temps[i]=="1":
                    scocre1+=1
                chance1.remove(i+1)
            else:
                if temps[i]=="1":
                    scocre2+=1
                chance2.remove(i+1)
            if scocre1> scocre2 and scocre2+len(chance2)<scocre1:
                break
        
        scocre1=0
        chance1=[1,3, 5, 7,9]
        scocre2=0
        chance2=[2, 4,6,8,10]
        for j in range(len(s)):
            
            if j%2==0:
                if s[j]=="1":
                    scocre1+=1
                chance1.remove(j+1)
            else:
                if s[j]=="1":
                    scocre2+=1
                chance2.remove(j+1)
            if scocre1> scocre2 and scocre2+len(chance2)<scocre1:
                break

        print(min(i,j)+1)
            

            

    else:
        #for team1 
        scocre1=0
        chance1=[1,3, 5, 7,9]
        scocre2=0
        chance2=[2, 4,6,8,10]
        for i in range(len(s)):
            if i%2==0:
                if s[i]=="1":
                    scocre1+=1
                chance1.remove(i+1)
            else:
                if s[i]=="1":
                    scocre2+=1
                chance2.remove(i+1)
            if scocre1> scocre2 and scocre2+len(chance2)<scocre1:
                break
    
    
        scocre1=0
        chance1=[1,3, 5, 7,9]
        scocre2=0
        chance2=[2, 4,6,8,10]
        for j in range(len(s)):
            
            if j%2==0:
                if s[j]=="1":
                    scocre1+=1
                chance1.remove(j+1)
            else:
                if s[j]=="1":
                    scocre2+=1
                chance2.remove(j+1)
            if scocre1< scocre2 and scocre1+len(chance1)<scocre2:
                break
        print(min(i,j)+1)
                
                 



        

    
    

            
                       
        
                        





        
    




    

                            
                       






            

        

        

                
            
            


        
        
               

    


    

        
                    

    


    

    
    
    
        
        

        
        




    

                


                

            

    
    
    

            
            

    

            



            




    
    
    
    

    

    



        





        

    





   






        
        
            
            
    




    

    

    



        
        

                
    
        


        
        



        





            
        
        





            
            
            
            

            
      
                
                

        

            
            
        
            









        

        
    



            

    
    
    



            

            


    
        


        
    

            
        
    

                
                
                
        
        
        

            

        





                    
                
            
        

            
    
        
    
    

    
        
    
 

    
        


    
        

