


1) Add a lowercase English alphabet at the end of the string.
2) Create a copy of the string and concatenate both of the strings.
First-line contains ‘T’, denoting the number of Test cases.
For each Test case:
The first line contains an integer, ‘N’, denoting the length of the input string S.
The following line contains the string ‘S’ of length ‘N’.
For each test case, you have to print an integer denoting the minimum number of operations required to form the given string ‘S’.
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= ‘T’ <= 10
1 <= ‘N’ <= 10^5
Note- Sum of ‘N’ over all test cases does not exceed 10^5.
Time Limit: 1 sec
We will store the minimum operations required to construct the first ‘i’ characters.
Algorithm:
Approach: In the second operation, we are just adding the length |s| prefix of the string ‘S’ to the current string ‘s’. So we can use the Z-Algorithm to store for each index the length of the longest substring starting from S[i], which is also a prefix of the string ‘S’. If Z[i] >= ‘i’, we can use the second operation.
Algorithm: