#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
const long long mod = 1e9 + 7;
long long fP(long long base, long long power) {
  long long result = 1;
  while (power > 0) {
    if (power & 1) {
      result = result * base % mod;
    }
    power >>= 1;
    base = (base * base) % mod;
  }
  return result;
}
using namespace std;
const long long maxn = 1e5 + 50;
char s[15];
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long ans;
    long long q, w;
    long long cun1 = 0, cun2 = 0;
    cin >> s + 1;
    cout << s << endl;
    ans = 10;
    q = w = 0;
    for (long long i = (1); i <= (11); i++) {
      if (i & 1 && (s[i] == '?' || s[i] == '1')) q++;
      if (!(i & 1) && s[i] == '1') w++;
      if (i & 1)
        cun1 = (10 - i - 1) / 2;
      else
        cun1 = (10 - i) / 2;
      if (i & 1)
        cun2 = (10 - i + 1) / 2;
      else
        cun2 = (10 - i) / 2;
      if (q - w > cun2) {
        ans = min(ans, i);
        break;
      }
      if (w - q > cun1) {
        ans = min(ans, i);
        break;
      }
    }
    q = w = 0;
    for (long long i = (1); i <= (11); i++) {
      if (i & 1 && s[i] == '1') q++;
      if ((!(i & 1)) && (s[i] == '1' || s[i] == '?')) w++;
      if (i & 1)
        cun1 = (10 - i - 1) / 2;
      else
        cun1 = (10 - i) / 2;
      if (i & 1)
        cun2 = (10 - i + 1) / 2;
      else
        cun2 = (10 - i) / 2;
      if (q - w > cun2) {
        ans = min(ans, i);
        break;
      }
      if (w - q > cun1) {
        ans = min(ans, i);
        break;
      }
    }
    cout << ans << endl;
    ;
  }
}
