description: 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.
solution: import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.OutputStream;
  import java.io.PrintWriter;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Collections;
  import java.util.Comparator;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.LinkedList;
  import java.util.List;
  import java.util.Map;
  import java.util.Map.Entry;
  import java.util.PriorityQueue;
  import java.util.Queue;
  import java.util.Random;
  import java.util.Stack;
  import java.util.StringTokenizer;
  import java.util.TreeMap;
  import java.util.TreeSet;
  
  public class hacker49 {
  
  	static class FastReader 
      { 
          BufferedReader br; 
          StringTokenizer st; 
    
          public FastReader() 
          { 
              br = new BufferedReader(new
                       InputStreamReader(System.in)); 
          } 
    
          String next() 
          { 
              while (st == null || !st.hasMoreElements()) 
              { 
                  try
                  { 
                      st = new StringTokenizer(br.readLine()); 
                  } 
                  catch (IOException  e) 
                  { 
                      e.printStackTrace(); 
                  } 
              } 
              return st.nextToken(); 
          } 
    
          int nextInt() 
          { 
              return Integer.parseInt(next()); 
          } 
    
          long nextLong() 
          { 
              return Long.parseLong(next()); 
          } 
    
          double nextDouble() 
          { 
              return Double.parseDouble(next()); 
          } 
    
          String nextLine() 
          { 
              String str = ""; 
              try
              { 
                  str = br.readLine(); 
              } 
              catch (IOException e) 
              { 
                  e.printStackTrace(); 
              } 
              return str; 
          } 
      } 
  	public static void main(String[] args) {
  		OutputStream outputStream =System.out;
  	    PrintWriter out =new PrintWriter(outputStream);
  		FastReader s=new FastReader();
  int t=s.nextInt();
  while(t>0) {
  //	String str=s.next();
  //	String y=s.next();
  //	int n=str.length();
  //	HashMap<Character,ArrayList<Integer>> e=new HashMap<>();
  //	HashSet<String>[] f1=new HashSet[n];
  //	HashSet<String>[] f2=new HashSet[n];
  //	for(int i=0;i<n;i++) {
  //		f1[i]=new HashSet<>();
  //		f2[i]=new HashSet<>();
  //	}
  //	for(int i=n-1;i>=0;i--) {
  //		String h="";
  //		f1[i].add(h);
  //		for(int j=i;j>=0;j--) {
  //			h+=str.charAt(j);
  //			f1[i].add(h);
  //		}
  //	}
  //	for(int i=0;i<n;i++) {
  //		String h="";
  //		f2[i].add(h);
  //		for(int j=i;j<n;j++) {
  //			h+=str.charAt(j);
  //			f2[i].add(h);
  //		}
  //	}
  //	for(int i=0;i<n;i++) {
  //		if(!e.containsKey(str.charAt(i))) {
  //			e.put(str.charAt(i), new ArrayList<>());
  //			e.get(str.charAt(i)).add(i);
  //		}else {
  //			e.get(str.charAt(i)).add(i);
  //		}
  //	}
  //	int o=y.length();
  //	boolean p=false;
  //	out:for(int i=0;i<o;i++) {
  //		String str1=y.substring(0,i+1);
  //		String str2=y.substring(i,o);
  //		if(e.containsKey(y.charAt(i))) {
  //			int g=e.get(y.charAt(i)).size();
  //			for(int j=0;j<g;j++) {
  //				if(f2[e.get(y.charAt(i)).get(j)].contains(str1) && (e.get(y.charAt(i)).get(j)>0) &&  f1[e.get(y.charAt(i)).get(j)-1].contains(str2)) {
  //					p=true;
  ////					System.out.println(e.get(y.charAt(i)).get(j)+" "+y.charAt(i)+" "+str1);
  //					break out;
  //				}
  //			}
  //		}
  //	}
  //		if(p) {
  //			out.println("YES");
  //		}else {
  //			out.println("NO");
  //		}
  	String y=s.next();
  	char[] a=y.toCharArray();
  	char[] b=new char[10];
  	for(int i=0;i<10;i++) {
  		b[i]=a[i];
  	}
  	for(int i=0;i<10;i++) {
  		if(a[i]=='?') {
  			if(i%2==0) {
  				a[i]='1';
  			}else {
  				a[i]='0';
  			}
  		}
  	}
  	for(int i=0;i<10;i++) {
  		if(b[i]=='?') {
  			if(i%2==0) {
  				b[i]='0';
  			}else {
  				b[i]='1';
  			}
  		}
  	}
  	int c1=0;
  	int c2=0;
  	int d1=0;
  	int d2=0;
  	int min=10;		
  	out:for(int i=0;i<10;i++) {
  		if(i%2==0) {
  			d1++;
  		}else {
  			d2++;
  		}
  		if(a[i]=='1') {
  			if(i%2==0) {
  				c1++;
  			}else {
  				c2++;
  			}
  		}
  		int r1=5-d1;
  		int r2=5-d2;
  		if(c1+r1<c2 || c2+r2<c1) {
  			min=(i+1);
  			break out;
  		}
  	}
  	c1=0;
  	c2=0;
  	d1=0;
  	d2=0;
  	out1:for(int i=0;i<10;i++) {
  		if(i%2==0) {
  			d1++;
  		}else {
  			d2++;
  		}
  		if(b[i]=='1') {
  			if(i%2==0) {
  				c1++;
  			}else {
  				c2++;
  			}
  		}
  		int r1=5-d1;
  		int r2=5-d2;
  		if(c1+r1<c2 || c2+r2<c1) {
  			min=Math.min(min,(i+1));
  			break out1;
  		}}
  	out.println(min);
  	t--;
  }
  		
     out.close();
  	}
  	
  static long m=-1;
  static void sf(long[] arr){
          int n = arr.length;
          Random rnd = new Random();
          for(int i=0; i<n; ++i){
              long tmp = arr[i];
              int randomPos = i + rnd.nextInt(n-i);
              arr[i] = arr[randomPos];
              arr[randomPos] = tmp;
          }   
  }
  	
  static HashMap<Integer,pair> e=new HashMap<>();
  static ArrayList<Integer>[] f1=new ArrayList[200001];	
  static PriorityQueue<pair> q=new PriorityQueue<>();	
  static ArrayList<pair>[] f=new ArrayList[200001];
  	static class pair implements Comparable<pair>{
  		private int a;
  		private int b;
  		pair(int a,int b){
  			this.a=a;
  			this.b=b;
  		}
  		public int compareTo(pair o) {
  			return Integer.compare(o.b, this.b);
  		}
  //		
  		
  	}
  	static class node{
  		private int a;
  		private int b;
  		node(int a,int b){
  			this.a=a;
  			this.b=b;
  		}
  	}
  static int[] col=new int[200001];
  static int[] subtree=new int[200001];
  static int[] vis=new int[200001];
  static int dfs(int node) {
  		vis[node]=1;
  		int c=0;
  		for(int i=0;i<f[node].size();i++) {
  			if(vis[f[node].get(i).a]==0) {
  				c+=dfs(f[node].get(i).a);
  			}
  		}
  		subtree[node]+=c;
  		subtree[node]+=col[node];
  		return subtree[node];
  	}
  	public static int upper_bound(long[] a ,long x,int n) {
  		int l=-1;
  		int r=n;
  		while(r>l+1) {
  			int mid=(l+r)/2;
  			if(a[mid]<x) {
  				l=mid;
  			}else {
  				r=mid;
  			}
  		}
  		return r;
  				
  	}
  	public static int lower_bound(long[] a ,long x,int n) {
  		int l=-1;
  		int r=n;
  		while(r>l+1) {
  			int mid=(l+r)/2;
  			if(a[mid]<=x) {
  				l=mid;
  			}else {
  				r=mid;
  			}
  		}
  		return l;
  				
  	}
  	public static long lb(int n,long[] pre,long k,long a,long b,long x,long y) {
  		long l=0;
  		long r=n+1;
  		while(l<r) {
  			long mid=(l+r)/2;
  			long sum=0;
  			long gcd=GCD(a,b);
  			long g=mid/(a*b/gcd);
  			long a1=mid/a;
  			long b1=mid/b;
  			sum+=(pre[(int) g]*(x+y))/100;
  			if(x>=y) {
  				sum+=((pre[(int) a1]-pre[(int) g])*x)/100;
  				sum+=(((pre[(int)(a1+b1-g)]-pre[(int)(a1)])*y))/100;
  			}else {
  				sum+=((pre[(int) b1]-pre[(int) g])*y)/100;
  				sum+=(((pre[(int)(a1+b1-g)]-pre[(int)(b1)])*x))/100;
  			}
  			if(sum>=k) {
  				r=mid;
  			}else {
  				l=mid+1;
  			}
  //			System.out.println(mid+" "+h);
  		}
  		
  		return r;
  				
  	}
  	
  	
  	
  	public static long[] merge_sort(long[] A, int start, int end) {
  		if (end > start) {
  			int mid = (end + start) / 2;
  			long[] v = merge_sort(A, start, mid);
  			long[] o = merge_sort(A, mid + 1, end);
  			return (merge(v, o));
  		} else {
  			long[] y = new long[1];
  			y[0] = A[start];
  			return y;
  		}
  	}
  	public static long[] merge(long a[], long b[]) {
  		
  		long[] temp = new long[a.length + b.length];
  		int m = a.length;
  		int n = b.length;
  		int i = 0;
  		int j = 0;
  		int c = 0;
  		while (i < m && j < n) {
  			if (a[i] < b[j]) {
  				temp[c++] = a[i++];
  			
  			} else {
  				temp[c++] = b[j++];
  			}
  		}
  		while (i < m) {
  			temp[c++] = a[i++];
  		}
  		while (j < n) {
  			temp[c++] = b[j++];
  		}
  		return temp;
  	}	
  	public static int[] Create(int[] a,int n) {
  		int[] b=new int[n+1];
  		for(int i=1;i<=n;i++) {
  			int j=i;
  			int h=a[i];
  			while(i<=n) {
  				b[i]+=h;
  				i=get_next(i);
  			}
  			i=j;
  		}
  		return b;
  	}
  public static int get_next(int a) {
  	return a+(a&-a);
  }
  public static int get_parent(int a) {
  	return a-(a&-a);
  }
  public static int query_1(int[] b,int index) {
  	int sum=0;
  	if(index<=0) {
  		return 0;
  	}
  	while(index>0) {
  		sum+=b[index];
  		index=get_parent(index);
  	}
  	return sum;
  }
  public static int query(int[] b,int n,int l,int r) {
  	int sum=0;
  	sum+=query_1(b,r);
  	sum-=query_1(b,l-1);
  	return sum;
  }
  public static void update(int[] a,int[] b,int n,int index,int val) {
  	int diff=val-a[index];
  	a[index]+=diff;
  	while(index<=n) {
  		b[index]+=diff;
  		index=get_next(index);
  	}	
  }
  	
  //	public static void Create(int[] a,pair[] segtree,int low,int high,int pos) {
  //		if(low>high) {
  //			return;
  //		}
  //		if(low==high) {
  //			segtree[pos].b.add(a[low]);
  //			return ;
  //		}
  //		int mid=(low+high)/2;
  //		Create(a,segtree,low,mid,2*pos);
  //		Create(a,segtree,mid+1,high,2*pos+1);
  //		segtree[pos].b.addAll(segtree[2*pos].b);
  //		segtree[pos].b.addAll(segtree[2*pos+1].b);
  //	}
  //	public static void update(pair[] segtree,int low,int high,int index,int pos,int val,int prev) {
  //		if(index>high || index<low) {
  //			return ;
  //		}
  //		if(low==high && low==index) {
  //			segtree[pos].b.remove(prev);
  //			segtree[pos].b.add(val);
  //			return;
  //		}
  //			int mid=(high+low)/2;
  //			 update(segtree,low,mid,index,2*pos,val,prev);
  //			 update(segtree,mid+1,high,index,2*pos+1,val,prev);
  //			 segtree[pos].b.clear();
  //			  segtree[pos].b.addAll(segtree[2*pos].b);
  //			  segtree[pos].b.addAll(segtree[2*pos+1].b);
  //			  
  //	}
  //	public static pair query(pair[] segtree,int low,int high,int qlow,int qhigh ,int pos) {
  //		if(low>=qlow && high<=qhigh) {
  //			return segtree[pos];
  //		}
  //		if(qhigh<low || qlow>high) {
  //			return new pair();
  //		}
  //		int mid=(low+high)/2;
  //	  pair a1=query(segtree,low,mid,qlow,qhigh,2*pos);
  //	  pair a2=query(segtree,mid+1,high,qlow,qhigh,2*pos+1);
  //	  pair a3=new pair();
  //	  a3.b.addAll(a1.b);
  //	  a3.b.addAll(a2.b);
  //	  return a3;
  //	  
  //	}
  //	
  //	public static int nextPowerOf2(int n) 
  //	{ 
  //	    n--; 
  //	    n |= n >> 1; 
  //	    n |= n >> 2; 
  //	    n |= n >> 4; 
  //	    n |= n >> 8; 
  //	    n |= n >> 16; 
  //	    n++;     
  //	    return n; 
  //	} 
  //	
  ////	static class pair implements Comparable<pair>{
  ////		private int a;
  ////		private long b;
  //////		private long c;
  ////		pair(int a,long b){
  ////			this.a=a;
  ////			this.b=b;
  //////			this.c=c;
  ////		}
  ////		public int compareTo(pair o) {
  //////		if(this.a!=o.a) {
  //////			return Long.compare(this.a, o.a);
  //////		}else {
  ////			return Long.compare(o.b,this.b);
  //////		}
  ////		}
  ////	}
  //	static class pair implements Comparable<pair>{
  //		private int a;
  //		private int b;
  //		pair(int a,int b){
  ////			this.b=new HashSet<>();
  //			this.a=a;
  //			this.b=b;
  //		}
  //		public int compareTo(pair o) {
  //			return Integer.compare(this.b, o.b);
  //		}
  //	}
  	public static int lower_bound(ArrayList<Long> a ,int n,long x) {
  		int l=0;
  		int r=n;
  		while(r>l+1) {
  			int mid=(l+r)/2;
  			if(a.get(mid)<=x) {
  				l=mid;
  			}else {
  				r=mid;
  			}
  		}
  		return l;		
  	}
  	public static int[] is_prime=new int[1000001];
  	public static ArrayList<Long> primes=new ArrayList<>();
   	public static void sieve() {
  		long maxN=1000000;
  		for(long i=1;i<=maxN;i++) {
  			is_prime[(int) i]=1;
  		}
  		is_prime[0]=0;
  		is_prime[1]=0;
  		for(long i=2;i*i<=maxN;i++) {
  			if(is_prime[(int) i]==1) {
  //				primes.add((int) i);
  				for(long j=i*i;j<=maxN;j+=i) {
  					is_prime[(int) j]=0;
  				}
  			}
  		}
  		for(long i=0;i<=maxN;i++) {
  			if(is_prime[(int) i]==1) {
  				primes.add(i);
  			}
  		}		
  	}
  //	public static pair[] merge_sort(pair[] A, int start, int end) {
  //		if (end > start) {
  //			int mid = (end + start) / 2;
  //			pair[] v = merge_sort(A, start, mid);
  //			pair[] o = merge_sort(A, mid + 1, end);
  //			return (merge(v, o));
  //		} else {
  //			pair[] y = new pair[1];
  //			y[0] = A[start];
  //			return y;
  //		}
  //	}
  //	public static pair[] merge(pair a[], pair b[]) {
  //		pair[] temp = new pair[a.length + b.length];
  //		int m = a.length;
  //		int n = b.length;
  //		int i = 0;
  //		int j = 0;
  //		int c = 0;
  //		while (i < m && j < n) {
  //			if (a[i].b >= b[j].b) {
  //				temp[c++] = a[i++];
  //			
  //			} else {
  //				temp[c++] = b[j++];
  //			}
  //		}
  //		while (i < m) {
  //			temp[c++] = a[i++];
  //		}
  //		while (j < n) {
  //			temp[c++] = b[j++];
  //		}
  //		return temp;
  //	}
  	public static long im(long a) {
  		return binary_exponentiation_1(a,mod-2)%mod;
  	}
  	public static long binary_exponentiation_1(long a,long n) {
  		long res=1;
  		while(n>0) {
  			if(n%2!=0) {
  				res=((res)%(mod) * (a)%(mod))%(mod);
  				n--;
  			}else {
  				a=((a)%(mod) *(a)%(mod))%(mod);
  				n/=2;
  			}
  		}
  		return (res)%(mod);
  		
  	}
  
  	public static double bn1(double a,double n) {
  		double res=1;
  		while(n>0) {
  			if(n%2!=0) {
  //				res=((res)%(1000000007) * (a)%(1000000007))%(1000000007);
  				res=(res*a);
  				n--;
  			}else {
  //				a=((a)%(1000000007) *(a)%(1000000007))%(1000000007);
  				a=(a*a);
  				n/=2;
  			}
  		}
  		return (res);	
  	}
  	public static long bn(long a,long n) {
  		long res=1;
  		while(n>0) {
  			if(n%2!=0) {
  				res=res*a;
  				n--;
  			}else {
  				a*=a;
  				n/=2;
  			}
  		}
  		return res;
  		
  	}
  public static long[] fac=new long[300001];
  public static void ff() {
  		fac[0]=(long)1;
  		fac[1]=(long)1;
  		for(long i=2;i<=300000;i++) {
  			fac[(int) i]=(fac[(int) (i-1)]*i)%(m);
  		}
  	}	
  public static long mod=998244353;
  public static long GCD(long a,long b) {
  		if(b==(long)0) {
  			return a;
  		}
  		return GCD(b , a%b);
  	}
  public static long c=0;	
  }