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