#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {
    fastio
    ll T;
    cin>>T;
    while(T--){
        string s;
        cin>>s;
        ll n=s.length();
        if(n==1){
            cout<<1<<"\n";
            continue;
        }
        ll totalBeautifulStrings = 0;
        vector<ll> unstableStrings,minus;
        ll temp=0;
        for(ll i=0;i<n;i++){
            if(i==0){
                if(s[i]!='?'){
                    temp=1;
                }else{
                    int j=i;
                    while(j+1<n && s[j+1]=='?'){
                        j++;
                    }
                    if(j==n-1){
                        temp=j-i+1;
                        unstableStrings.push_back(temp);
                        temp=0;
                        break;
                    }
                    temp=j-i+2;
                    i=j+1;
                }
                continue;
            }
            if(s[i]=='0' && s[i-1]=='1'){
                temp+=1;
            }else if(s[i]=='1' && s[i-1]=='0'){
                temp+=1;
            }else if((s[i]=='0' && s[i-1]=='0') || (s[i]=='1' && s[i-1]=='1') ){
                unstableStrings.push_back(temp);
                temp=1;
            }else if(s[i]=='?'){
                int j=i;
                while(j+1<n && s[j+1]=='?'){
                    j++;
                }
                if(j==n-1){
                    temp+=j-i+1;
                    unstableStrings.push_back(temp);
                    temp=0;
                    break;
                }
                ll cnt = j-i+1;
                if((cnt%2==0 && s[i-1]!=s[j+1]) || (cnt%2==1 && s[i-1]==s[j+1])){
                    temp+=cnt+1;
                    i=j+1;
                }else{
                    temp+=cnt;
                    unstableStrings.push_back(temp);
                    temp=cnt+1;
                    i=j+1;
                    minus.push_back(cnt);
                }

            }

        }
        unstableStrings.push_back(temp);
        ll sum=0;
        for(auto x:unstableStrings ){
            sum+=(x*(x+1))/2;
        }
        for(auto x:minus ){
            sum-=(x*(x+1))/2;
        }
        cout<<sum<<"\n";
    }
    return 0;
}