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

inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}

inline bool read(int& a){
    int s=0,w=1;
    char ch=getchar();
    if(ch==EOF){
        return false;
    }
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=s*w;
    return true;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

template<typename...args>inline bool read(int &a,args&...x){
    return (read(a),read(x...));
}

inline void writeln(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
    puts("");
}

const int N=200010;

string s;
int t,n,ans,dp[N][2];

signed main(){
	read(t);
	
	while(t--){
		cin>>s;
		n=s.size();
		dp[0][0]=dp[0][1]=0;
		ans=0;
		
		for(int i=1;i<=n;i++){
			if(s[i-1]=='0'){
				dp[i][0]=dp[i-1][1]+1;
				dp[i][1]=0;
				ans+=dp[i][0];
			}
			else if(s[i-1]=='1'){
				dp[i][1]=dp[i-1][0]+1;
				dp[i][0]=0;
				ans+=dp[i][1];
			}
			else{
				dp[i][0]=dp[i-1][1]+1;
				dp[i][1]=dp[i-1][0]+1;
				ans+=max(dp[i][0],dp[i][1]);
			}
		}
		
		writeln(ans);
	}
	
	return 0;
}