#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi > vvi; 
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int,int> pr;
typedef unordered_set<int> st;
typedef unordered_map<int,int> mp;
typedef unordered_map<int,vi> mpv; 
#define mpr(a,b) make_pair(a,b)
#define mod 1000000007
#define infl (1LL << 60LL)
#define inf INT_MAX 
#define nl cout<<"\n"
void fast()
{
	//code by comore
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
int gcd(int a, int b) 
{
    if (!a || !b)
        return a | b;
    unsigned shift = __builtin_ctz(a | b);
    a >>= __builtin_ctz(a);
    do {
        b >>= __builtin_ctz(b);
        if (a > b)
            swap(a, b);
        b -= a;
    } while (b);
    return a << shift;
}
void solve()
{
	int i,j,k,l,f1,f2;
	ll r=0,c1,c=0;
	string s;
	cin>>s;
	l=s.length();
	for(i=0;i<l;i++)
		if(s[i]!='?')
			break;
	c1=i;
	r=r+(c1*(c1+1))/2;
	for(;i<l;)
	{
			if(s[i]=='1')
				{f1=1;f2=0;}
			else
				{f1=0;f2=1;}
			c=1;
			for(k=i+1;k<l;k++)
			{
				c++;
				if(s[k]=='?')
				{
					continue;
				}
				else if(c%2==0)
				{
					if(s[k]!=(char)(f2+48))
					{
						c--;
						break;
					}
				}
				else
				{
					if(s[k]!=(char)(f1+48))
					{
						c--;
						break;
					}
				}
			}
			r=r+(c*(c+1))/2+c*c1;
			j=k-1;
			for(;j>=0;j--)
				if(s[j]!='?')
					break;
			c1=k-1-j;
			i=k;
	}
	cout<<r<<"\n";
}	
int main()
{
	fast();
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}