#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
char s[N] = ".";
int main()
{
    int T;
    scanf("%d", &T);
    while (T--)
    {
        scanf("%s", s + 1);
        long long n = strlen(s);
        long long ans = 0;
        for (long long i = 1; i < n; i++)
        {
            ans += i * (n - i) * ((s[i] == s[i - 1]) + 1);
            if (s[i] == '0') ans += n - i;
            if (s[i] == s[i - 1]) ans -= n - i;
        }
        printf("%lld\n", ans);
    }
    return 0;
}
