#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long n = (long long)s.length();
    vector<vector<long long>> cnt(2, vector<long long>(2));
    for (long long i = 0; i < n; i++) {
      if (s[i] == '?') {
        cnt[i % 2][0]++;
      } else if (s[i] == '1') {
        cnt[i % 2][1]++;
      }
    }
    long long a = (n + 1) / 2;
    long long b = n - a;
    long long res = n - 1;
    {
      long long player1 = 0;
      long long player2 = 0;
      long long ta = a;
      long long tb = b;
      vector<vector<long long>> tmp = cnt;
      for (long long i = 0; i < n; i++) {
        if (i % 2 == 0) {
          if (s[i] == '1') {
            ++player1;
            --tmp[i % 2][1];
          } else if (s[i] == '1') {
            --tmp[i % 2][0];
          }
          --ta;
        } else {
          if (s[i] == '1') {
            ++player2;
            --tmp[i % 2][1];
          }
          if (s[i] == '?') {
            ++player2;
          }
          if (s[i] == '?') {
            --tmp[i % 2][0];
          }
          --tb;
        }
        long long p1 = player1 + tmp[0][0] + tmp[0][1];
        long long p2 = player2 + tmp[1][0] + tmp[1][1];
        if (player1 > player2 + tb) {
          res = min(res, i);
        } else if (player2 > player1 + ta) {
          res = min(res, i);
        }
      }
    }
    {
      long long player1 = 0;
      long long player2 = 0;
      long long ta = b;
      long long tb = a;
      vector<vector<long long>> tmp = cnt;
      for (long long i = 0; i < n; i++) {
        if (i % 2 == 1) {
          if (s[i] == '1') {
            ++player1;
            --tmp[i % 2][1];
          } else if (s[i] == '1') {
            --tmp[i % 2][0];
          }
          --ta;
        } else {
          if (s[i] == '1') {
            ++player2;
            --tmp[i % 2][1];
          }
          if (s[i] == '?') {
            ++player2;
          }
          if (s[i] == '?') {
            --tmp[i % 2][0];
          }
          --tb;
        }
        long long p1 = player1 + tmp[0][0] + tmp[0][1];
        long long p2 = player2 + tmp[1][0] + tmp[1][1];
        if (player1 > player2 + tb) {
          res = min(res, i);
        } else if (player2 > player1 + ta) {
          res = min(res, i);
        }
      }
    }
    cout << res + 1 << '\n';
  }
  return 0;
}
