#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll inf = 1000000007 ;
bool compare(int a,int b){
    return (a>b);
}
ll power(ll a,ll pow){
    ll ans=1;
    if(a<0) a+=inf;
    while(pow){
        if(pow%2==1){
            ans = ((ans)%inf*(a)%inf)%inf;
        }
        a = ((a)%inf*(a)%inf)%inf;
        if(a<0) a+=inf;
        pow/=2;
    }
    return ans;
}
int main(){
    IOS
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        int n = s.size();
        int arr[n];
        int qnum=0,lnum=-1,tot=0;
        for(int i=0;i<n;i++){
            if(s[i]=='?') tot+=1;
        }
        arr[n-1]=1;
        if(s[n-1]=='?') qnum=1;
        else if(s[n-1]=='1') lnum=1;
        else lnum=0;
        // cout<<lnum<<' '<<qnum<<endl;
        for(int i=n-2;i>=0;i--){
            if(s[i]=='?'){
                // cout<<"Y"<<' ';
                arr[i]=arr[i+1]+1;
                qnum+=1;
            }
            else{
                if(s[i+1]!='?'){
                    if(s[i]==s[i+1]){
                        arr[i]=1;
                    }
                    else{
                        arr[i]=arr[i+1]+1;
                    }
                }
                else{
                    // cout<<"M"<<' ';
                    if(lnum!=-1){
                        if((qnum%2!=0 && s[i]=='0'+lnum) ||(qnum%2==0 && s[i]!='0'+lnum)) arr[i] = arr[i+1]+1;
                        else arr[i] = qnum+1;
                    }
                    else{
                        arr[i] = qnum+1;
                    }
                }
                qnum=0;
                lnum=s[i]-'0';
            }
        }
        // for(int i=0;i<n;i++){
        //     cout<<arr[i]<<' ';
        // }
        // cout<<endl;
        ll count=0;
        int j=0;
        while(j<n){
            count+=arr[j];
            j++;
        }
        cout<<count<<endl;
    }
    return 0;
}