import java.io.*;

public class Qfour {
    public static int check(String word, char regex, int ans){
        if(word.length() == 1){
            if(word.charAt(0) == regex){
                return ans;
            }
            else{
                return ans + 1;
            }
        }
        String h1 = word.substring(0, word.length()/2);
        String h2 = word.substring(word.length()/2, word.length());
        int max1 = h1.length();
        for(int i = 0; i < h1.length(); i++){
            if(h1.charAt(i) == regex){
                int index = i;
                int cnt = 0;
                while(index < h1.length() && h1.charAt(index) == regex){
                    index++;
                    cnt++;
                }
                i = index;
                if(h1.length() - cnt < max1){
                    max1 = h1.length() - cnt;
                }
            }
        }
        int max2 = h2.length();
        for(int i = 0; i < h2.length(); i++){
            if(h2.charAt(i) == regex){
                int index = i;
                int cnt = 0;
                while(index < h2.length() && h2.charAt(index) == regex){
                    index++;
                    cnt++;
                }
                i = index;
                if(h2.length() - cnt < max2){
                    max2 = h2.length() - cnt;
                }
            }
        }
        if(max1 < max2){
            ans = ans + max1;
            ans = check(h2, (char)(regex + 1), ans);
            return ans;
        }
        else if(max2 > max1){
            ans = ans + max2;
            ans = check(h1, (char)(regex + 1), ans);
            return ans;
        }
        else{
            ans = ans + max2;
            int check1 = check(h1, (char)(regex + 1), ans);
            int check2 = check(h2, (char)(regex + 1), ans);
            ans = Math.min(check1, check2);
            return ans;
        }
    }
    public static void main(String[] args) throws Exception{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        for(int i = 0; i < n; i++){
            int l = Integer.parseInt(in.readLine());
            String word = in.readLine();
            check(word, 'a', 0);
            System.out.println(check(word, 'a', 0));
        }
        in.close();
    }
}