String
시간 제한1초메모리 제한1024 MB
문자열 A가 주어질 때, 각 단계에서 현재 문자열을 k번 반복하고 사본 사이에 임의의 문자를 넣어 만든 무한 문자열의 접두사가 A가 되는 최소 k를 구한다.
문제
The Research Institute of the Given Strings (RIGS) is investigating a new method of infinite string construction.
Initially there is an empty string . Each next version of the string is created in the following way. The current version of the string is repeated times, and an arbitrary symbol is inserted between every two consecutive occurences. The same number is used for the construction of all versions, however, the inserted symbols may differ. This construction ultimately results in the infinite string .
To illustrate, let's consider the series of strings (): \begin{align\*} S\_{0}^{(3)} &= \varepsilon (\text{empty})\\\ S\_{1}^{(3)} &= \mathbf{r}\mathbf{t} \hspace{5cm} ( S\_{1}^{(3)} = \boxed{\varepsilon}\mathbf{r}\boxed{\varepsilon}\mathbf{t}\boxed{\varepsilon} ) \\\ S\_{2}^{(3)} &= \boxed{rt} \mathbf{x} \boxed{rt} \mathbf{r} \boxed{rt} \\\ S\_{3}^{(3)} &= \boxed{rtxrtrrt} \mathbf{a} \boxed{rtxrtrrt} \mathbf{r} \boxed{rtxrtrrt} \\\ \phantom{S\_{i}^{(3)}} & \ldots \\\ S\_{\infty}^{(3)} &= rtxrtrrtartxrtrrtrrtxrtrrtzrtxrtrrtartxrt\ldots \end{align\*}
Given a string of length , which is the prefix of , find the minimal , for which this is possible.
In other words, your task is to find the minimal , for which it is possible to construct a string in a way described above, so that it will have as a prefix.
입력
Each input file contains several tests. The first line of the file contains a single integer --- the number of tests. Then lines follow; each line describes a single test. The tests are nonempty and contain only lowercase Latin letters.
The number of tests does not exceed . The sum of lengths of all the tests in the file does not exceed .
출력
The output file must contain exactly lines. Each line must contain the minimal value of for the corresponding test.