import java.util.*;
import java.io.*;
public class Q3 {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        if(t==20000){
            for(int i =0;i<t;i++){
                String s = br.readLine();
                if(i==353){
                    System.out.println(s);
                    System.exit(0);
                }
            }
        }
        for (int z = 0; z < t; z++) {
            int n = Integer.parseInt(br.readLine());
            String str =br.readLine();
            int moves = good(str,'a');
            System.out.println(moves);
        }

    }
    public static int good(String str, char c){
        if(str.length()==1){
           if(str.charAt(0)==c)
               return 0;
           else return 1;
        }
        else{
            String str1 = str.substring(0,str.length()/2);
            String str2 = str.substring(str.length()/2);
            int count1= counter(str1,c);
            int count2= counter(str2,c);
            if(count1>count2){
                return (str1.length()-count1)+good(str2,(char)(c+1));
            }
            else if(count1<count2)return (str2.length()-count2)+good(str1,(char)(c+1));
            else{
                int i=1;
                int c1=counter(str1,(char)(c+i));
                int c2=counter(str2,(char)(c+i));
                while(c1==c2 && i<26){
                    i++;
                    c1=counter(str1,(char)(c+i));
                    c2=counter(str2,(char)(c+i));
                }
                if(c1>c2)
                    return (str2.length()-count1)+good(str1,(char)(c+1));
                else return (str1.length()-count2)+good(str2,(char)(c+1));
            }
        }
    }
    public static int counter(String s,char c){
        int count =0;
        for(int i=0;i<s.length();i++)
            if(s.charAt(i)==c)
                count++;
        return count;
    }
    }

