Given a string S made of letters a, b and c, find the number of sub strings that do not contain all the letters a, b and c. That is the number of sub strings that do not contain at least one of the letters a or b or c.

Note that the sub string should contain atleast one letter, that is it should not be empty string.

Input
First line of the input is the number of test cases T.  It is followed by T lines. Each test case is a single line which is the string S.

Output 
For each test case, print a single number, the required answer. 

Constraints 
1 ≤ |S| ≤ 10^6

SAMPLE INPUT
3
ababa
abc
babac

SAMPLE OUTPUT
15
5
12
t=int(raw_input())
for w in range(t):
    s=raw_input()
    l=len(s)
    cnt=l*(l+1)/2
    a=0
    b=0
    c=0
    for i in range(len(s)):
        if s[i]=='a':
            a=i+1
            cnt-=min(b,c)
        if s[i]=='b':
            b=i+1
            cnt-=min(a,c)
        if s[i]=='c':
            c=i+1
            cnt-=min(a,b)
    print cnt