/*package whatever //do not write package name here */

import java.sql.SQLOutput;
import java.util.*;
import java.lang.*;
import java.io.*;

public class cp {
    static int counter(int start, int n,String s, char c) {
        int count=0;
        for (int i=start;i<n;i++)
            if (s.charAt(i)==c) count++;
         return count;
    }
    static int answer(int start, int n,String s, char c) {
        //System.out.println(c);
        int ans=0;
        if (start+1==n && s.charAt(n-1)==c) return 0;
        if (start+1==n && s.charAt(n-1)!=c) return 1;
        int c_left=counter(start,n/2,s,c);
        int c_right=counter(n/2,n,s,c);
        //System.out.println(c_left+" "+c_right);
        if (c_left< c_right) {
            //System.out.println("left send" + ans);
            ans+= (n-start)/2 - c_right + answer(start,(n-start)/2 +start ,s,(char)(c+1));

        }

        else {
            //System.out.println("Right send");
            ans+= (n-start)/2 - c_left + answer(n-(n-start)/2,n,s,(char)(c+1));
            //System.out.println("ans "+ans);

        }

        return ans;

    }

    public static void main (String[] args) {
        //code

        Scanner in =new Scanner(System.in);
        int t=in.nextInt();

        while(t-->0){
            int n=in.nextInt();
            String s=in.next();
            System.out.println(answer(0,n,s,'a'));
            }





    }
}