#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 2e5+10;
inline int read(){
    int x=0,f=1; char ch;
    while((ch=getchar())<'0'||ch>'9')if(ch=='-')f=-1;
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return x*f;
}
int main(){
    LL i,j,n;
    char s[N];
    int t;
    cin>>t;
    while(t--){
        cin>>(s+1);
        n=strlen(s+1);
        if(n==1)cout<<"1"<<endl;
        else{
            LL ans=n,co=0,kiss=0;
            for(i=1;i<=n;i++){
                if(s[i]=='?'){
                    LL k=i,cn=!(s[i-1]-'0');
                    while(k<=n&&s[k]=='?'){
                        k++;
                        cn=!cn;
                        co++;
                    }
                    if(k==n+1){
                        break;
                    }
                    if(i==1||s[k]-'0'==cn){
                        co++;
                        i=k;
                    }
                    else {
                        ans+=(co-1)*co/2-(kiss-1)*kiss/2;
                        co=k-i+1;
                        kiss=co-1;
                        i=k;
                    }
                }
                else{
                    if(i==1)co=1;
                    else if(s[i]==s[i-1]){
                        ans+=(co-1)*co/2-(kiss-1)*kiss/2;
                        kiss=0;
                        co=1;
                    }
                    else{
                        co++;
                    }
                }
            }
            ans+=(co-1)*co/2-(kiss-1)*kiss/2;
            cout<<ans<<endl;
        }
    }
    return 0;
}