#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#define int long long
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define endl cout<<'\n';
#define LINE cout << "-----------------------\n";
#define IOS ios::sync_with_stdio(false),cin.tie(0);
using namespace std;
const int maxn = 1e6+5;

signed main(){
	IOS;
	int t ; 
	cin >> t ;
	char need;
	while(t--){
		string s; cin >> s;
		int ans=0 , cnt;
		vector<int> pos(s.size());
		need = '0' , cnt = 0;
		for(int i=0 ; i<(int)s.size() ; ++i){
			if(s[i] == need || s[i] == '?') ++cnt , pos[i] = cnt;
			else cnt = 0;
			if(need == '0') need = '1';
			else need = '0';
		}
		need = '1' , cnt = 0;
		for(int i=0 ; i<(int)s.size() ; ++i){
			if(s[i] == need || s[i] == '?') ++cnt , pos[i] = max(pos[i] , cnt);
			else cnt = 0;
			if(need == '0') need = '1';
			else need = '0';
		}
		for(int &c : pos) ans += c;
		cout << ans << '\n';
	}
}