for _ in range(int(input())):
s = input()
n = len(s)
ans = 0
i = 0
count = 0
while i < n and s[i] == '?':
i += 1
count += 1
while i < n:
if i+1 < n and s[i+1] == '?':
j = i+1
qs = 0
while j < n and s[j] == '?':
qs += 1
j += 1
if j < n:
if (qs & 1 and s[i] == s[j]) or (qs & 1 == 0 and s[i] != s[j]):
count += qs + 1
else:
count += 1
ans += (count*(count + 1))//2 + qs*count
count = qs
else: count += qs + 1
i = j
elif i+1 < n and s[i+1] != s[i]:
count += 1
i += 1
else:
count += 1
ans += (count*(count + 1))//2
count = 0
i += 1
ans += (count*(count + 1))//2
print(ans)
#include <bits/stdc++.h>
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2")
using namespace std;
typedef pair<int, int> PII;
typedef long long ll;
using vi = vector<int>;
using vl = vector<long long>;
const ll MOD = 998244353 ;
const int dx[4]{1, 0, -1, 0}, dy[4]{0, 1, 0, -1}; // for every grid problem!!
#define MP make_pair
#define vt vector
#define pb push_back
#define rp(i, e) for (int (i) = 0; (i) < (int) (e); (i)+=1)
#define rp2(i, b, e) for (int (i) = b; (i) < (int) (e); (i)+=1)
#define in(x, e) (x.find(e) != x.end())
#define inpr(a, n) for (int ar = 0; ar < n; ar++) {cin >> a[ar];}
#define pa(a, pref, n) pref[0] = 0; rp(i, n) pref[i+1] = pref[i] + a[i]
#define car(a) cout << "[ "; for(auto i: a) {cout << i << ' ';} cout << "] ";
#define all(a) a.begin(), a.end()
#define fs first
#define sc second
void solve(){
string s; cin >> s;
int n = s.size();
int last = 2;
int l = 0;
ll re = 0;
int lq = 0;
rp(i, n){
if(s[i] == '?'){
if(last != 2) last ^= 1;
lq++;
}
else{
int cu = s[i] - '0';
if(last == cu) l = i-lq;
last = cu;
lq = 0;
}
re += i - l + 1;
}
cout << re << endl;
}
//COUT << SETPRECISION(30) PLEASE
//USE DP[2] PLEASE
//USE DP[2] PLEASE
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << setprecision(30);
int t; cin >> t; while(t--)
solve();
return 0;
}
174. Dungeon Game | 127. Word Ladder |
123. Best Time to Buy and Sell Stock III | 85. Maximal Rectangle |
84. Largest Rectangle in Histogram | 60. Permutation Sequence |
42. Trapping Rain Water | 32. Longest Valid Parentheses |
Cutting a material | Bubble Sort |
Number of triangles | AND path in a binary tree |
Factorial equations | Removal of vertices |
Happy segments | Cyclic shifts |
Zoos | Build a graph |
Almost correct bracket sequence | Count of integers |
Differences of the permutations | Doctor's Secret |
Back to School | I am Easy |
Teddy and Tweety | Partitioning binary strings |
Special sets | Smallest chosen word |
Going to office | Color the boxes |