String

시간 제한1초메모리 제한1024 MB

요약
문자열 A가 주어질 때, 각 단계에서 현재 문자열을 k번 반복하고 사본 사이에 임의의 문자를 넣어 만든 무한 문자열의 접두사가 A가 되는 최소 k를 구한다.
난이도

어려움10점 중 8점

유형
문자열, 문자열 매칭, 이분 탐색, 수학
정답자
아직 제출이 없습니다

문제

The Research Institute of the Given Strings (RIGS) is investigating a new method of infinite string construction.

Initially there is an empty string S_0(k)=εS\_{0}^{(k)} = \varepsilon. Each next version of the string is created in the following way. The current version of the string is repeated kk times, and an arbitrary symbol is inserted between every two consecutive occurences. The same number kk is used for the construction of all versions, however, the inserted symbols may differ. This construction ultimately results in the infinite string S_∞(k)S\_{\infty}^{(k)}.

To illustrate, let's consider the series of strings (k=3k = 3): \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 AA of length nn, which is the prefix of S_∞(k)S\_{\infty}^{(k)}, find the minimal kk, for which this is possible.

In other words, your task is to find the minimal kk, for which it is possible to construct a string S_∞(k)S\_{\infty}^{(k)} in a way described above, so that it will have AA as a prefix.

입력

Each input file contains several tests. The first line of the file contains a single integer TT --- the number of tests. Then TT 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 10510^5. The sum of lengths of all the tests in the file does not exceed 10610^6.

출력

The output file must contain exactly TT lines. Each line must contain the minimal value of kk for the corresponding test.

예제1

  1. 예제 1

    입력
    2
    abacabab
    rtxrtrrtartxrtrrtrrtxrt
    
    예상 출력
    2
    3