#include <bits/stdc++.h>
using namespace std;
string s;
int ans;
void check() {
  int sc[2] = {0}, ki[2] = {0};
  for (int i = 0; i < 10; i++) {
    sc[i % 2] += (s[i] == '1');
    ki[i % 2] += 1;
    if (sc[0] + 5 - ki[0] < sc[1] || sc[1] + 5 - ki[1] < sc[0])
      ans = min(ans, i + 1);
  }
}
void solve(int idx) {
  if (idx == 10) {
    check();
    return;
  }
  if (s[idx] == '?') {
    s[idx] = '1';
    solve(idx + 1);
    s[idx] = '0';
    solve(idx + 1);
    s[idx] = '?';
  } else
    solve(idx + 1);
}
void code() {
  cin >> s;
  ans = 10;
  solve(0);
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    code();
  }
}
