#include <iostream>
#include <vector>

#define ull unsigned long long
using namespace std;

ull c(ull n){
    return n*(n+1)/2;
}
void solve() {
    vector<int> v;
    cin >> noskipws;
    bool fullanon = true;
    while (true) {
        char c;
        cin >> c;
        if (c == '0') {
            v.push_back(0);
            fullanon = false;
        }
        if (c == '1') {
            v.push_back(1);
            fullanon = false;
        }
        if (c == '?') {
            v.push_back(2);
        }
        if (c == '\n' && !v.empty()) {
            break;
        }
    }
    if(fullanon){
        ull count = c(v.size());
        cout << count << endl;
        return;
    }
    ull res = 0;
    ull current_carry = 0;
    ull prev_carry = 0;
    ull start = 0;
    ull type = 2;
    for(ull i = 0;i<v.size();i++){
        ull x = v[i];
        if(x != 2){
            ull t = i%2==x?0:1;
            if(type == 2){
                type = t;
            } else if(type != t){
                ull len = (i-start);
                ull count = c(len+prev_carry)-c(prev_carry);
                res += count;
                start = i;
                type = t;
                prev_carry = current_carry;
            }
            current_carry = 0;
        } else {
            current_carry++;
        }
    }
    ull len = (v.size()-start);
    ull count = c(len+prev_carry)-c(prev_carry);
    res += count;
    cout << res << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int ncases;
    cin >> ncases;
    for (int i = 0; i < ncases; i++) {
        solve();
    }
}
