import java.util.*;

public class Prb4{
    static int ans = 0;


    static void find(String s, int i, int j, char t){
        if( i == j){
            ans += s.charAt(i) == t ? 0 : 1;
            return ;
        }
        
        int fchar = 0, fnextChar = 0, schar = 0, snextChar = 0;
        int st = i, end = j, mid = (i + j) / 2;

        while( i < j ){
            if( s.charAt(i) == t )
                fchar++;
            else if( s.charAt(i) == (char)(t+1)) 
                fnextChar++;
            
            if( s.charAt(j) == t )
                schar++;
            else if( s.charAt(j) == (char)(t+1)) 
                snextChar++;

                i++;
                j--;
        }

        if( fchar > schar ){
            ans += mid - st + 1 - (fchar);
            find(s, mid+1, end, (char)(t+1));
        }
        else if( fchar < schar){
            ans += end - mid- schar;
            find(s, st, mid, (char)(t+1));
        }
        else{
            if( fnextChar > snextChar  ){
                ans += end - mid- (schar); 
                ans += -fchar + fnextChar;
                find(s, st, mid, (char)(t+1));
            }
            else{
                ans += mid - st + 1 - (fchar); 
                find(s, mid+1 , end, (char)(t+1));
            }
        }

    }

    public static void main(String[] args) {
        try {
            

            Scanner sc = new Scanner(System.in);
            int t = sc.nextInt();
            while(t--> 0 ){
                ans = 0;
                int n = sc.nextInt();
                String s = sc.next();
                find(s, 0, n-1, 'a');
                System.out.println(ans);
            }

        } catch (Exception e) {
            //TODO: handle exception
        }
    }
}