#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define ff first
#define ss second
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define nn "\n"
#define sci(x) scanf("%d", &x)
#define LL_INF (1LL << 62)
#define INF (1 << 30)
#define SetBit(x, k) (x |= (1LL << k))
#define ClearBit(x, k) (x &= ~(1LL << k))
#define CheckBit(x, k) (x & (1LL << k))
#define mod 1000000007
#define N 1000006

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while(t--){
        string s;
        cin >> s;

        s = "*"+s;
        s += "*";
        int n = s.size()-2;


        int lft[s.size()+2][2];

        for(int i = 0; i <= n; i++){
            lft[i][0] = 1;
            lft[i][1] = 1;
        }

        lft[0][0] = 0;
        lft[0][1] = 0;
        lft[n+1][0] = 0;
        lft[n+1][1] = 0;
        
        for(int i = 1; i <= n; i++){
            if(s[i]=='0'){
                if(s[i-1]=='1') lft[i][0] = 1+lft[i-1][0];
                else if(s[i-1]=='0') lft[i][0] = 1;
                else lft[i][0] = lft[i-1][1]+1;
            }
            else if(s[i]=='1') {
                if(s[i-1]=='0') lft[i][0] = 1+lft[i-1][0];
                else if(s[i-1]=='1') lft[i][0] = 1;
                else lft[i][0] = lft[i-1][0]+1;
            }
            else {
                lft[i][0] = 1;
                lft[i][1] = 1;

                if(s[i-1]=='1') lft[i][0] = lft[i-1][0]+1;
                else if(s[i-1]=='?') lft[i][0] = lft[i-1][1]+1;

                if(s[i-1]=='0') lft[i][1] = lft[i-1][0]+1;
                else if(s[i-1]=='?') lft[i][1] = lft[i-1][0]+1;
            }
        }

        ll res = 0;
        for(int i = 1; i <= n; i++){
            // cout << lft[i][0] << " : " << lft[i][1] << nn;
            // res += (ll) rgt[i][0];
            if(s[i]=='?') res += max(lft[i][0], lft[i][1]);
            else res += lft[i][0];
        }

        cout << res << nn;
    }

    return 0;
}