import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Codeforces {

    static FastScanner sc;
    static PrintWriter out;
    static int mod = (int) (1e9+7);

    public static void main(String[] args){
        sc = new FastScanner();
        out = new PrintWriter(System.out);

        int t = sc.nextInt();
        while(t-- > 0){
            solve();
        }

        out.close();
    }

    private static void solve() {

        int n = sc.nextInt();
        String s = sc.next();
        
        int op = helper(s, n, 0);
        out.println(op);
    }

    private static int helper(String s, int n, int k) {

        char c = (char) (k + 'a');
//        out.println(c);
        if(n == 1){
            if(s.charAt(0) == c)
                return 0;
            else
                return 1;
        }

        String s1 = s.substring(0, n/2);
        String s2 = s.substring(n/2, n);
//        out.println(s1 + " " + s2);
        int val1 = 0, val2 = 0;

        for(int i=0; i<n/2; i++){
            if(s.charAt(i) != c)
                val1++;
        }
        for(int i=n/2; i<n; i++){
            if(s.charAt(i) != c)
                val2++;
        }
        k++;
        return Math.min(val1 + helper(s2, n/2, k), val2 + helper(s1, n/2, k));

    }

    public static int nCr(int n, int k) {
        int C[] = new int[k + 1];

        // nC0 is 1
        C[0] = 1;

        for (int i = 1; i <= n; i++) {
            // Compute next row of pascal
            // triangle using the previous row
            for (int j = Math.min(i, k); j > 0; j--)
                C[j] = (C[j]%mod + C[j - 1]%mod)%mod;
        }
        return C[k]%mod;
    }

    private static int findLcm(int n, int m) {

        return n*m/findGcd(Math.min(n, m), Math.max(n, m));
    }

    private static int findGcd(int n, int m) {
        if(n == 0)
            return m;
        return findGcd(m%n, n);
    }

    private static long findLcm(long n, long m) {

        return n*m/findGcd(Math.min(n, m), Math.max(n, m));
    }

    private static long findGcd(long n, long m) {
        if(n == 0)
            return m;
        return findGcd(m%n, n);
    }

    public static void intSort (int[] arr) {
        //First ruffle

        int n = arr.length;
        Random r = new Random();
        for (int i=0; i<arr.length; i++) {
            int j = r.nextInt(n);
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }

        //then sort
        Arrays.sort(arr);
    }

    public static void longSort (long[] arr) {
        //First ruffle

        int n = arr.length;
        Random r = new Random();
        for (int i=0; i<arr.length; i++) {
            int j = r.nextInt(n);
            long temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }

        //then sort
        Arrays.sort(arr);
    }

    public static void sort2dArray (long[][] arr) {
        Arrays.sort(arr, (a, b) -> {
            if (a[0] == b[0])
                return (int) (a[1] - b[1]);
            return (int) (a[0] - b[0]);
        });
//        Arrays.sort(arr, (a, b) -> {
//            if (a[1] == b[1])
//                return (int) (a[0] - b[0]);
//            return (int) (a[1] - b[1]);
//        });
    }

    public static void sort2dArray (int[][] arr) {
//        Arrays.sort(arr, (a, b) -> {
//            if (a[1] == b[1])
//                return (int) (a[0] - b[0]);
//            return (int) (a[1] - b[1]);
//        });
        Arrays.sort(arr, (a, b) -> {
            if (a[0] == b[0])
                return (int) (a[1] - b[1]);
            return (int) (a[0] - b[0]);
        });
    }

    public static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }

}

