import java.io.*;
import java.util.*;

public class A {
	
	public static int count(int start , int end , char c ,String s) {
		
		int count = 0;
		
		for(int i = start ; i <= end ;i++) {
			char curr = s.charAt(i);
			
			if(curr == c) {
				count++;
			}
		}
			
		return count;
		
		
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
			FastScanner sc = new FastScanner();
			
			int t = sc.nextInt();
			StringBuilder sb = new StringBuilder();
			
			while(t-- > 0) {
				
				int n = sc.nextInt();
				
				String s = sc.next();
				
				int res = 0;
				
				int start  = 0;
				int end = s.length() - 1;
				int target = n / 2;
				
				int limit = 0;
				int base = 1;
				
				while(base < n) {
					base <<= 1;
					limit++;
					
				}
				int[][] map = new int[26][n];
				
				for(int i = 0 ;i < n ; i++) {
					char c = s.charAt(i);
					int index = (int)(c - 'a');
					map[index][i]++;
				}
				
				char finalChar = (char)('a' + limit);
				//System.out.println(finalChar);
				
				for(char c = 'a' ; c < finalChar ; c++) {
					
					int mid = start + (end - start) / 2;
					
					int count1 = count(start , mid , c , s);
					int count2 = count(mid + 1, end , c , s);
					
					
					if(count1 == count2 ) {
						//System.out.println(c);
						boolean found  =false;
						for(char d = (char)(c + 1) ; d < finalChar ; d++) {
							
							int index = (int)(d - 'a');
							
							int leftCount = map[index][mid] - map[index][start];
							int rightCount = map[index][end] - map[index][mid + 1];
							if(leftCount > rightCount) {
								found  =true;
								end = mid;
							}
							else if(rightCount > leftCount) {
								found  =true;
								start = mid + 1;
							}
							
						}
						if(!found) {
							start = mid + 1;
						}
						res += target - count1;
						target >>>=1 ;
						continue;
					}
					else if(count1 > count2) {
						res += target - count1;
						
						start = mid + 1;
					}
					
					else if(count2 > count1) {
						res += target - count2;
						
						end = mid;
					}
					
					target >>>= 1;
					
					
				}
				
				if(s.charAt(start) != finalChar && s.charAt(end) != finalChar) {
					res++;
				}
				
				sb.append(res);
				sb.append("\n");
				
			}
			System.out.println(sb);
			
			
			

	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

}
