import java.util.*;
public class agoodstring
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        int n;
        String s;
        while(t>0)
        {
            --t;
            n=sc.nextInt();
            s=sc.next();
            char ch='a';
            int q=check(s,0,n,ch);
            System.out.println(q);
        }
    }
    public static int check(String s,int start,int end,char ch)//bbdcaaaa,2,4,'c'
    {
        if(start>=end)
            return 0;
        if(start==end-1)
        {
            if(s.charAt(start)==ch)
                return 0;
            else
                return 1;
        }
        int mid=(start+end)/2;//3
        int c1=0;
        int c2=0;
        for(int i=start;i<mid;i++)
        {
            if(s.charAt(i)!=ch)
                c1++;//1
        }
        for(int i=mid;i<end;i++)
        {
            if(s.charAt(i)!=ch)
                c2++;//0
        }
        return Math.min(c1+check(s,mid,end,(char)(ch+1)),c2+check(s,start,mid,(char)(ch+1)));
    }
}