import java.util.Scanner;

public class CGoodString {
    static class Solution{

        public int solve(char[] str,int l,int r,char c){
            int len = r - l +1;
            if(len==1) return str[l]==c?0:1;
            int left = 0,right=0;
            int m = l+len/2;
            for(int i=l;i<=r;i++){
                if (str[i] != c) {
                    if(i<m) left++;
                    else right++;
                }
            }
            int ans = Integer.MAX_VALUE;
            ans = Math.min(ans, left + solve(str, m, r, (char) (c + 1)));
            ans = Math.min(ans, solve(str, l, m - 1, (char) (c + 1)) + right);
            return ans;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Solution solution = new Solution();
        int tt = scanner.nextInt();
        for (int i = 1; i <= tt; i++) {
            int n = scanner.nextInt();
            String str = scanner.next();
            int ans = solution.solve(str.toCharArray(),0,str.length()-1,'a');
            System.out.println(ans);
        }
    }
}
