#include <bits/stdc++.h>
using namespace std;
template <typename input_type>
inline input_type input() {
  input_type inp;
  cin >> inp;
  return inp;
}
void solve() {
  int ans = 1e9;
  string goal = input<string>();
  vector<int> hagh;
  for (int i = 0; i < 10; i++) {
    if (goal[i] == '?') {
      hagh.push_back(i);
    }
  }
  for (int mod = 0; mod < 2; mod++) {
    for (int i = 0; i < hagh.size(); i++) {
      if (hagh[i] % 2 == mod) {
        goal[hagh[i]] = '1';
      } else {
        goal[hagh[i]] = '0';
      }
    }
    int idx = 0, score[2] = {0, 0}, baghi[2] = {5, 5};
    while (idx < 10) {
      if (goal[idx] == '1') {
        score[idx % 2]++;
      }
      baghi[idx % 2]--;
      idx++;
      if (((score[1] < score[0]) and (score[0] - score[1] > baghi[1])) or
          ((score[0] < score[1]) and (score[1] - score[0] > baghi[0]))) {
        break;
      }
    }
    ans = min(ans, idx);
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int tc = input<int>();
  while (tc--) {
    solve();
  }
  return 0;
}
