human
Can you solve the below in PYTHON3?
Grandma Capa has decided to knit a scarf and asked Grandpa Sher to make a pattern for it, a pattern is a string consisting of lowercase English letters. Grandpa Sher wrote a string s of length n.

Grandma Capa wants to knit a beautiful scarf, and in her opinion, a beautiful scarf can only be knit from a string that is a palindrome. She wants to change the pattern written by Grandpa Sher, but to avoid offending him, she will choose one lowercase English letter and erase some (at her choice, possibly none or all) occurrences of that letter in string s.

She also wants to minimize the number of erased symbols from the pattern. Please help her and find the minimum number of symbols she can erase to make string s a palindrome, or tell her that it's impossible. Notice that she can only erase symbols equal to the one letter she chose.

A string is a palindrome if it is the same from the left to the right and from the right to the left. For example, the strings 'kek', 'abacaba', 'r' and 'papicipap' are palindromes, while the strings 'abb' and 'iq' are not.

Input

The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The next 2 ⋅ t lines contain the description of test cases. The description of each test case consists of two lines.

The first line of each test case contains a single integer n (1 ≤ n ≤ 10^5) — the length of the string.

The second line of each test case contains the string s consisting of n lowercase English letters.

It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.

Output

For each test case print the minimum number of erased symbols required to make the string a palindrome, if it is possible, and -1, if it is impossible.

Example

Input

5
8
abcaacab
6
xyzxyz
4
abba
8
rprarlap
10
khyyhhyhky

Output

2
-1
0
3
2

Note

In the first test case, you can choose a letter 'a' and erase its first and last occurrences, you will get a string 'bcaacb', which is a palindrome. You can also choose a letter 'b' and erase all its occurrences, you...

=====
What is a Python code to find the minimum number of symbols she can erase to make string s a palindrome, or tell her that it's impossible?
assistant
#Here is Python code to find the minimum number of symbols she can erase to make string s a palindrome, or tell her that it's impossible.

def answer():
    N = int(input())
    s = list(input())
    str_list = set(s)
    
    if all(s[i] == s[N-1-i] for i in range(N//2 + 1)):
        print(0)
        return
    
    def num_count(x):
        
        ts = []
        d = dict()
        cnt = 0
        for i in range(N):
            if s[i] != x:
                ts.append(s[i])
                d[cnt] = i
                cnt += 1
                
        n = len(ts)
        if any(ts[i] != ts[n-1-i] for i in range(n//2 + 1)):
            return -1
            
        ans = N - n
        ans -= 2*min(d[0],N-d[n-1]-1)
        
        if n%2 == 0:
            m = n//2
            if m == 1:
                ans -= d[1]-d[0]-1
                return ans
                
            ans -= d[m] - d[m-1] - 1
            
            for j in range(m-1):
                
                ans -= 2*min(d[m-1-j] - d[m-2-j] - 1 , d[m+1+j] - d[m+j] - 1)
        else:
            m = n//2
            if m == 0:
                return ans
                
            for j in range(m):
                
                ans -= 2*min(d[m-j] - d[m-1-j] - 1 , d[m+1+j] - d[m+j] - 1)
        return ans
    tans = N+1
    for x in str_list:
        tmp = num_count(x)
        if tmp != -1:
            tans = min(tans,tmp)
        else:
            continue
    
    if tans == N+1:
        print(-1)
    else:
        print(tans)
    return
            
            
        
        
    
    
t = int(input())
for _ in range(t):
    answer()