#include "bits/stdc++.h"
using namespace std;
#define T()               int test;cin>>test;while(test--)
#define int               long long 
#define pb                push_back
#define fo(i,n)           for(int i=0;i<n;i++)
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;
const int N=100000;

        


void solve()
{
    string s;cin>>s;int n=s.length();int mx1=0;int mx2=0;int ans=0;
    
    for(int i=0;i<n;i++){
        if(s[i]=='0'){
            mx1++;
            mx2=0;
            ans+=mx1;
        }
        else{
            if(s[i]=='1'){
                mx2++;
                mx1=0;
                ans+=mx2;
            }
            else{
                mx1++;
                mx2++;
                ans+=max(mx1,mx2);
            }
        }
        swap(mx1,mx2);
    }
    cout<<ans<<"\n";
}
signed main()
{
    // manipulated_seive(N);
	T()
	{
		solve();
	}
}