Given a string S and q queries of the form l,r, find the length of the shortest string that, when repeated some number of times, exactly forms the substring S[l...r].
### Input
- The first line contains the string S.
- The second line contains an integer q.
- The next q lines each contain two integers l and r.
### Output
- Print q integers, each being the answer to the corresponding query.
### Constraints
- 1≤|S|≤5×105.
- 1≤q≤106.
### Example
Input:
8aaabcabc3133848
Output:
135
Explanation:
- Query 1: Repeating the string a three times results in the string aaa.
- Query 2: Repeating the string abc two times results in the string abcabc.
- Query 3: Repeating the string abcab one time results in the string abcab.