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

public class Codeforces
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        int t=Integer.parseInt(bu.readLine());
        while(t-->0)
        {
            int n=Integer.parseInt(bu.readLine());
            char s[]=bu.readLine().toCharArray();
            int i,j,c[][]=new int[n+1][26];
            for(i=1;i<=n;i++)
            {
                for(j=0;j<26;j++)
                c[i][j]=c[i-1][j];
                c[i][s[i-1]-'a']++;
            }
            if(n==1)
            {
                int ans=0;
                if(c[1][0]==0) ans=1;
                else ans=0;
                sb.append(ans+"\n");
                continue;
            }
            if(c[n][0]==n)
            {
                sb.append(n/2+"\n");
                continue;
            }
            int ans=count(c,1,n,0);
            sb.append(ans+"\n");
        }
        System.out.print(sb);
    }

    static int count(int a[][],int l,int r,int x)
    {
        if(l==r)
        {
            if(a[l][x]-a[l-1][x]==1) return 0;
            else return 1;
        }
        int c1=a[l+(r-l)/2][x]-a[l-1][x],c2=a[r][x]-a[l+(r-l)/2][x];
        if(c1>c2) return (r-l+1)/2-c1+count(a,l+(r-l)/2+1,r,x+1);
        else if(c2>c1) return (r-l+1)/2-c2+count(a,l,l+(r-l)/2,x+1);
        else return (r-l+1)/2-c1+Math.min(count(a,l,l+(r-l)/2,x+1),count(a,l+(r-l)/2+1,r,x+1));
    }
}