#P17423. [ICPC 2018 Xuzhou R] Rikka with Nice Counting Striking Back

[ICPC 2018 Xuzhou R] Rikka with Nice Counting Striking Back

Problem Description

As we know, Yuta is poor at counting numbers. Rikka is worrying about this situation, so she gives Yuta some counting tasks to practice. Here is one of them:

In computer programming, a string is traditionally a sequence of characters and a substring of a string is a contiguous sequence of characters within the string. For instance, snowball\text{snowball} is a string, now\text{now} is a substring of snowball\text{snowball} and bow\text{bow} is not a substring of snowball\text{snowball}. Moreover, the concatenation of two strings UU and VV is named as UVU V, that is, if UU is snow\text{snow} and VV is ball\text{ball}, then UVU V is snowball\text{snowball}.

Rikka has a string SS of length nn and she wants Yuta to count how many distinct nice\textit{nice} strings in total. Here, she calls a non-empty string TT nice\textit{nice} if

  • TT is a substring of SS; and
  • TPT P is not a substring of SS for any non-empty string PP meeting the condition that TPT P and PTP T are the same string.

It is too difficult for Yuta. Can you help him?

Input Format

The input contains several test cases, and the first line contains a single integer TT (1≤T≤10001 \le T \le 1000), the number of test cases.

For each test case, the only line contains a single string SS of length nn (1≤n≤2×1051 \le n \le 2 \times 10^5) with only lowercase letters.

The input guarantees that the sum of nn in all test cases is at most 5×1065 \times 10^6.

Output Format

For each test case, output a single line with a single integer, the answer.

6
rikkasuggeststoallthecontestants
thisisaproblemdesignedforgrandmasters
ifyoudidnotachievethat
youdbetterskiptheproblem
wishyouahighrank
enjoytheexperience
500
679
244
290
132
163