#include <bits/stdc++.h>
using namespace std;
const long long mxn = 1e5 + 1;
const long long mod = 1e9 + 7;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
void gen(vector<string> &arr, long long n, string s, long long i) {
  if (i == n) {
    arr.push_back(s);
    return;
  }
  s.push_back('0');
  gen(arr, n, s, i + 1);
  s[s.length() - 1] = '1';
  gen(arr, n, s, i + 1);
}
long long compute(string s) {
  long long sum1 = 0;
  long long sum2 = 0;
  for (long long i = 0; i < s.length(); i++) {
    if (i % 2 == 0) {
      if (s[i] == '1') sum1++;
      if (sum1 > sum2 + (10 - i) / 2) return i + 1;
      if (sum2 > sum1 + (10 - i) / 2 - 1) return i + 1;
    } else {
      if (s[i] == '1') sum2++;
      if (sum2 > sum1 + (10 - i) / 2) return i + 1;
      if (sum1 > sum2 + (10 - i) / 2) return i + 1;
    }
  }
  return 10;
}
void solve() {
  string s;
  cin >> s;
  long long n = 0;
  for (long long i = 0; i < s.length(); i++)
    if (s[i] == '?') n++;
  string t;
  vector<string> a;
  gen(a, n, t, 0);
  vector<string> arr;
  for (long long i = 0; i < a.size(); i++) {
    string t = s;
    long long cnt = 0;
    for (long long j = 0; j < t.length(); j++) {
      if (t[j] == '?') {
        t[j] = a[i][cnt];
        cnt++;
      }
    }
    arr.push_back(t);
  }
  long long amin = INT_MAX;
  for (long long i = 0; i < arr.size(); i++) amin = min(amin, compute(arr[i]));
  cout << amin << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) solve();
  return 0;
}
