The Shortest Period

No attempts yetTime limit5sMemory limit128 MB

Problem

We call a string tt a period of a string ss if ts|t| \le |s| and ss is a prefix of tkt^k (the string tt written kk times in a row) for some positive integer kk. For example, the periods of the word entente are ent, entent, and entente, of lengths 33, 66, and 77. The shortest period of ss is its period of smallest length.

A teacher wrote a very long word on the whiteboard. Bytie was not paying much attention to the lesson, so instead he copied into his notebook every word that can be obtained from the whiteboard word by removing exactly one letter. If the whiteboard word has length nn, the notebook then holds nn words, each of length n1n-1. Bytie now wants to pick the notebook word whose shortest period is as short as possible. Given the whiteboard word, report the length of that shortest possible shortest period.

Input

The first line contains one integer dd (1d101 \le d \le 10), the number of test cases. Each of the next dd lines describes one test case: an integer nin_i (2ni2000002 \le n_i \le 200000), the length of the whiteboard word, followed by a single space and the nin_i-letter word itself, made of lowercase English letters.

Output

Print dd lines. The ii-th line contains one integer: the smallest possible shortest period, taken over all words obtainable from the ii-th whiteboard word by deleting exactly one letter.

Note

Consider the word ababcaba. The words Bytie writes in his notebook, together with the length of each one's shortest period, are:

WordShortest period
babcaba5
aabcaba6
abbcaba6
abacaba4
abababa2
ababcba6
ababcaa6
ababcab5

Removing the letter c in the fifth position gives abababa, whose shortest period has length 22, and no other single removal yields a shorter shortest period. Hence the answer is 22.