You are given a string $$$s$$$ of length $$$n$$$. Let $$$s[i..j]$$$ denote the substring $$$s_i s_{i+1} \ldots s_j$$$.
For every pair of indices $$$(i, j)$$$ with $$$1 \le i \le j \le n$$$, do the following:
Let $$$f(i, j)$$$ be the number of occurrences of $$$p$$$ as a substring in $$$w$$$. Here, an occurrence of $$$p$$$ in $$$w$$$ is a position $$$x$$$ such that $$$w[x..(x + |p| - 1)] = p$$$. Occurrences at different positions are counted separately, and they may overlap.
Compute $$$\sum_{1 \le i \le j \le n} f(i, j).$$$
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The only line of each test case contains a string $$$s$$$ ($$$1 \le |s| \le 3 \cdot 10^5$$$) consisting of lowercase Latin letters.
It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.
For each test case, output a single integer — the value of $$$\sum_{1 \le i \le j \le n} f(i, j)$$$.
4ababaaaaaabaabz
615200
In the first test case, $$$s = \texttt{abab}$$$, and the answer is $$$6$$$ — of the ten pairs $$$(i, j)$$$, six contribute one occurrence each and the rest contribute none:
| Name |
|---|


