import java.util.*;
import java.io.*;
public class q4{
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int test  = Integer.parseInt(br.readLine());
        while(test-->0){
            int n = Integer.parseInt(br.readLine());
            String str  = br.readLine();
            char ch[] = str.toCharArray();

            if(n==1 ){
                if(str.equals("a")){
                    System.out.println("0");
                }
                else{
                    System.out.println("1");
                }
                continue;
            }
            if(n==2){
                if(str.equals("ab")||str.equals("ba")){
                    System.out.println("0");
                }
                else if(str.charAt(0)=='a'||str.charAt(1)=='a'||str.charAt(0)=='b'||str.charAt(1)=='b'){
                    System.out.println("1");
                }
                else{
                    System.out.println("0");
                }
                continue;
            }


            int min = solution(ch,0,n,'a',n);
            System.out.println(min);
            
            
        }
    }
    public static int solution(char ch[],int start,int end,char c,int n){
        if(n==1)
            return (ch[start]==c?0:1);
        
        int half =start+ (end-start)/2;
        
        int count1 = 0;
        int count2 = 0;
        for(int i=start;i<half;i++){
            if(ch[i]==c){
                count1++;
            }
        }

        for(int i=half;i<end;i++){
            if(ch[i]==c){
                count2++;
            }
        }

        int first = n/2 - count1;
        int second = n/2 - count2;
        char cc = (char)(c+1);

        return Math.min(first + solution(ch,half,end,cc,n/2),second+solution(ch,start,half,cc,n/2));

    }
}