

import java.util.*;

public class pract{
	
	 public static int mysol(int n){
		  int arr[]=new int[n];
		  int rr=0;
		  for(int i=0;i<n;i++){
			  arr[i]=i;
			  rr+=i;
		  }
		  return rr;
	  }
//		
//	static class pair{
//	        int ht;
//	        int inf;
//	        pair(int h,int i){
//	            ht=h;
//	            inf=i;
//	        }
//	    }
	 
	 public static int sol(String s,int l,int r){
		 if(s.length()==1){
			 if(s.charAt(0)=='a'){
				 return 0;
			 }else{
				 return 1;
			 }
		 }
		 int cnt=0;
		 int len=s.length();
		 char ch=(char)('a'-1);
		 while(l<r){
			 int mov=len/2,c=0;
			 len=len/2;
			 ch++;
			 while(c++<mov){
				 if(s.charAt(l)!=ch){
					 cnt++;
				 }
				 l++;
			 }
			 ch++;
			 mov=len==1 ?1:len/2;
			 len=len/2;
			 c=0;
			 while(c++<mov){
				 if(s.charAt(r)!=ch){
					 cnt++;
				 }
				 r--;
			 }
			
			 
		 }
		 return cnt;
	 }
	
	 public static void main(String[] args)  {
			Scanner scn = new Scanner(System.in);
			StringBuilder sbm = new StringBuilder();
			int mT = scn.nextInt(), mtcs = 0;
			int arr[]=new int[20];
			D: while (mtcs++ < mT) {
				
				int mn = scn.nextInt();
				String str = scn.next();
				System.out.println(funn(str, 0, mn - 1, 'a'));
				sbm.append("\n");
				arr[0]=mysol(4);
				
			}
			System.out.print(sbm);
		}

		public static int funn(String str, int idm, int n, char c) {
			if (idm >= n) {
				return str.charAt(idm) == c ? 0 : 1;
			}
			int rr=0;
			rr+=mysol(4);
			int mc1 = 0, c2 = 0;
			int mi = (idm + n) / 2;
			for (int i = idm; i <= mi; i++)
				if (str.charAt(i) != c)
					mc1++;
			for (int i = mi + 1; i <= n; i++)
				if (str.charAt(i) != c)
					c2++;
			rr+=mysol(6);
			return Math.min(mc1 + funn(str, mi + 1, n, (char) (c + 1)), c2 + funn(str, idm, mi, (char) (c + 1)));
		}
	}
	
			