#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const int N = 50000;
long long mod(long long x) { return ((x % M + M) % M); }
long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }
long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }
bool prime(int n) {
  for (int i = 2; i < min(N, n); i++)
    if (n % i == 0) return 0;
  return 1;
}
long long ceil(long long a, long long b) {
  long long s;
  if (a % b == 0) {
    s = a / b;
  } else {
    s = (a / b) + 1;
  }
  return s;
}
long long end(long long w1, long long w2, long long rem1, long long rem2) {
  if (w1 > (w2 + rem2) || w2 > (w1 + rem1)) {
    return 1;
  } else {
    return 0;
  }
}
long long m2(string s) {
  for (long long i = 0; i < s.size(); i++) {
    if (s[i] == '?') {
      if ((i + 1) % 2 == 0) {
        s[i] = '1';
      } else {
        s[i] = '0';
      }
    }
  }
  long long w1 = 0, w2 = 0, rem1 = 5, rem2 = 5, ans = 0;
  for (long long i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      w1++;
      rem1--;
    } else {
      rem1--;
    }
    ans++;
    i++;
    if (end(w1, w2, rem1, rem2)) {
      return ans;
    }
    if (s[i] == '1') {
      w2++;
      rem2--;
    } else {
      rem2--;
    }
    ans++;
    if (end(w1, w2, rem1, rem2)) {
      return ans;
    }
  }
  return 10;
}
long long m1(string s) {
  for (long long i = 0; i < s.size(); i++) {
    if (s[i] == '?') {
      if ((i + 1) % 2 == 1) {
        s[i] = '1';
      } else {
        s[i] = '0';
      }
    }
  }
  long long w1 = 0, w2 = 0, rem1 = 5, rem2 = 5, ans = 0;
  for (long long i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      w1++;
      rem1--;
    } else {
      rem1--;
    }
    ans++;
    i++;
    if (end(w1, w2, rem1, rem2)) {
      return ans;
    }
    if (s[i] == '1') {
      w2++;
      rem2--;
    } else {
      rem2--;
    }
    ans++;
    if (end(w1, w2, rem1, rem2)) {
      return ans;
    }
  }
  return 10;
}
void solve() {
  string s;
  ;
  cin >> s;
  cout << min(m1(s), m2(s)) << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  long long c = 0;
  long long T;
  cin >> T;
  while (T--) {
    solve();
  }
}
