Under construction

Still being built. Things may change

Decomposition

Time limit3sMemory limit512 MB

Summary
For each string, sum the products of smallest periods over all ways to split it into substrings, modulo 1e9+7.
Level

Hard8 of 10

Topics
String matching, Dynamic programming
Solved
No attempts yet

Problem

You are given a string SS. You want to partition it into several (possibly one) nonempty substrings. There are 2∣S∣−12^{|S|-1} ways of partitions. For example, aba, ab+a, a+ba, a+b+a are all the partitions of the string aba.

The weight of a substring TT is the length of the shortest string xx such that T=xx…xT = x x \ldots x. For example, the weight of aaa is 11, and the weight of ab is 22. The weight of a partition is the product of the weights of all substrings in it.

Output the sum of the weights of all partitions, modulo 109+710^9 + 7.

Input

The first line contains an integer TT (1≤T≤1051 \leq T \leq 10^5), the number of test cases.

Each test case is on its own line and contains a string SS (1≤∣S∣≤2⋅1051 \leq |S| \leq 2 \cdot 10^5) made of lowercase English letters. The sum of ∣S∣|S| over all test cases is at most 10610^6.

Output

For each test case, output the answer modulo 109+710^9 + 7 on its own line.

Examples1

  1. Example 1

    Input
    1
    abaababaabbbaabbbb
    
    Expected output
    5320053