logo AlgoBeat OnlineJudge
登录 注册

#209439. [EC Final 2021] Beautiful String

内存限制:1024 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Prof. Pang recently got a dictionary of the elvish language, including many strings representing their words. He thinks a partition of string is beautiful if both of the following conditions are satisfied:

  • , where are nonempty substrings. means the concatenation of string and here.
  • .

For example, you can partition the string 114514 into parts : 114514 = 1 + 1 + 4 + 5 + 1 + 4. The first, second, fifth parts are the same, and the third and sixth parts are the same. Thus, the partition of 114514 into 1, 1, 4, 5, 1, and 4 is beautiful.

Accordingly, the beauty of a string is defined as the number of beautiful partitions of .

Given a string , please help Prof. Pang to figure out the sum of beauties of all substrings of .

输入格式

The first line contains a single integer indicating the number of test cases.

For each test case, there is one single line containing the string , consisting of digits from 0' to9'.

It is guaranteed that the length of each in each test case will not exceed and the total length will not exceed .

输出格式

For each test case, output a single line containing an integer, indicating the sum of beauties of all substrings of .

样例

样例输入 1

2
114514
0000000

样例输出 1

1
3