#include <bits/stdc++.h>
using namespace std;
void test_case() {
  string s;
  cin >> s;
  int ans = 9;
  {
    int c1 = 0, c2 = 0;
    for (int i = 0; i < s.length(); i++) {
      if (i % 2)
        c2 += (s[i] == '1');
      else
        c1 += (s[i] != '0');
      if (c1 > c2 + (10 - i) / 2) ans = min(ans, i);
    }
  }
  {
    int c1 = 0, c2 = 0;
    for (int i = 0; i < s.length(); i++) {
      if (i % 2)
        c2 += (s[i] != '0');
      else
        c1 += (s[i] == '1');
      if (c2 > c1 + (9 - i) / 2) ans = min(ans, i);
    }
  }
  cout << ans + 1 << "\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) test_case();
}
