import java.util.*;
import java.io.*;
import java.math.*;

public class Main {

    private static FastReader fr = new FastReader();
    private static Helper hp = new Helper();
    private static StringBuilder result = new StringBuilder();

    public static void main(String[] args) {
        Task solver = new Task();
        solver.solve();
    }

    static class Task {

        private long helper(String s, char ch, int n){
            if(n == 1 && s.charAt(0) == ch) return 0;
            if(n == 1 && s.charAt(0) != ch) return 1;
            StringBuilder sb = new StringBuilder();
            for(int i=0; i<n/2; i++) sb.append(ch);
            String newStr = sb.toString();
            long op1 = 0, op2 = 0;
            long ans1 = helper(s.substring(n/2, n), (char)(ch+1), n/2);
            long ans2 = helper(s.substring(0, n/2), (char)(ch+1), n/2);
            if(s.substring(0, n/2).equals(newStr)){
                op1 = ans1;
            }
            else{
                for(int i=0; i<n/2; i++){
                    if(s.charAt(i) != newStr.charAt(i)) op1 += 1;
                }
                op1 += ans1;
            }
            if(s.substring(n/2, n).equals(newStr.toString())){
                op2 = ans2;
            }
            else{
                for(int i=n/2, j=0; i<n; ++i, ++j){
                    if(s.charAt(i) != newStr.charAt(j)) op2 += 1;
                }
                op2 += ans2;
            }
            return Math.min(op1, op2);
        }

        public void solve() {
            int nt = fr.ni();
            while(nt-- > 0){
                int n = fr.ni();
                String s = fr.next();
                long ans = helper(s, 'a', n);
                result.append(ans).append("\n");
            }
            System.out.println(result);
        }
    }

    static class Helper {
        public int[] ipArrInt(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = fr.ni();
            return arr;
        }

        public long[] ipArrLong(int n, int si) {
            long[] arr = new long[n];
            for (int i = si; i < n; i++)
                arr[i] = fr.nl();
            return arr;
        }
    }

    static class FastReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        private static PrintWriter pw;

        public FastReader() {
            reader = new BufferedReader(new InputStreamReader(System.in));
            pw = new PrintWriter(System.out);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ni() {
            return Integer.parseInt(next());
        }

        public long nl() {
            return Long.parseLong(next());
        }

        public double nd() {
            return Double.parseDouble(next());
        }

        public String rl() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        public void print(String str) {
            pw.print(str);
            pw.flush();
        }
    }
}