#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed;cout.precision(10);
#define endl "\n"
#define tc ll T; cin >> T; while(T--)
#define pb push_back
#define mod 1000000007
#define S second
#define F first
using namespace std;
typedef long long ll;
const int N = 7005;

int32_t main(){

    fastio;
    tc{
        string s; cin >> s;
        int n = s.length();

        ll ans = 1ll;
        int dp[2][n], c0 = 0, c1 = 0;
        memset(dp, 0, sizeof(dp));
        if(s[n-1] == '0') dp[0][n-1] = 1;
        if(s[n-1] == '1') dp[1][n-1] = 1;
        if(s[n-1] == '?') dp[0][n-1] = dp[1][n-1] = 1;

        for(int i = n-2; i >= 0; i--){
            if(s[i] == '0'){
                if(s[i+1] == '0') dp[0][i] = 1;
                else dp[0][i] = dp[1][i+1] + 1;
                ans += dp[0][i];
            }   
            else if(s[i] == '1'){
                if(s[i+1] == '1') dp[1][i] = 1;
                else dp[1][i] = dp[0][i+1] + 1;
                ans += dp[1][i];
            }   
            else{
                dp[0][i] = dp[1][i+1] + 1;
                dp[1][i] = dp[0][i+1] + 1;
                ans += max(dp[0][i], dp[1][i]);
            }      
        }
        cout << ans << endl;
    }

    

    return 0;
}