import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class CF1385D {

    static int calculate(String s,int left,int right,char c){
        if(left == right){
            if(s.charAt(left) == c){
                return 0;
            }
            else{
                return 1;
            }
        }
        else{
            int mid = (left + right) / 2;
            int leftCost = 0;
            for(int i = left;i <= mid;i++){
                if(s.charAt(i) != c){
                    leftCost++;
                }
            }
            int rightCost = 0;
            for(int i = mid+1;i <= right;i++){
                if(s.charAt(i) != c){
                    rightCost++;
                }
            }

            int p = calculate(s,mid+1,right,(char)(c+1));
            int q = calculate(s,left,mid,(char)(c+1));

            return Math.min(leftCost+p,rightCost+q);
        }
    }


    public static void main(String[] args) {
        FastReader input = new FastReader();
        PrintWriter pw = new PrintWriter(System.out);

        int t = input.nextInt();

        while (t > 0){

            int n = input.nextInt();
            String s = input.nextLine();

            int cost = calculate(s,0,n-1,'a');
            pw.println(cost);

            t--;
        }


        // ****If sorting is required, use ArrayList
        pw.flush();
        pw.close();
    }
    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());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}
