import java.util.Scanner;

public class Main {
	static int ans = -1;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		int tc = s.nextInt();
		for(int i = 0;i < tc;i++) {
		int n = s.nextInt();
		String str = s.next();
		char c = 'a';
		fun(n , 0 , c , 0 , n , str);
		System.out.println(ans);
		}
	}
	public static void fun(int k , int val , char c , int l , int r , String str) {
		if(k == 1) {
			if(str.charAt(l) != c) {
				val++;
			}
			if(ans == -1 || ans > val) {
				ans = val;
			}
			return ;
		}
		int cnt1 = 0;
		int cnt2 = 0;
		for(int i = l;i < (l + r) / 2;i++) {
			if(str.charAt(i) != c) {
				cnt1++;
			}
		}
		for(int i = (l + r) / 2;i < r;i++) {
			if(str.charAt(i) != c) {
				cnt2++;
			}
		}
		fun(k / 2 , val + cnt2 , (char)(c + 1) , l , (l + r) / 2 , str);
		fun(k / 2 , val + cnt1 , (char)(c + 1) , (l + r) / 2 , r , str);
	}

}
