import java.io.*;
import java.util.*;

public class Main {
  public static void main(String[] args) throws IOException {
    InputStreamReader in = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(in);

    int t = Integer.parseInt(br.readLine());

    for (int c = 0; c < t; c++) {
      int n = Integer.parseInt(br.readLine());
      String s = br.readLine();

      int[] arr = new int[n];

      for (int i = 0; i < n; i++) {
        arr[i] = s.charAt(i)-'a';
      }

      System.out.println(findMin(arr, 0, 0, n-1));
    }
  }
  public static int findMin(int[] arr, int cur, int l, int r) {
    if (l == r) {
      if (arr[l] == cur) {
        return 0;
      }
      return 1;
    }
    int s = r-l+1;

    int c1 = 0;
    int c2 = 0;
    for (int i = 0; i < s/2; i++) {
      int index1 = l+i;
      int index2 = l+s/2+i;

      if (arr[l+i] != cur) {
        c1++;
      }
      if (arr[l+s/2+i] != cur) {
        c2++;
      }
    }
    c1 += findMin(arr, cur+1, l+s/2, r);
    c2 += findMin(arr, cur+1, l, r-s/2);

    return Math.min(c1, c2);
  }
}