//created by Whiplash99
import java.io.*;
import java.util.*;
public class D
{
    private static int solve(char[] str, int l, int r, char cur)
    {
        if(l==r) return str[l]==cur?0:1;
        int mid=(l+r)/2;

        int c1=0,c2=0;
        for(int i=0;i<=mid;i++) if(str[i]!=cur) c1++;
        for(int i=mid+1;i<=r;i++) if(str[i]!=cur) c2++;

        int tmp1=c1+solve(str,mid+1,r,(char)(cur+1));
        int tmp2=c2+solve(str,l,mid,(char)(cur+1));

        return Math.min(tmp1,tmp2);
    }
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        int T=Integer.parseInt(br.readLine().trim());
        StringBuilder sb=new StringBuilder();

        while(T-->0)
        {
            N=Integer.parseInt(br.readLine().trim());
            char[] str=br.readLine().trim().toCharArray();

            sb.append(solve(str,0,N-1,'a')).append("\n");
        }
        System.out.println(sb);
    }
}