import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class TaskD {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);
        
        try {
            int t = Integer.parseInt(br.readLine());
            while(t-->0) {
                int n = Integer.parseInt(br.readLine());
                char[] c = br.readLine().toCharArray();
                int ans = solve(c, 0, n-1, 'a');
                pw.println(ans);
            }
        }
        finally {
            pw.flush();
            pw.close();
        }
    }

    static int solve(char[] c, int l, int r, char x) {
        if(r == l) {
            return c[l] != x ? 1 : 0;
        }
        else {
            int c1 = 0;
            int mid = (l+r)/2;
            for(int i=l ; i<=mid ; i++) {
                if(c[i] != x) {
                    c1++;
                }
            }
            c1 += solve(c, mid+1, r, (char)(x+1));

            int c2 = 0;
            for(int i=mid+1 ; i<=r ; i++) {
                if(c[i] != x) {
                    c2++;
                }
            }
            c2 += solve(c, l, mid, (char)(x+1));

            return Math.min(c1, c2);
        }
    }
}
