import java.util.Arrays;
import java.util.Scanner;

public class P1385D {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        sc.nextLine();
        while (t-- > 0) {
            String n = sc.nextLine();
            char[] chars = sc.nextLine().toCharArray();
            System.out.println(check(chars, 'a'));

        }
    }

    private static int check(char[] chars, char c) {
        if (chars.length == 0) return 0;
        if (chars.length == 1){
            if (chars[0] == c) return 0;
            return 1;
        }

        char[] left = Arrays.copyOfRange(chars, 0, chars.length / 2);
        char[] right = Arrays.copyOfRange(chars, chars.length / 2, chars.length);
        int leftdist = dist(left, c);
        int rightdist = dist(right, c);
        if (leftdist < rightdist) {
            return leftdist + check(right, ++c);
        } else if (leftdist > rightdist){
            return rightdist + check(left, ++c);
        } else {
            return leftdist + Math.min(check(right, ++c), check(left, ++c));
        }
    }

    private static int dist(char[] chars, char c) {
        int sum = 0;
        for(char x : chars) {
            if (x != c) sum++;
        }
        return sum;
    }
}