import java.util.Scanner;
import java.awt.image.BandedSampleModel;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class A {

    public static int rec(String s,int start,int ans)
    {
        if(s.length()==1&&s.charAt(0)-'a'==start)
        {
            return 0;
        }
        else if(s.length()==1)
        {
            return 1;
        }
        else
        {
            int temp=0;
            for(int i=0;i<s.length()/2;i++)
            {
                if(s.charAt(i)-'a'!=start)
                {
                    temp++;
                }
            }

            int temp2=0;
            for(int i=s.length()-1;i>=s.length()/2;i--)
            {
                if(s.charAt(i)-'a'!=start)
                {
                    temp2++;
                }
            }

            return Math.min(temp2+rec(s.substring(0,s.length()/2),start+1,ans+temp2),temp+rec(s.substring(s.length()/2,s.length()),start+1,ans+temp));
        }


    }

    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int cases = sc.nextInt();
        for(int i=0;i<cases;i++)
        {
           int n=sc.nextInt();
           String s=sc.next();
           //int ans=0;
            int arr[]=new int[n];
            for(int j=0;j<n;j++)
            {
                arr[j]=s.charAt(j)-'a';
            }
           int ans=rec(s,0,0);
            System.out.println(ans);

        }

    }
}
