import java.util.*;
import java.io.*;
public class EdD {

	public static void main(String[] args) throws Exception{

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		int t = Integer.parseInt(bf.readLine());
 		for(int i = 0;i<t;i++){
//	 		String input1 = bf.readLine().trim();
//	 		String input2 = bf.readLine().trim();
	 		int len = Integer.parseInt(bf.readLine());
	 		String input = bf.readLine().trim();
	 		int size = 1;
	 		int num = 1;
	 		while(num != len){
	 			num*=2;
	 			size++;
	 		}
	 		int[][] array = new int[len+1][26];
	 		
	 		for(int j=0;j<len;j++){
	 			char temp = input.charAt(j);
	 			for(int k = 0;k<26;k++){
	 				array[j+1][k] = array[j][k];
	 			}
	 			array[j+1][(int)(temp)-97] = array[j][(int)(temp)-97]+1;

	 		}
 			int add = size-1;
 			char lastletter = 'a';
 			lastletter+=add;
 			int maxsum = 0;
 			for(int j = 0;j<len;j++){
 				int sum = 0;
 				int temp = j+0;
 				int temp1 = j+0;
 				int prod = 1;
	 			for(char k = lastletter;k>='a';k--){
	 				sum+= (array[temp+(int)(Math.ceil((prod+0.0)/2.0))][(int)(k)-97] - array[temp][(int)(k)-97]);
	 				temp = temp/prod * prod;
	 				if (temp1%2 == 0){
	 					temp+=prod;
	 				}
	 				else{
	 					temp-=prod;
	 				}
	 				temp1/=2;
	 				prod*=2;
	 			}
	 			maxsum = Math.max(sum,  maxsum);
 			}
 			out.println(len-maxsum);
 		}
 		
 		
 		out.println();
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	


