import java.io.*;
import java.util.*;  
public class main {	
	static String s;
	static int[][] memo;
	public static int solve(char c, int start, int end)
	{
		if(start==end)return 1-(memo[c-'a'][start]-memo[c-'a'][start-1]);
		int mistakesFirst=(end-start+1)/2-(memo[c-'a'][(start+end)/2]-memo[c-'a'][start-1])+solve(++c, (start+end)/2+1, end);c--;
		int mistakesLast=(end-start+1)/2-(memo[c-'a'][end]-memo[c-'a'][(start+end)/2])+solve(++c, start, (start+end)/2);c--;
		return Math.min(mistakesFirst, mistakesLast);
	}
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw= new PrintWriter(System.out);
		int t = Integer.parseInt(br.readLine());
		for (int i = 0; i < t; i++) {
			int n = Integer.parseInt(br.readLine());
			s = br.readLine();
			memo= new int[26][n+1];
			for (char c = 'a'; c <= 'z'; c++) {
				for (int j = 0; j < n; j++) {
					if(s.charAt(j)==c)memo[c-'a'][j+1]++;
					memo[c-'a'][j+1]+=memo[c-'a'][j];
				}
			}
			pw.println(solve('a',1, s.length()));
		}
		pw.close();
	}
}