#include <bits/stdc++.h>
using namespace std;
const int W = 1e7 + 10;
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p) {
  cerr << "{";
  _print(p.first);
  cerr << ",";
  _print(p.second);
  cerr << "}";
}
template <class T>
void _print(vector<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void _print(set<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void _print(multiset<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v) {
  cerr << "[ ";
  for (auto i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
inline void boostIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int solve(int i, int goalA, int goalB, int chanceA, int chanceB, string &s) {
  if (i > 9) return 0;
  if (goalA > chanceB + goalB) {
    return 0;
  }
  if (goalB > chanceA + goalA) {
    return 0;
  }
  if (s[i] == '1') {
    if (i % 2 == 0) {
      goalA++;
      chanceA--;
    } else {
      goalB++, chanceB--;
    }
    return 1 + solve(i + 1, goalA, goalB, chanceA, chanceB, s);
  } else if (s[i] == '0') {
    if (i % 2 == 0)
      chanceA--;
    else
      chanceB--;
    return 1 + solve(i + 1, goalA, goalB, chanceA, chanceB, s);
  } else if (s[i] == '?') {
    if (i % 2 == 0) {
      return 1 + min(solve(i + 1, goalA + 1, goalB, chanceA - 1, chanceB, s),
                     solve(i + 1, goalA, goalB, chanceA - 1, chanceB, s));
    } else {
      return 1 + min(solve(i + 1, goalA, goalB + 1, chanceA, chanceB - 1, s),
                     solve(i + 1, goalA, goalB, chanceA, chanceB - 1, s));
    }
  }
  return 0;
}
int main() {
  boostIO();
  long long tc = 1;
  cin >> tc;
  while (tc--) {
    string s;
    cin >> s;
    cout << solve(0, 0, 0, 5, 5, s) << "\n";
  }
  return 0;
}
