#include <bits/stdc++.h>
#define clr(x) memset(x, 0, sizeof x)
#define LL long long

using namespace std;

const int maxn = 2e5+5;
int t,n,top;
LL ans;
LL dp[10][maxn];
char s[maxn];

int main() {
	cin >> t;
	while(t--) {
		scanf("%s",s+1);
		n = strlen(s+1);
		ans = 0;
		for(int i = 1; i <= n; i++)
			dp[0][i] = s[i] == '0' ? dp[1][i-1]+dp[3][i-1]+1 : 0,
			dp[1][i] = s[i] == '1' ? dp[0][i-1]+dp[2][i-1]+1 : 0,
			dp[2][i] = s[i] == '?' ? dp[1][i-1]+dp[3][i-1]+1 : 0,
			dp[3][i] = s[i] == '?' ? dp[0][i-1]+dp[2][i-1]+1 : 0,
			ans += dp[0][i]+dp[1][i]+dp[2][i]+dp[3][i];
		LL lft = 0, rgt = 0, f = 0;
		for(int i = 1; i <= n; i++) {
			if(s[i] == '?') {
				if(!f) lft = i, rgt = i, f = 1;
				else rgt = i;
			}
			if(s[i] != '?' && f) {
				ans -= (rgt-lft+2)*(rgt-lft+1)/2;
				f = 0;
			}
		}
		if(f) ans -= (rgt-lft+2)*(rgt-lft+1)/2;
        printf("%lld\n",ans);
	}
	return 0;
}
