#include <bits/stdc++.h>
#include <sstream>
#include <string>

using namespace std;

# define M_PI  3.14159265358979323846
typedef long long ll;
#define int long long
#define pb push_back
#define fo(x) for(ll i=0;i<x;i++)
#define INF 2e18
#define all(v) v.begin(),v.end()
#define dbg(x) cout<<#x<<" = "<<x<<"\n";

int SetBit (int n, int x) { return n | (1 << x); }
int ClearBit (int n, int x) { return n & ~(1 << x); }
int ToggleBit (int n, int x) { return n ^ (1 << x); }
bool CheckBit (int n, int x) { return (bool)(n & (1 << x)); }
bool sort_by_sec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }

const int M = 1e9 + 7;
long long mod(long long x) {
	return ((x % M + M) % M);
}
long long add(long long a, long long b) {
	return mod(mod(a) + mod(b));
}
long long mul(long long a, long long b) {
	return mod(mod(a) * mod(b));
}
ll gcd(ll a, ll b)
{
	if (a == 0)
		return b;
	return gcd(b % a, a);
}

int findGCD(int arr[], int n)
{
	int result = arr[0];
	for (int i = 1; i < n; i++)
	{
		result = gcd(arr[i], result);

		if (result == 1)
		{
			return 1;
		}
	}
	return result;
}

ll modPow(ll a, ll b) {
	if (b == 0)
		return 1LL;
	if (b == 1)
		return a % M;
	ll res = 1;
	while (b) {
		if (b % 2 == 1)
			res = mul(res, a);
		a = mul(a, a);
		b = b / 2;
	}
	return res;
}
long long binpow(long long a, long long b) {
	if (b == 0)
		return 1;
	long long res = binpow(a, b / 2);
	if (b % 2)
		return res * res * a;
	else
		return res * res;
}


void seive_primes() {

	vector<int>prime;
	int vis[1000010], num;
	memset(vis, 1, sizeof(vis));
	num = 0;
	for (int i = 2; i < 1000010; i++)
	{
		if (vis[i])
		{
			prime.pb(i);

			for (int j = 2; j * i < 1000010; j++)
				vis[j * i] = 0;
		}
	}
}
bool isPrime(int x) {
	if (x < 2) return false;
	for (int y = 2; y * y <= x; y++)
		if (x % y == 0)
			return false;
	return true;
}

void solve () {


	string s;

	cin >> s;
	int n = s.length();
	char c = s[0];
	int ans = n * (n + 1) / 2;

	int idx = 0;
	int k = 1;
	// cout << ans << "\n";
	int zz = 0;
	for (int i = 1; i < s.length(); i++)
	{
		// cout << ans << "\n";
		if (s[i] != '?')
		{

			if (c == s[i] && c != '?')
			{
				if ((i - idx - 1) % 2 == 0)
				{
					ans -= (n - i ) * (idx + 1 - zz);
					zz = idx + 1;
					k = 1;
				}
			}
			else if (c != '?')
			{
				if ((i - idx - 1) % 2)
				{
					ans -= (n - i) * (idx + 1 - zz);
					zz = idx + 1;
					k = 1;
				}
			}
			c = s[i];
			idx = i;
		}
		k++;

	}

	cout << ans << "\n";
}





int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout << fixed;
	cout << setprecision(8);
	int tc = 1;
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> tc;
	for (int t = 1; t <= tc; t++) {
		// cout << "Case #" << t << ": ";
		solve();
	}
	cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
	return 0;
}