import java.util.*;

public class D656 {
    static int [][] frq;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t > 0) {
            int n = sc.nextInt();
            String s = sc.next();
            frq = new int[26][n + 1];
            for (int i = 0; i < 26; i++) {
                for (int j = 1; j <= n; j++) {
                    frq[i][j] = frq[i][j - 1] + (s.charAt(j - 1) == (char) (i + 97) ? 1 : 0);
                }
            }
            System.out.println(solve(1, n, 0));
            t--;
        }

    }

    static int solve(int lo, int hi, int c) {
        if (lo == hi) return 1 - (frq[c][hi] - frq[c][lo - 1]);
        int mid = (lo + hi) / 2; int num = (hi - lo + 1) / 2;
        int lower = num - (frq[c][mid] - frq[c][lo - 1]);
        int upper = num - (frq[c][hi] - frq[c][mid]);
        lower += solve(mid + 1, hi, c + 1);
        upper += solve(lo, mid, c + 1);
        return Math.min(lower, upper);
    }


}