#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cstring>
#include <cmath>

using namespace std;
#define F first
#define S second
typedef long long ll;
const int M = 200005;
const int mod = 1e9+7;

int last[M][4];

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        ll ans = 0;
        string s;
        cin >> s;
        memset(last,-1,sizeof last);
        int n = s.length();
        for(int i = n - 1; i >= 0; --i)
        {
            int w = 0;
            if(s[i] == '?')
            {
                last[i][1] = max(last[i + 1][0]+1, 1);
                last[i][0] = max(last[i + 1][1]+1, 1);
            }
            else
            {
                bool c = s[i] - '0';
                last[i][c] = max(1, last[i + 1][!c]+1);
            }
        }
        for(int i = 0; i < n; ++i)
        {
            int m = 0;
            for(int j = 0; j < 2; ++j)
            {
                if(last[i][j] >= 0)
                {
                    m = max(last[i][j], m);
                }
            }
            ans += m;
        }
        cout << ans << endl;
    }
    return 0;
}
