String Strange Sum

아직 제출이 없습니다시간 제한4초메모리 제한1024 MB

문제

You are given a string ss consisting of lowercase English letters.

Let us consider a segment \[,r]\[\ell, r] such that 2rs2 \leq \ell \leq r \leq |s|. Let us define f(,r)f(\ell, r) as the length of the longest suffix of substring s\[1,1]s\[1, \ell-1] such that this suffix can be divided into prefixes of substring s\[,r]s\[\ell, r]. If there are no such suffixes then f(,r)=0f(\ell, r) = 0.

Find the sum _=2s_r=sf(,r)\displaystyle \sum\limits\_{\ell=2}^{|s|} \sum\limits\_{r=\ell}^{|s|} f(\ell, r).

입력

The first line contains a single integer tt (1t1051 \leq t \leq 10^5) --- the number of test cases. Description of test cases follows.

The only line for each test case contains the string ss (2s21052 \leq |s| \leq 2 \cdot 10^5) consisting of lowercase English letters.

It is guaranteed that the sum of s|s| for all test cases does not exceed 21052 \cdot 10^5.

출력

For each test case, print a single integer --- the answer to the problem.

힌트

Let us consider the third test case. In this case, f(2,2)=0f(2, 2) = 0, f(2,3)=0f(2, 3) = 0, f(2,4)=0f(2, 4) = 0, f(2,5)=0f(2, 5) = 0, f(3,3)=0f(3, 3) = 0, f(3,4)=2f(3, 4) = 2, f(3,5)=2f(3, 5) = 2, f(4,4)=0f(4, 4) = 0, f(4,5)=2f(4, 5) = 2, f(5,5)=0f(5, 5) = 0. So the answer is 66.