Periodic Palindrome
题号:NC21529
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Chiaki has a string ... w wr w wr ... with infinite length, where w=w1w2... wm and wr=wm wm-1 ... w1.
Chiaki cuts out a substring s=s1s2... sn (m < n) from the infinite string. And it's guaranteed s contains w or wr as a substring. She would like to know the number of pairs (i,j) where 1 ≤ i ≤ j ≤ n and is a possible value of w or wr.

输入描述:

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains a string s (2 ≤ |s| ≤ 106) consisting only of lowercase English letters.
It is guaranteed that the sum of |s| in all cases does not exceed 106.

输出描述:

For each test case, output an integer denoting the answer.
示例1

输入

复制
1
aaa

输出

复制
5