import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
public class Main {
    public static HashMap<String, Integer>map=new HashMap<String,Integer>();
    public static int cost(String str, char c)
    {
        if(map.containsKey(str+" "+c))
            return map.get(str+" "+c);
        if(str.length()==1)
        {
            if(str.charAt(0)==c)
                return 0;
            return 1;
        }
        int countL=0;
        int countR=0;
        for(int i=0;i<str.length()/2;i++)
        {
            if(str.charAt(i)!=c)
                countL++;
        }
        for(int i=str.length()/2;i<str.length();i++)
        {
            if(str.charAt(i)!=c)
                countR++;
        }
        countL=countL+cost(str.substring(str.length()/2),(char)(c+1));
        countR=countR+cost(str.substring(0,str.length()/2),(char)(c+1));
        map.put(str+" "+c,Math.min(countL,countR));
        return Math.min(countL,countR);
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        for(int q=0;q<t;q++)
        {
            int n=sc.nextInt();
            sc.nextLine();
            String str=sc.nextLine();
            System.out.println(cost(str,'a'));
    //        System.out.println(map.get(str+" a"));
        }
    }
}