Coming directly to the question.
Input:
First line has the t testcases.
Each testcase will have a number n , that will be the number of strings , which will be given input in the next line , followed by the line , having n strings ( made up of only a,b,c ..... y,z ) , may be same or different as well.
Output:
for each testcase print the minimum distance between the 2 equal strings. Note: if the n strings , if all are different , that is no two strings are same , then output -1.
Constraints:
1≤t≤ 10
1≤n≤105
Sum of n over all testcase is less than 2*105.
Sum of length ( of strings ) over all test cases is less than 550000.
Length of a prticular string is less than 26. And strings will be all in lowercase.
Clearly , the minimum distance is between the 'me' and 'me' so index 0 and index 2 ,so answer is (2-0) = 2.
( also as it is lesser than 'abc' and 'abc' distance , index 1 and index 4 , answer for 'abc' and 'abc' is 3 .)
answer is 2.
Obviously answer will be -1 as no match is found.