/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300iq as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class D
   {
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int T = Integer.parseInt(st.nextToken());
         StringBuilder sb = new StringBuilder();
         while(T-->0)
         {
            int N = Integer.parseInt(infile.readLine());
            arr = infile.readLine().toCharArray();
            sb.append(recur(0, N-1, 'a')+"\n");
         }
         System.out.print(sb);
      }
      static char[] arr;
      public static int recur(int left, int right, char tag)
      {
         if(left == right)
         {
            if(tag == arr[left])
               return 0;
            return 1;
         }
         int mid = (left+right)/2;
         //first half
         int cost = 0;
         for(int i=left; i <= mid; i++)
            if(tag != arr[i])
               cost++;
         int res = cost+recur(mid+1, right, (char)(tag+1));
         cost = 0;
         for(int i=mid+1; i <= right; i++)
            if(tag != arr[i])
               cost++;
         res = Math.min(res, cost+recur(left, mid, (char)(tag+1)));
         return res;
      }
   }