#include #define INF 2000000000 using namespace std; typedef long long ll; int read(){ int f = 1, x = 0; char c = getchar(); while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();} while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar(); return f * x; } int n; char s[2100000]; int lt[2100000], tot; void init(){ scanf("%s", s); n = strlen(s); } void solve(){ int cnt1 = 0, cnt2 = 0, acc = 0; tot = 0; for (int i = 0; i < n; ++i){ if (s[i] == '?'){ if (cnt2 > 0){ if (cnt2 == i){ if (cnt2 & 1) ++acc; }else { if ((cnt2 & 1) == 0) ++acc; } } cnt2 = 0, ++cnt1; }else { if (cnt1) lt[tot++] = cnt1; cnt1 = 0; ++cnt2; } } if (cnt2 == n){ printf("%d\n", ((n + 1) & 1)); return ; } if (cnt2){ if (cnt2 & 1) ++acc; } if (cnt1) lt[tot++] = cnt1; int ans = 0; for (int i = 0; i < tot; ++i){ if (lt[i] & 1){ int anst = ans; for (int j = 0; j <= lt[i] + 1; j += 2) anst = max(anst, ans | j); ans = anst; }else { int anst = ans; for (int j = 0; j <= lt[i]; j += 2) anst = max(anst, ans | j); ans = anst; ++acc; } } acc %= 2; ans += acc; printf("%d\n", ans); } int main(){ int T = read(); while (T--){ init(); solve(); } return 0; }