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.InputStream;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.util.*;
  
  
  public class Main implements Runnable {
      int n, m, k;
      static boolean use_n_tests = true;
      long mod = 1_000_000_007;
      Random rand = new Random();
      Boolean[][] dp;
  
      void solve(FastScanner in, PrintWriter out, int testNumber) {
          char[] s = in.nextc();
          int goal1 = 0, goal2 = 0, miss1 = 0, miss2 = 0;
          int reminderA = 5, reminderB = 5;
          for (int i = 0; i < s.length; i++) {
              if (i % 2 == 1) {
                  if (s[i] == '1') ++goal2;
                  else if (s[i] == '?') ++miss2;
                  --reminderB;
              }
              else {
                  if (s[i] == '1') ++goal1;
                  else if (s[i] == '?') ++miss1;
                  --reminderA;
              }
  
              if (goal1 + miss1 > goal2 + reminderB) {
                  out.println(i + 1);
                  return;
              }
  
              if (goal2 + miss2 > goal1 + reminderA) {
                  out.println(i + 1);
                  return;
              }
          }
          out.println(10);
      }
  
      boolean check(String c, String  s) {
          for (int i = 0; i < (c.length() + 1) / 2; i++) {
              int j = 0;
              while (j < i) {
                  if (c.charAt(i + j + 1) == c.charAt(i - 1 - j)) {
                      j++;
                  } else {
                      break;
                  }
              }
              if (j == i) {
                  if (s.contains(c.substring(i))) {
                      return true;
                  }
              }
          }
          return false;
      }
  
      boolean rec(char[] s, char[] t, int i, int j) {
          if (j == t.length) {
              return true;
          }
          if (j < 0 || j >= t.length || i < 0 || i >= s.length) {
              return false;
          }
          if (dp[i][j] != null) {
              return dp[i][j];
          }
          if (s[i] == t[j]) {
              if (rec(s, t, i - 1, j + 1)) {
                  return dp[i][j] = true;
              }
              if (rec(s, t, i + 1, j + 1)) {
                  return dp[i][j] = true;
              }
          }
          return dp[i][j] = false;
      }
  
      // ****************************** template code ***********
  
      class Pt {
          int x, y;
  
          boolean sameAxis(Pt b) {
              return b.x == x || b.y == y;
          }
  
          int manxDist(Pt b) {
              return Math.abs(x - b.x) + Math.abs(y - b.y);
          }
  
          void read() {
              x = in.nextInt();
              y = in.nextInt();
          }
      }
  
      void swap(Integer[] a, int i, int j) {
          Integer tmp = a[i];
          a[i] = a[j];
          a[j] = tmp;
      }
  
      void swap(List<Integer> a, int i, int j) {
          Integer tmp = a.get(i);
          a.set(i, a.get(j));
          a.set(j, tmp);
      }
  
      long manhDist(long x, long y, long x1, long y1) {
          return Math.abs(x - x1) + Math.abs(y - y1);
      }
  
      double dist(double x, double y, double x1, double y1) {
          return Math.sqrt(Math.pow(x - x1, 2.0) + Math.pow(y - y1, 2.0));
      }
  
      public static class FW {
          public static void add(long[] t, int i, long value) {
              for (; i < t.length; i |= i + 1)
                  t[i] += value;
          }
  
          public static long sum(long[] t, int i) {
              long res = 0;
              for (; i >= 0; i = (i & (i + 1)) - 1)
                  res += t[i];
              return res;
          }
  
          public static void add(long[] t, int a, int b, long value) {
              add(t, a, value);
              add(t, b + 1, -value);
          }
      }
  
      int sign(int a) {
          if (a < 0) {
              return -1;
          }
          return 1;
      }
  
      long binpow(long a, int b) {
          long res = 1;
          while (b != 0) {
              if (b % 2 == 0) {
                  b /= 2;
                  a *= a;
                  a %= mod;
              }
  
              b--;
              res *= a;
              res %= mod;
          }
          return res;
      }
  
      List<Integer> getGidits(long n) {
          List<Integer> res = new ArrayList<>();
          while (n != 0) {
              res.add((int) (n % 10L));
              n /= 10;
          }
          return res;
      }
  
      List<Integer> generatePrimes(int n) {
          List<Integer> res = new ArrayList<>();
          boolean[] sieve = new boolean[n + 1];
          for (int i = 2; i <= n; i++) {
              if (!sieve[i]) {
                  res.add(i);
              }
              if ((long) i * i <= n) {
                  for (int j = i * i; j <= n; j += i) {
                      sieve[j] = true;
                  }
              }
          }
          return res;
      }
  
      int[] ask(int l) {
          System.out.printf("? %d\n", l);
          System.out.flush();
          return in.nextArray(n);
      }
  
      static int stack_size = 1 << 29;
  
      static class Coeff {
          long mod;
          long[][] C;
          long[] fact;
          boolean cycleWay = false;
  
          Coeff(int n, long mod) {
              this.mod = mod;
              fact = new long[n + 1];
              fact[0] = 1;
              for (int i = 1; i <= n; i++) {
                  fact[i] = i;
                  fact[i] %= mod;
                  fact[i] *= fact[i - 1];
                  fact[i] %= mod;
              }
          }
  
          Coeff(int n, int m, long mod) {
              // n > m
              cycleWay = true;
              this.mod = mod;
              C = new long[n + 1][m + 1];
              for (int i = 0; i <= n; i++) {
                  for (int j = 0; j <= Math.min(i, m); j++) {
                      if (j == 0 || j == i) {
                          C[i][j] = 1;
                      } else {
                          C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
                          C[i][j] %= mod;
                      }
                  }
              }
          }
  
          public long C(int n, int m) {
              if (cycleWay) {
                  return C[n][m];
              }
              return fC(n, m);
          }
  
          private long fC(int n, int m) {
              return (fact[n] * inv(fact[n - m] * fact[m] % mod)) % mod;
          }
  
          private long inv(long r) {
              if (r == 1)
                  return 1;
              return ((mod - mod / r) * inv(mod % r)) % mod;
          }
      }
  
      class Pair {
          int first;
          long second;
  
          Pair(int f, long s) {
              first = f;
              second = s;
          }
  
          public int getFirst() {
              return first;
          }
  
          public long getSecond() {
              return second;
          }
      }
  
      class MultisetTree<T> {
          int size = 0;
  
          TreeMap<T, Integer> mp = new TreeMap<>();
  
          void add(T x) {
              mp.merge(x, 1, Integer::sum);
              size++;
          }
  
          void remove(T x) {
              if (mp.containsKey(x)) {
                  mp.merge(x, -1, Integer::sum);
                  if (mp.get(x) == 0) {
                      mp.remove(x);
                  }
                  size--;
              }
          }
  
          boolean contains(T x) {
              return mp.containsKey(x);
          }
  
          T greatest() {
              return mp.lastKey();
          }
  
          T higher(T x) {
              return mp.higherKey(x);
          }
  
          T smallest() {
              return mp.firstKey();
          }
  
          int size() {
              return size;
          }
  
          int diffSize() {
              return mp.size();
          }
      }
  
      class Multiset<T> {
          int size = 0;
  
          Map<T, Integer> mp = new HashMap<>();
  
          void add(T x) {
              mp.merge(x, 1, Integer::sum);
              size++;
          }
  
          boolean contains(T x) {
              return mp.containsKey(x);
          }
  
          void remove(T x) {
              if (mp.containsKey(x)) {
                  mp.merge(x, -1, Integer::sum);
                  if (mp.get(x) == 0) {
                      mp.remove(x);
                  }
                  size--;
              }
          }
  
          int size() {
              return size;
          }
  
          int diffSize() {
              return mp.size();
          }
      }
  
      static class Range {
          int l, r;
          int id;
  
          public int getL() {
              return l;
          }
  
          public int getR() {
              return r;
          }
  
          public Range(int l, int r, int id) {
              this.l = l;
              this.r = r;
              this.id = id;
          }
      }
  
      static class Array {
          static Range[] readRanges(int n, FastScanner in) {
              Range[] result = new Range[n];
              for (int i = 0; i < n; i++) {
                  result[i] = new Range(in.nextInt(), in.nextInt(), i);
              }
              return result;
          }
  
          static List<List<Integer>> intInit2D(int n) {
              List<List<Integer>> res = new ArrayList<>();
              for (int i = 0; i < n; i++) {
                  res.add(new ArrayList<>());
              }
              return res;
          }
  
          static boolean isSorted(Integer[] a) {
              for (int i = 0; i < a.length - 1; i++) {
                  if (a[i] > a[i + 1]) {
                      return false;
                  }
              }
              return true;
          }
  
          static public long sum(int[] a) {
              long sum = 0;
              for (int x : a) {
                  sum += x;
              }
              return sum;
          }
  
          static public long sum(long[] a) {
              long sum = 0;
              for (long x : a) {
                  sum += x;
              }
              return sum;
          }
  
          static public long sum(Integer[] a) {
              long sum = 0;
              for (int x : a) {
                  sum += x;
              }
              return sum;
          }
  
          static public int min(Integer[] a) {
              int mn = Integer.MAX_VALUE;
              for (int x : a) {
                  mn = Math.min(mn, x);
              }
              return mn;
          }
  
          static public int min(int[] a) {
              int mn = Integer.MAX_VALUE;
              for (int x : a) {
                  mn = Math.min(mn, x);
              }
              return mn;
          }
  
          static public int max(Integer[] a) {
              int mx = Integer.MIN_VALUE;
              for (int x : a) {
                  mx = Math.max(mx, x);
              }
              return mx;
          }
  
          static public int max(int[] a) {
              int mx = Integer.MIN_VALUE;
              for (int x : a) {
                  mx = Math.max(mx, x);
              }
              return mx;
          }
  
          static public int[] readint(int n, FastScanner in) {
              int[] out = new int[n];
              for (int i = 0; i < out.length; i++) {
                  out[i] = in.nextInt();
              }
              return out;
          }
      }
  
      class Graph {
          List<List<Integer>> graph;
  
          Graph(int n) {
              create(n);
          }
  
          private void create(int n) {
              List<List<Integer>> graph = new ArrayList<>();
              for (int i = 0; i < n; i++) {
                  graph.add(new ArrayList<>());
              }
              this.graph = graph;
          }
  
          void read(int m, FastScanner in) {
              for (int i = 0; i < m; i++) {
                  int v = in.nextInt() - 1;
                  int u = in.nextInt() - 1;
                  graph.get(v).add(u);
              }
          }
  
          void readBi(int m, FastScanner in) {
              for (int i = 0; i < m; i++) {
                  int v = in.nextInt() - 1;
                  int u = in.nextInt() - 1;
                  graph.get(v).add(u);
                  graph.get(u).add(v);
              }
          }
      }
  
      class FastScanner {
          BufferedReader br;
          StringTokenizer st;
  
          public FastScanner(InputStream io) {
              br = new BufferedReader(new InputStreamReader(io));
          }
  
          public String line() {
              String result = "";
              try {
                  result = br.readLine();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              return result;
          }
  
          public String next() {
              while (st == null || !st.hasMoreElements()) {
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
              return st.nextToken();
          }
  
          public char[] nextc() {
              return next().toCharArray();
          }
  
          public int nextInt() {
              return Integer.parseInt(next());
          }
  
          public int[] nextArray(int n) {
              int[] res = new int[n];
              for (int i = 0; i < n; i++) {
                  res[i] = in.nextInt();
              }
              return res;
          }
  
          public long[] nextArrayL(int n) {
              long[] res = new long[n];
              for (int i = 0; i < n; i++) {
                  res[i] = in.nextLong();
              }
              return res;
          }
  
          public Long[] nextArrayL2(int n) {
              Long[] res = new Long[n];
              for (int i = 0; i < n; i++) {
                  res[i] = in.nextLong();
              }
              return res;
          }
  
  
          public Integer[] nextArray2(int n) {
              Integer[] res = new Integer[n];
              for (int i = 0; i < n; i++) {
                  res[i] = in.nextInt();
              }
              return res;
          }
  
          public long nextLong() {
              return Long.parseLong(next());
          }
  
      }
  
      void run_t_tests() {
          int t = in.nextInt();
          int i = 0;
          while (t-- > 0) {
              solve(in, out, i++);
          }
      }
  
      void run_one() {
          solve(in, out, -1);
      }
  
      @Override
      public void run() {
          in = new FastScanner(System.in);
          out = new PrintWriter(System.out);
          if (use_n_tests) {
              run_t_tests();
          } else {
              run_one();
          }
          out.close();
      }
  
      static FastScanner in;
      static PrintWriter out;
  
      public static void main(String[] args) throws InterruptedException {
          Thread thread = new Thread(null, new Main(), "", stack_size);
          thread.start();
          thread.join();
      }
  }