import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
 
public class D{
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
        public FastReader(){br = new BufferedReader(new InputStreamReader(System.in));} 
        String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());}catch (IOException  e){e.printStackTrace();}}return st.nextToken();} 
        int nextInt(){return Integer.parseInt(next());} 
        long nextLong(){return Long.parseLong(next());} 
        double nextDouble(){return Double.parseDouble(next());} 
        int[] readArray(int n){int[] a=new int[n];for (int i=0; i<n; i++) a[i]=nextInt();return a;}
        long[] readLongArray(int n){long[] a=new long[n];for (int i=0; i<n; i++) a[i]=nextLong();return a;}
        String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;} 
    } 
    static int getgcd(int n1,int n2){
        while(n1 != n2)
        {
            if(n1 > n2)
                n1 -= n2;
            else
                n2 -= n1;
        }
        return n1;
    }
    static boolean isSorted(int[] arr, int n){
        for(int i=1;i<n;i++){
            if(arr[i]<arr[i-1]) return false;
        }
        return true;
    }
    static boolean isPrime(long n){
        if(n==2) return true;
        else if(n%2==0) return false;
        for(int i=3;i<=n/2;i+=2){
            if(n%i==0) return false;
        }
        return true;
    }
    static int count(String arr,char a){
        int ret=0;
        int len=arr.length();
        if(len==1){
            if(arr.charAt(0)==a) return 0;
            else return 1;
        }
        else{
            int count1=0,count2=0;
            for(int i=0;i<((len)/2);i++){
                if(arr.charAt(i)!=a) count1++;
            }
            for(int i=((len)/2);i<len;i++){
                if(arr.charAt(i)!=a) count2++;
            }
            if(count2>count1){
                ret+=(count1);
                ret+=count(arr.substring((len/2), len),(char)(a+1));
            }else if(count1>count2){
                ret+=(count2);
                ret+=count(arr.substring(0, (len/2)),(char)(a+1));
            }else{
                ret+=(count2);
                ret+=Math.min(count(arr.substring(0, (len/2)),(char)(a+1)),count(arr.substring((len/2), len),(char)(a+1)));
            }
        }
        return ret;
    }
    public static void main(String[] args) throws NumberFormatException, IOException {
        FastReader s=new FastReader();
        int t = s.nextInt();
        int n;
        while(t>0){
            n=s.nextInt();
            String str = s.nextLine();
            System.out.println(count(str,'a'));
            t--;
        }
    }
}