
import java.util.*;

public class Codeforces {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String experiments = sc.nextLine();
        int nExperiments = Integer.parseInt(experiments);
        for (int i = 0; i < nExperiments; i++) {
            sc.nextLine();
            String s = sc.nextLine();
            int ans = minNumberOfChanges(s, 'a');
            System.out.println(ans);
        }
    }

    private static int minNumberOfChanges(String s, char c) {
        if (s.length() == 1) {
            return s.charAt(0) == c ? 0 : 1;
        }
        String left = s.substring(0, s.length() / 2);
        String right = s.substring(s.length() / 2);
        int a = minNumberOfChanges(left, (char) (c + 1)) + diff(right, c);
        int b = minNumberOfChanges(right, (char) (c + 1)) + diff(left, c);
        return Math.min(a, b);
    }

    private static int diff(String s, char c) {
        int ans = 0;
        for (char c1 : s.toCharArray()) {
            if (c1 != c) {
                ans++;
            }
        }
        return ans;
    }


}
