import java.util.*;

public class D {
    static int solve(char s[], int left, int right, char c) {
        if (left == right) {
            if (s[left] == c) {
                return 0;
            }
            return 1;
        }
        int first = 0;
        int second = 0;
        int mid = (left + right) / 2;
        for (int i = left; i <= mid; i++) {
            if (s[i] != c) {
                first++;
            }
        }
        for (int i = mid + 1; i <= right; i++) {
            if (s[i] != c) {
                second++;
            }
        }
        int x = solve(s, left, mid, (char) (c + 1));
        int y = solve(s, mid + 1, right, (char) (c + 1));
        return Math.min(first + y, x + second);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        int testCases = sc.nextInt();
        for (int t = 0; t < testCases; t++) {
            int n = sc.nextInt();
            sc.nextLine();
            String str = sc.nextLine();
            char s[] = str.toCharArray();
            sb.append(solve(s, 0, n - 1, 'a')).append("\n");
        }
        System.out.print(sb);
    }
}