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

public class Main {

    private static int testCase(int n, String s) {
        return replacesNeeded(s.toCharArray(), 0, n, 'a');
    }

    private static int replacesNeeded(char[] s, int start, int end, char c) {
        if (end == start + 1) {
            return s[start] == c ? 0 : 1;
        } else {
            int countFirst = 0, countSecond = 0;
            int mid = (start + end) >> 1;

            for (int i = start; i < mid; i++) {
                if (s[i] == c) countFirst++;
            }

            for (int i = mid; i < end; i++) {
                if (s[i] == c) countSecond++;
            }

            return Math.min((mid - start) - countFirst + replacesNeeded(s, mid, end, (char) (c + 1)), (mid - start) - countSecond + replacesNeeded(s, start, mid, (char) (c + 1)));
        }
    }

    public static void main(String[] args) {
        FastScanner in = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int t = in.nextInt();  // Scanner has functions to read ints, longs, strings, chars, etc.
        //in.nextLine();
        for (int i = 1; i <= t; ++i) {
            int n = in.nextInt();
            String s = in.next();

            out.println(testCase(n, s));
        }

        out.close();
    }

    private 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());
        }
    }
}