#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<set>
#include<vector>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long ll;
const int mod = 1000000007;


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--) {
		string s; cin >> s;		
		ll n = (ll) s.size();
		ll prev = 0;
		ll start = 0, ans = 0, ques = 0;
		for (ll i = 1; i < n; i++) {
			if (s[i] == '?') { ques++; continue; }
			if (s[prev] != '?' && (s[i] != s[prev] && ques & 1 || s[i] == s[prev] && !(ques & 1))) {
				ans += ((i - start) * (i - start + 1)) / 2 - ((i-prev - 1)*(i-prev))/2;
				start = prev + 1;
			}
			ques = 0; prev = i;
		}
		ans += ((n - start) * (n + 1 - start)) / 2;
		cout << ans << '\n';
	}
	return 0;
}


