Consider the string of infinite length obtained by repeating abcdefghijklmnopqrstuvwxyz
infinitely many times. That is, it looks like abc...xyzabc...xyzabc...
Let string be the prefix of this string of length . For example,
- if ,
abcdef
- if ,
abcdefghijklmnopqrstuvwxyzabc
Vedansh calls a string special if it contains as a substring. Formally, is special if for some , .
Vedansh has string of length (consisting of lowercase Latin letters only). He wants to convert into a special string. To do so he can perform the following operation:
- Pick an such that and delete . The remaining parts of are concatenated.
Since Vedansh is lazy, he wants to do this in the minimum number of operations or determine if cannot be converted to a special string. Help Vedansh in doing so.
Input Format
- The first line of input contains a single integer — the number of test cases. The description of test cases follows.
- Each test case consists of three lines of input
- The first line of each test case contains an integer — the length of the string .
- The second line of each test case contains the string which consists of lowercase Latin letters only.
- The third line of each test case contains an integer — the length of the string whose form is described in the statement.
Output Format
For each test case, if can be converted to a special string, output the minimum number of operations to do so. Otherwise output .
Constraints
- consists of only lowercase Latin letters
- It is guaranteed that the sum of over all test case does not exceed .
Sample Input 1
3
9
ababbdced
4
7
bdcgehx
5
6
acbcbd
3
Sample Output 1
3
-1
1
Explanation
Test case : , so . We can delete the following characters from : , which has as a substring.
Test case : , so . It can be shown that can not be converted into a special string.
Test case : , so . We can delete the following characters from : , which has as a substring.
Solution:
solution link 1
https://shareus.in/?i=yScFNErxQ
if 1st link is not work then click on another link
Solution link 2
Solution link 3
Solution link 4
How to get link tutorial video link