import java.util.*;
public class Main {
  static	int c=0;
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int t=in.nextInt();
		while(t-->0) {
			int n=in.nextInt();
			String str=in.next();
			int z=good(str, 0, str.length()-1, 'a');
			System.out.println(z);
			
		}
		
	}
	
	public static int good(String str, int l ,int r, char ch){
	    c++;
	    if(l==r){
	        if(str.charAt(l)==ch){
	           
	            return 0;
	        }
	        return 1;
	    }
	    if(l>r){
	        return 1000000;
	    }
	    int mid=(l+r)/2;
	    int c1=0, c2=0;
	    for(int i=l ; i<=mid ; i++){
	        if(str.charAt(i)!=ch){
	            c1+=1;
	           
	        }
	    }
	    for(int i=mid+1 ; i<=r ; i++){
	        if(str.charAt(i)!=ch){
	            c2+=1;
	            
	        }
	    }
	    c1+=good(str, mid+1, r, (char)(ch+1));
	    c2+=good(str, l, mid, (char)(ch+1));
	    return Math.min(c1, c2);
	}
	
}