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


       }
    }

}