#include<bits/stdc++.h>
#define maxN 300005
#define P 1000000007
#define INF 0x3f3f3f3f
using namespace std;
using ll=long long;
bool f[maxN];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int T;cin>>T;
    while(T--)
    {
        string s;cin>>s;
        bool cur=0;
        for(int i=0;i<s.length();++i){
            if(s[i]=='?'){
                cur=!cur;
                continue;
            }
            if(s[i]-'0'==cur) f[i]=0;
            else f[i]=1;
            cur=!cur;
        }
        int n=s.length();
        int r[2]={n,n};
        ll ans=0;
        for(int i=s.length()-1;i>=0;--i){
            if(s[i]=='?'){
                ans+=max(r[0],r[1])-i;
                continue;
            }
            ans+=r[!f[i]]-i;
            // cout<<s.substr(i,r[!f[i]]-i)<<"\n";
            r[f[i]]=i;
        }
        cout<<ans<<"\n";
    }
}
