#include <bits/stdc++.h>
using namespace std;
void solve() {
  int b = 0, c = 0, d = 0, e = 0;
  char a[12] = {'\0'};
  for (int i = 1; i < 11; i++) cin >> a[i];
  for (int i = 1; i < 11; i++) {
    if (a[i] == '1') {
      if (i % 2 == 1)
        b++;
      else
        c++;
    } else if (a[i] == '?') {
      if (i % 2 == 1)
        d++;
      else
        e++;
    }
    if (b + d > (11 - i) / 2 + c || c + e > (10 - i) / 2 + b) {
      cout << i << endl;
      break;
    }
    if (i == 10) cout << 10 << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.setf(ios::fixed, ios::floatfield);
  cin.tie(NULL);
  int a;
  cin >> a;
  while (a--) solve();
  return 0;
}
