#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define pb push_back
#define MOD 1000000007
#define sz5 100005
#define sz6 1000005
#define UP upper_bound
#define LB lower_bound
#define F first
#define S second
#define PI pair<int,int>
#define PL pair<ll,ll>
#define VI vector<int>
#define VL vector<ll>

char change(char a){
    if(a=='0')
        return '1';
    return '0';
}

ll find_next(ll idx, string &st){
    char pre=st[idx];
    for(ll la=idx+1;la<st.length();la++){
        char cur = change(pre);
        // cout<<":"<<la<<' '<<pre<<' '<<cur<<' '<<st[la]<<endl;
        if(pre==st[la])
            return la-1;

        pre=cur;
    }

    return (ll)st.length()-1;
}

ll find_pre(ll idx, string &st){
    char pre=st[idx];
    for(ll la=idx-1;la>=0;la--){
        if(st[la]!='?')
            return la+1;
    }

    return 0;
}

void test_case(void) {
    ll la,lb, ans=0;
    string st;
    cin>>st;
    ll n=st.length();

    int cnt=0;
    for(la=0;la<st.length();la++){
        if(st[la]=='?')
            cnt++;
    }

    if(cnt==n){
        // ll dif=n;
        ans=(n*(n+1))/2;
        cout<<ans<<endl;
        return;
    }

    la=0;
    bool mk=true;
    while(la<n){
        if(st[la]=='?'){
            la++;
            continue;
        }
        ll a=find_next(la, st);
        ll b=find_pre(la, st);
        // cout<<la<<' ';
        // cout<<a<<' '<<b<<endl;

        ll tot=a-b+1;
        ans+=(tot*(tot+1))/2;
        if(!mk){
            ll s=la-b;
            ans-=(s*(s+1))/2;
        }
        la=a+1;
        mk=false;
    }

    cout<<ans<<endl;
}

int main() {
    FAST

    #ifndef ONLINE_JUDGE
        freopen("in", "r", stdin);
        // freopen("out", "w", stdout);
    #endif

    int t;  cin>>t;
    for(int i=1;i<=t;i++){
        // cout<<"Case #"<<i<<": ";
        test_case();
    }

    return 0;
}