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

public class D_aGoogString {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static final PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    private static final StringBuilder sb = new StringBuilder();
    static int[] nums;
    private static StringTokenizer st;

    private static int readInt() throws IOException {
        while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return Integer.parseInt(st.nextToken());
    }

    private static String readToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public static void main(String[] args) throws IOException {
        int T = readInt();
        while (T-- > 0) pw.println(solve());
        pw.close();
    }

    private static int solve() throws IOException {
        int n = readInt();
        char[] s = readToken().toCharArray();
        nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = s[i] - 'a';
        }

        if (n == 1) {
            if (nums[0] == 0) return 0;
            else return 1;
        } else {
            return n - solve(0, n, 0);
        }
    }

    // end-start must be 2, 4, 8, 16, ...
    // return maximum correct positions.
    private static int solve(int start, int end, int c) {
        if (end - start == 2) {
            if (nums[start] == c) {
                if (nums[start + 1] == c + 1) return 2;
                return 1;
            } else {
                if (nums[start + 1] == c) {
                    if (nums[start] == c + 1) return 2;
                    return 1;
                } else {
                    if (nums[start + 1] == c + 1) return 1;
                    return 0;
                }
            }
        }

        return Math.max(countDifference(start, (start + end) / 2, c) + solve((start + end) / 2, end, c + 1),
                solve(start, (start + end) / 2, c + 1) + countDifference((start + end) / 2, end, c));
    }

    static int countDifference(int start, int end, int wanted) {
        int count = 0;
        for (int i = start; i < end; i++) {
            if (nums[i] == wanted) count++;
        }
        return count;
    }
}
