Decomposition

문자열 S의 모든 분할에 대해 각 조각의 가중치(최소 반복 주기)의 곱을 모두 더한 값을 1e9+7로 나눈 나머지를 여러 테스트 케이스에 대해 구한다.

어려움8문자열 매칭동적 계획법정수론조합론아직 제출이 없습니다시간 제한3초메모리 제한512 MB

문제

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

We define the weight of a substring TT as the length of the shortest string xx such that T=xxxT = x x \ldots x. For example, the weight of aaa is 11, and the weight of ab is 22. We define the weight of a partition as the product of the weights of all substrings in this partition.

Output the sum of weights of all partitions. The answer can be large, so output the answer modulo 109+710^9 + 7.

입력

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

Each test case is given on a separate one line containing a string SS (1S21051 \leq |S| \leq 2 \cdot 10^5) consisting of lowercase English letters.

It is guaranteed that S106\sum |S| \leq 10^6.

출력

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