import java.io.IOException; 
import java.util.Scanner;
 
public class cf1385d {
   	public static void main(String[] args) throws Exception {
         	Scanner in = new Scanner(System.in);
         	int t = in.nextInt();
         	
         	while (t-- > 0) {
                	int n = in.nextInt();
                	String s = in.next();
                	int ans = f('a', s);
                	System.out.println(ans);
         	}
   	}
 
   	public static int f(char c, String s) {
         	if (s.length() == 1) {
                	return s.charAt(0) == c ? 0 : 1;
         	} else {
                	return Math.min(f((char) (c + 1), s.substring(0, s.length() / 2)) +
                              	toc(c, s.substring(s.length() / 2)),
                              	f((char) (c + 1), s.substring(s.length() / 2)) +
                              	toc(c, s.substring(0, s.length() / 2)));
 
         	}
   	}
 
   	public static int toc(char c, String s) {
         	char ch[] = s.toCharArray();
         	int ans = 0;
         	
         	for (int i = 0; i < s.length(); i++) {
                	if (ch[i] != c)
                       	ans++;
         	}
         	
         	return ans;
   	}
}
