


The string only consists of lowercase English alphabets.
The first line of input contains 'T', the number of test cases.
The first line of each test case contains an integer 'N', denoting the length of string 'S'.
The second line of each test case contains the string 'S'.
The only line of output of each test case should contain an integer denoting the minimum rotations required to get the same string 'S'.
Print the output of each test case in a separate line.
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= N <= 10 ^ 4
Time Limit: 1 sec
The string 'S' only contains lowercase English characters.
Where 'T' denotes the number of test cases and 'N' denotes the length of string 'S'.
The idea that we will be using in this approach is that we start from position 1 and start generating all substrings of length N and check if this substring is equal to the original string S or not. Let’s see how we will achieve this.
For Example: N = 3 and S = abc
The idea that we will be using in this approach is that we will generate a string named C of length 2*N - 1. This string will be made by removing the first character from string S and then concatenating it with string S(with the first character as well) and in this string check when S occurs.
For example, if S = code, then C = odecode.
Now we are almost done and we just have to traverse this string C once and the index where we encounter string S, that index is the number of rotations required to get back to S. For this string matching, we’ll use the famous Knuth-Morris-Pratt algorithm(KMP). Let’s see how will we reach our final answer.
For example: N = 4 and S = abcd