/*package whatever //do not write package name here */

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

public class GFG {
	public static void main (String[] args) {
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0)
		{
		    int n=sc.nextInt();
		    String str=sc.next();
		    int res=Integer.MAX_VALUE;
		    for(int i=0;i<n;i++)
		    {
		        if(res>(str.charAt(i)+0))
		        res=str.charAt(i)+0;
		    }
		    int k=rec(str,0,n-1,(char)res);
		    System.out.println(k);
		}
	}
	public static int rec( String str,int s,int e,char c)
	{
	    
	    if(s==e)
	    {
	        if(str.charAt(s)!=c)
	        return 1;
	        return 0;
	    }
	    if(s>e)
	    {
	        
	        return 0;
	    }
	    
	    int count1=0;
	    int count2=0;
	    for(int i=s;i<s+(e-s+1)/2;i++ )
	    {
	        if(str.charAt(i)!=c)
	        count1++;
	    }
	    for(int i=s+(e-s+1)/2;i<=e;i++)
	    {
	        if(str.charAt(i)!=c)
	        count2++;
	    }
	    
	    return Math.min( (count1+rec(str,s+(e-s+1)/2,e,(char)(c+1))),
	                      (count2+rec(str,s,s+((e-s+1)/2)-1,(char)(c+1))));
	    
	  
	}
}