#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1e18
#define F first
#define S second
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pll pair<ll,ll>
#define vl vector<ll>
#define all(x) (x).begin(),(x).end()
#define siz 300005
#define MOD   998244353
vector<vector<ll> > adj(siz);
vector<ll> vis(siz,0);
ll mod=MOD;
ll power(ll x, ll y){
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return ((power(x, y / 2))%mod * (power(x, y / 2))%mod)%mod;
    else
        return (x%mod * (power(x, y / 2))%mod * (power(x, y / 2))%mod)%mod;
}
ll foo(ll n){
	return ( n*(n+1) )/2;
}
int main(){
	ll q=1;
	cin>>q;
	while(q--){
		string s;
		cin>>s;
		ll n=s.size(),gap=0,last=-1,l=0,r=0,ans=0;
		while(l<n){
			//cout<<last<<" "<<l<<" "<<r<<" "<<ans<<endl;
			if(r==n or (last!=-1 and s[r]!='?' and 
				((s[r]!=s[last] and gap%2==1)
					or(s[r]==s[last] and gap%2==0)) ) ){
				if(r==n){
					ans+=foo(r-l);
					break;
				}
				ll nl=last+1;
				ans+=(foo(r-l)-foo(r-nl));
				if(last<nl)last=-1;l=nl;
			}
			else{
				if(s[r]!='?'){last=r;gap=0;}
				else gap++;
				r++;
			}
		}
		cout<<ans<<endl;
	}
}