import java.util.Scanner;

public class ProblemD {

    static int needReplace(char c, char[] s, int fromIncl, int toExcl) {
        int count = 0;
        for (int i = fromIncl; i < toExcl; i++) {
            if (s[i] != c) {
                count++;
            }
        }
        return count;
    }

    static int findMin(char c, char[] s, int fromIncl, int toExcl) {
        if (fromIncl == toExcl - 1) {
            return c == s[fromIncl] ? 0 : 1;
        }
        // Choose c from left and go right
        int mid = (fromIncl + toExcl) / 2;
        int chooseLeft = needReplace(c, s, fromIncl, mid)
                + findMin((char)((int)c + 1), s, mid, toExcl);
        // Choose c from right and go left
        int chooseRight = needReplace(c, s, mid, toExcl)
                + findMin((char)((int)c + 1), s, fromIncl, mid);
        return Math.min(chooseLeft, chooseRight);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();

        for (int i = 0; i < t; i++) {
            int n = scanner.nextInt();
            String s = scanner.next();

            System.out.println(findMin('a', s.toCharArray(), 0, n));
        }
    }
}
