QOJ.ac

QOJ

Time Limit: 6 s Memory Limit: 128 MB Total points: 10

#10392. The Shortest Period [B]

统计

A word $t$ is called a period of the word $s$ if it is not longer than $s$ and there exists a natural number $k$ such that $s$ is a prefix of $t^{k}$. E.g., the periods of the word entente are: ent, entent and entente.

The teacher wrote a very long word on the whiteboard. Bytie was not really interested in what was the class about but he wrote down in his notebook all the words that can be obtained from the word on the whiteboard by removing exactly one letter. Now he would like to choose the word in his list with the shortest shortest period. Write a program that will help him with this problem.

Input Format

The first line of the standard input contains one integer $d$ ($1 ≤ d ≤ 10$), the number of test cases. $d$ lines follow, each of them contains one integer $n_{i}$ ($2 ≤ n_{i} ≤ 200\,000$) that denotes the length of the word on the whiteboard and a $n_{i}$-letter word composed of small English letters.

Output Format

Your program should write $d$ lines to the standard output. The $i$-th line should contain the answer for the $i$-th test case: one integer equal to the length of the shortest period among all the shortest periods of the words written in Bytie's notebook.

Example

Input

1
8 ababcaba

Output

2

Notes

Explanation of the example: Here are the words written by Bytie, together with the length of their shortest periods:

  • babcaba - 5,

  • aabcaba - 6,

  • abbcaba - 6,

  • abacaba - 4,

  • abababa - 2,

  • ababcba - 6,

  • ababcaa - 6,

  • ababcab - 5.

We see that removing the letter c at the fifth position of the word produces a word with the shortest period of length 2 and removing no other letter gives a word with a shorter shortest period.

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.