import java.io.*;
import java.util.*;
//import java.util.HashMap;


//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.io.PrintWriter;
//import java.math.BigInteger;
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.HashMap;
//import java.util.StringTokenizer;

public class Equal {
    static ArrayList<Integer>[] tree;
    static boolean[] vis;
    static int dp[][];

    //    static boolean dfs(int u, int dest) {
    //        if (dp[u][dest] != 0) {
    //            if (dp[u][dest] == 1)
    //                return true;
    //            return false;
    //        }
    //        vis[u] = true;
    //        if (u == dest) {
    //            vis[u] = false;
    //            dp[u][dest] = 1;
    //            return true;
    //        }
    //        for (int i = 0; i < tree[u].size(); i++) {
    //            int v = tree[u].get(i);
    //            if (vis[v])
    //                continue;
    //            if (dfs(v, dest)) {
    //                vis[u] = false;
    //                dp[u][dest] = 1;
    //                dp[dest][u] = 1;
    //
    //                return true;
    //            }
    //
    //        }
    //        vis[u] = false;
    //        dp[u][dest] = -1;
    //        dp[dest][u] = -1;
    //        return false;
    //    }
    static class pair implements Comparable<pair> {
        int x;
        int t;

        public pair(int xx, int tt) {
            x = xx;
            t = tt;
        }

        @Override
        public int compareTo(pair o) {
            return t - o.t;
        }
    }

    static boolean dif1(String x, String y) {
        int dif = 0;
        if (x.length() != y.length())
            return false;
        for (int i = 0; i < x.length(); i++) {
            if (x.charAt(i) != y.charAt(i))
                dif++;
        }
        return dif <= 1;
    }

    static int[] p;
    static int[] rank;

    static int findSet(int i) {
        return (p[i] == i) ? i : (p[i] = findSet(p[i]));
    }

    static boolean isSameSet(int i, int j) {
        return findSet(i) == findSet(j);
    }

    static void unionSet(int i, int j) {
        if (!isSameSet(i, j)) {
            int x = findSet(i);
            int y = findSet(j);
            if (rank[x] > rank[y]) {
                p[y] = x;
            } else {
                p[x] = y;
                if (rank[x] == rank[y])
                    rank[y]++;
            }
        }
    }

    static int allSame(String s, int beg, int end, char x) {
        int[] alph = new int['z' - 'a' + 1];

        for (int i = beg; i <= end; i++) {
            alph[s.charAt(i) - 'a']++;

        }
        return (end - beg + 1) - alph[x - 'a'];
    }

    static int bruteForce(String s, int beg, int end, char x) {
        if (beg == end) {
            if (s.charAt(beg) == x)
                return 0;
            return 1;
        }
        return Math.min(allSame(s, beg, (beg + end) / 2, x) + bruteForce(s, ((beg + end) / 2) + 1, end, (char) (x + 1))
                , bruteForce(s, beg, (beg + end) / 2, (char) (x + 1)) + allSame(s, ((beg + end) / 2) + 1, end, x)
        );
    }

    public static void main(String[] args) throws IOException {
        //BufferedReader br = new BufferedReader(new FileReader("name.in"));
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter out = new PrintWriter(System.out);

        int T = Integer.parseInt(br.readLine());
        while (T-- > 0) {
            int n = Integer.parseInt(br.readLine());
            out.println(bruteForce(br.readLine(), 0, n - 1, 'a'));
        }

        out.flush();
        out.close();

    }


}
