import java.util.*;

public class Main {
    public static int count(char[] c, int l, int r, char symbol) {
        if (r - l == 0) {
            if (c[l] == symbol) return 0;
            return 1;
        }
        char next = (char) (((int) symbol) + 1);
        int n = (r - l + 1) / 2;
        int ml = l + (r - l) / 2;
        int mr = ml + 1;
        int maxL = 0, maxR = 0;
        int nextL = 0, nextR = 0;
        for (int i = l; i <= ml; i++) {
            if (c[i] == symbol)
                maxL++;
            if (c[i] == next)
                nextL += 1;
        }
        for (int i = mr; i <= r; i++) {
            if (c[i] == symbol)
                maxR++;
            if (c[i] == next)
                nextR += 1;
        }

        if (maxL > maxR || (maxL == maxR && nextL <= nextR)) {
//            System.out.println("l " + (n - maxL) + " " + mr + " " + r);
            return (n - maxL) + count(c, mr, r, next);
        } else {
//            System.out.println("r " + (n - maxR) + " " + l + " " + ml);
            return (n - maxR) + count(c, l, ml, (char) next);
        }
    }

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int _t = s.nextInt();
        for (int t = 0; t < _t; t++) {
            int n = s.nextInt();
            char[] c = s.next().toCharArray();
            System.out.println(count(c, 0, n - 1, 'a'));
        }
    }
}