#P7958. Yiwen with Sqc
Yiwen with Sqc
Yiwen with Sqc
Problem Description
Recently, Yiwen is learning Assembly Language. Since Yiwen is a genius in computer science, he proposed an extremely valuable technique called Basic Instruction Technology. Using this kind of technique, Yiwen can create numerous different instruction. Some of these instruction can be used to calculate some special eigenvalue of a string, such as . For a string , let be the character of it. Instruction sqc has 4 operands , , and , where is a string, , is a character represented by ASCII value. returns the number of character in substring . Yiwen wants you to calculate following expression for the given string : $$\sum_{c=97}^{122}\sum_{i=1}^{n}\sum_{j=i}^{n} sqc(s,i,j,c)^2$$ Note that the ASCII value of 'a' is and the ASCII value of 'z' is . The answer will probably be very huge, so just calculate the answer modulo .
Input
The input consists of multiple test cases. The first line contains an integer () -- the number of test cases. For each test case, the only line contains a string () consists of lowercase English letters. It is guaranteed that the sum of over all test cases does not excceed .
Output
For each test case, output your answer modulo in a single line.
Sample Input
5
ababa
a
abcdefga
afidhehfhd
ggggggggggg
Sample Output
57
1
122
328
1716
Source
2021“MINIEYE杯”中国大学生算法设计超级联赛(7)