import java.lang.*;
import java.util.*;

public class ct1 {

    static class Freq{
        int freq=0;
        char c;
        Freq(char c) {
            this.c = c;
        }
    }

    static class Sort implements Comparator<Freq>{
        public int compare(Freq f1, Freq f2){
            return f2.freq - f1.freq;
        }
    }

    void fun2(){

    }

    class x{
        void fun(){
            fun2();
        }
    }

    static long fib(int n){
        if(n==1)
            return 0;
        else if(n==2)
            return 1;
        else return fib(n-1)+fib(n-2);
    }

    static int res = 0;

    static void solve(String x, int s, int e, char c){
        if(s>=e)
            return;
        if(e-s == 1){
            if(x.charAt(s)!=c){
                res++;
            }
            return;
        }
        int left = 0, right = 0, laage=0, raage=0;
        for(int i=s; i<(e+s)/2; i++){
            if(x.charAt(i) == c)
                left++;
            if(x.charAt(i) == (char)(c+1))
                laage++;
        }
        for(int i=(e+s)/2; i<e; i++){
            if(x.charAt(i) == c)
                right++;
            if(x.charAt(i) == (char)(c+1))
                raage++;
        }
        if(left>right) {
            res += ((e-s) / 2 - left);
            solve(x, (e+s)/2, e, (char)(c+1));
        }
        else if(right>left) {
            res += ((e-s) / 2 - right);
            solve(x, s, (e+s)/2, (char)(c+1));
        }
        else {
//            res += ((e-s) / 2 - right);
//            solve(x, s, (e+s)/2, (char)(c+1));
            if(laage<raage) {
                res += ((e-s) / 2 - left);
                solve(x, (e+s)/2, e, (char)(c+1));
            }
            else{
                res += ((e-s) / 2 - right);
                solve(x, s, (e+s)/2, (char)(c+1));
            }
        }
    }

    public static void main(String[] args){
//        System.out.println(fib(45));
        Scanner inp = new Scanner(System.in);
        int x = inp.nextInt();
        while(x-->0){
            int n = inp.nextInt();
            String a = inp.next();
            char c = (char)97;
            res=0;
            solve(a, 0, n, c);
            System.out.println(res);
        }
    }

    static long dp[][] = new long[100002][6];

    static long ans(int[]a, int i, int k, int z, boolean isl){
        if(i<0 || k==0 || i>=a.length){
            return 0;
        }
        if(dp[i][z]!=-1)
            return dp[i][z];
        long val = 0;
        if(i<a.length)
            val = Math.max(val,a[i]+ans( a, i+1, k-1, z, false));
        if(!isl && i>=0 && z>0)
            val = Math.max(val, a[i]+ans(a, i-1, k-1, z-1, true));
        return dp[i][z] = val;

    }

    static void print(ArrayList<Integer> a){
        for(int i=0; i<a.size(); i++){
            System.out.print(a.get(i) + " ");
        }
        System.out.println();
    }




}