#include <bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define cases long long int t;cin>>t;while(t--)
#define fio ios::sync_with_stdio(false); cin.tie(0)
#define ALL(v) (v).begin(), (v).end() 
#define twod(n,m) vector<vector<int> > arr( n , vector<int> (m, 0))
#define prs(s,n) for(ll i=0;i<n;i++)cout<<s[i];
#define pra(arr,n) for(ll i=0;i<n;i++)cout<<arr[i]<<" ";
#define err1(a) cout<<#a<<" "<<a<<endl;
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl;
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl;
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl;
using namespace std;
int main() 
{
	fio;
	cases
	{
	    string s;
	    cin>>s;
	    ll n = s.length();
	    ll i = 1;
	    ll curr = 1;
	    ll ans = 0;
	    while(i<n)
	    {
	        if(s[i]=='?')
	        {
	            ll j = i;
	            while(j<n && s[i]==s[j])
	                ++j;
	            ll diff = j-i;
	            if(j==n)
	            {
	                i = j;
	                curr += diff;
	                continue;
	            }
	            else
	            {
	                if((s[i-1] == s[j] && diff%2) || (s[i-1]!=s[j] && diff%2==0) || s[i-1]=='?')
	                {
	                        curr += diff;
	                        i = j;
	                }
	                else
	                {
	                    curr += diff;
                        ans += (curr*(curr+1))/2;
                        i = j;
                        ans -= (diff*(diff+1))/2;
                        curr = diff;
                    }
	            }
	            continue;
	        }
	        else if(s[i]==s[i-1])
	        {
	            ans += (curr*(curr+1))/2;
	            curr = 1;
	        }
	        else
	            ++curr;
	        ++i;
	       // err3(i,curr,ans);
	    }
	   // err3(i,curr,ans);
	    ans += (curr*(curr+1))/2;
	    cout<<ans<<endl;
	}
}