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

public class _1385D {
    static int[] MODS = {1000000007, 998244353, 1000000009};
    static int MOD = MODS[0];
    static int n;
    static int[][] dp;
    static String s;

    public static void main(String[] args) {
        sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int t = sc.nextInt();
        while (t-- > 0) {
            n = sc.nextInt();
            dp = new int[2*n][26];
            s = sc.next();
            for (int i = 0; i < dp.length; i++) {
                Arrays.fill(dp[i], -1);
            }
            for (int i = n; i < 2*n; i++) {
                Arrays.fill(dp[i], 1);
                for (int j = 0; j < 26; j++) {
                    dp[i][s.charAt(i-n)-'a'] = 0;
                }
            }
            out.println(dpmypp(1, 0));
        }
        out.close();
    }

    public static int dpmypp(int a, int b) {
        if (dp[a][b] != -1) {
            return dp[a][b];
        }
        int pow = (int) (Math.log(a) / Math.log(2));
        int interval = n / (int) Math.pow(2, pow);
        int left = interval * (a - (int) Math.pow(2, pow));
        int right = left + interval;
        int middle = left + interval / 2;
        int count = 0;
        for (int i = left; i < middle; i++) {
            if (s.charAt(i) == 'a'+b) {
                count++;
            }
        }
        dp[a][b] = dpmypp(2*a+1, (b+1) % 26) + middle - left - count;
        count = 0;
        for (int i = middle; i < right; i++) {
            if (s.charAt(i) == 'a'+b) {
                count++;
            }
        }
        dp[a][b] = Math.min(dp[a][b], dpmypp(2*a, (b+1) % 26) + right - middle - count);
        return dp[a][b];
    }

    public static int[] sort(int[] arr) {
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < arr.length; i++) {
            list.add(arr[i]);
        }
        Collections.sort(list);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = list.get(i);
        }
        return arr;
    }

    public static void scan(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            arr[i] = sc.nextInt();
        }
    }

    public static MyScanner sc;
    public static PrintWriter out;

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            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;
        }
    }
}
