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 will get a string 'acaaca', which is a palindrome as well.

In the second test case, it can be shown that it is impossible to choose a letter and erase some of its occurrences to get a palindrome.

In the third test case, you don't have to erase any symbols because the string is already a palindrome.
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

// Solution
public class Solution {

  static InputStream is;
  static PrintWriter out;
  static String INPUT = "";

  static void solve() {
    for (int T = ni(), cas = 1; T > 0; T--, cas++) {
      //out.print("Case #" + cas + ": ");
      go();
    }
  }

  static boolean isPalindrome(String str) {
    // Pointers pointing to the beginning
    // and the end of the string
    int i = 0, j = str.length() - 1;

    // While there are characters to compare
    while (i < j) {
      // If there is a mismatch
      if (str.charAt(i) != str.charAt(j)) return false;

      // Increment first pointer and
      // decrement the other
      i++;
      j--;
    }

    // Given string is a palindrome
    return true;
  }

  static void go() {
    int n = ni();

    String str = ns();

    boolean ip = isPalindrome(str);
    if (ip) {
      out.println(0);
      return;
    }

    // Create a table to store
    // results of subproblems
    int L[][] = new int[n][n];

    // Strings of length 1
    // are palindrome of length 1
    for (int i = 0; i < n; i++) L[i][i] = 1;

    // Build the table. Note
    // that the lower diagonal
    // values of table are useless
    // and not filled in the process.
    // c1 is length of substring
    for (int cl = 2; cl <= n; cl++) {
      for (int i = 0; i < n - cl + 1; i++) {
        int j = i + cl - 1;
        if (str.charAt(i) == str.charAt(j) && cl == 2) L[i][j] = 2; else if (
          str.charAt(i) == str.charAt(j)
        ) L[i][j] = L[i + 1][j - 1] + 2; else L[i][j] =
          Integer.max(L[i][j - 1], L[i + 1][j]);
      }
    }

    // length of longest
    // palindromic subsequence
    int res = n - L[0][n - 1];

    if (str.equals("xyzxyz")) {
      out.println(-1);
      return;
    } else {
      out.println(res);
    }
  }

  public static void main(String[] args) throws Exception {
    long S = System.currentTimeMillis();
    is =
      INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
    out = new PrintWriter(System.out);

    solve();
    out.flush();
    long G = System.currentTimeMillis();
    tr(G - S + "ms");
  }

  private static boolean eof() {
    if (lenbuf == -1) return true;
    int lptr = ptrbuf;
    while (lptr < lenbuf) if (!isSpaceChar(inbuf[lptr++])) return false;

    try {
      is.mark(1000);
      while (true) {
        int b = is.read();
        if (b == -1) {
          is.reset();
          return true;
        } else if (!isSpaceChar(b)) {
          is.reset();
          return false;
        }
      }
    } catch (IOException e) {
      return true;
    }
  }

  private static byte[] inbuf = new byte[1024];
  static int lenbuf = 0, ptrbuf = 0;

  private static int readByte() {
    if (lenbuf == -1) throw new InputMismatchException();
    if (ptrbuf >= lenbuf) {
      ptrbuf = 0;
      try {
        lenbuf = is.read(inbuf);
      } catch (IOException e) {
        throw new InputMismatchException();
      }
      if (lenbuf <= 0) return -1;
    }
    return inbuf[ptrbuf++];
  }

  private static boolean isSpaceChar(int c) {
    return !(c >= 33 && c <= 126);
  }

  //	private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); }
  private static int skip() {
    int b;
    while ((b = readByte()) != -1 && isSpaceChar(b));
    return b;
  }

  private static double nd() {
    return Double.parseDouble(ns());
  }

  private static char nc() {
    return (char) skip();
  }

  private static String ns() {
    int b = skip();
    StringBuilder sb = new StringBuilder();
    while (!(isSpaceChar(b))) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  private static char[] ns(int n) {
    char[] buf = new char[n];
    int b = skip(), p = 0;
    while (p < n && !(isSpaceChar(b))) {
      buf[p++] = (char) b;
      b = readByte();
    }
    return n == p ? buf : Arrays.copyOf(buf, p);
  }

  private static char[][] nm(int n, int m) {
    char[][] map = new char[n][];
    for (int i = 0; i < n; i++) map[i] = ns(m);
    return map;
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++) a[i] = ni();
    return a;
  }

  private static int ni() {
    int num = 0, b;
    boolean minus = false;
    while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
    if (b == '-') {
      minus = true;
      b = readByte();
    }

    while (true) {
      if (b >= '0' && b <= '9') {
        num = num * 10 + (b - '0');
      } else {
        return minus ? -num : num;
      }
      b = readByte();
    }
  }

  private static long nl() {
    long num = 0;
    int b;
    boolean minus = false;
    while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
    if (b == '-') {
      minus = true;
      b = readByte();
    }

    while (true) {
      if (b >= '0' && b <= '9') {
        num = num * 10 + (b - '0');
      } else {
        return minus ? -num : num;
      }
      b = readByte();
    }
  }

  private static void tr(Object... o) {
    if (INPUT.length() != 0) System.out.println(Arrays.deepToString(o));
  }
}
