#P1984D. "a" String Problem

    ID: 10668 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>brute forcehashingimplementationmathstring suffix structuresstrings*2000

"a" String Problem

Description

You are given a string ss consisting of lowercase Latin characters. Count the number of nonempty strings tt \neq "a\texttt{a}" such that it is possible to partition^{\dagger} ss into some substrings satisfying the following conditions:

  • each substring either equals tt or "a\texttt{a}", and
  • at least one substring equals tt.

^{\dagger} A partition of a string ss is an ordered sequence of some kk strings t1,t2,,tkt_1, t_2, \ldots, t_k (called substrings) such that t1+t2++tk=st_1 + t_2 + \ldots + t_k = s, where ++ represents the concatenation operation.

The first line contains a single integer tt (1t1041 \leq t \leq 10^4) — the number of test cases.

The only line of each test case contains a string ss consisting of lowercase Latin characters (2s21052 \leq |s| \leq 2 \cdot 10^5).

The sum of s|s| over all test cases does not exceed 31053 \cdot 10^5.

For each test case, output a single integer — the number of nonempty strings tt \neq "a\texttt{a}" that satisfy all constraints.

Input

The first line contains a single integer tt (1t1041 \leq t \leq 10^4) — the number of test cases.

The only line of each test case contains a string ss consisting of lowercase Latin characters (2s21052 \leq |s| \leq 2 \cdot 10^5).

The sum of s|s| over all test cases does not exceed 31053 \cdot 10^5.

Output

For each test case, output a single integer — the number of nonempty strings tt \neq "a\texttt{a}" that satisfy all constraints.

Sample Input 1

8
aaaaa
baba
cabacb
aaabaaa
bitset
ab
abbaaaabbb
yearnineteeneightyfour

Sample Output 1

4
4
1
16
1
2
3
1

Note

In the first test case, tt can be "aa\texttt{aa}", "aaa\texttt{aaa}", "aaaa\texttt{aaaa}", or the full string.

In the second test case, tt can be "b\texttt{b}", "bab\texttt{bab}", "ba\texttt{ba}", or the full string.

In the third test case, the only such tt is the full string.