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

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // freopen(".vscode/input.txt","r",stdin);
    // freopen(".vscode/output.txt","w",stdout);
    // #endif

    int t;cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        int n = s.size();
        int ans=0,count=1,one =-1,zero=-1;

        int define;

        for(int i=0;i<n;i++)
        {
            if(s[i] == '1' && one ==-1)
            {
                ans+=count;
                one = i;
                zero = (i+1);
                define = i;
                count++;
            }
            else if(s[i]=='0' && zero == -1)
            {
                ans+=count;
                zero = i;
                one = (i+1);
                define = i;
                count++;
            }
            else if(s[i]=='?')
            {
                ans+=count;
                count++;
            }
            else if(s[i]=='1' && i%2 == one%2)
            {
                ans+=count;
                one = i;
                count++;
                define = i;
            }
            else if(s[i]== '0' && i%2 == zero%2)
            {
                ans+=count;
                zero = i;
                count++;
                define = i;
            }
            else if(s[i]=='1')
            {
                count = i-define;
                define = i;
                ans+=count;
                count++;
                one = i;
                zero = (i+1);
            }
            else if(s[i]=='0')
            {
                count = i-define;
                define = i;
                ans+= count;
                count++;
                zero = i;
                one = (i+1);
            }
        }

        cout<<ans<<endl;

    }
    
    return 0;
}