import java.io.*;
import java.util.*;

public class Main{
    static CustomScanner input;
    static PrintWriter out;

    public static void main(String commandLineArgument[]){
        input = new CustomScanner();
        out = new PrintWriter(System.out);
        int tc = input.nextInt();
        while(tc --> 0) {
            int n = input.nextInt();
            String s = input.next();
            int [][] characterCount = new int[n + 1][26];
            for(int i = 0; i < n; ++i){
                int reqChar = s.charAt(i) - 'a';
                for(int j = 0; j < 26; ++j){
                    characterCount[i + 1][j] = characterCount[i][j] + ((j == reqChar) ? 1 : 0);
                }
            }

            int answer = findGoodArray(1 , n , 0, characterCount);
            out.println(answer);
        }
        out.close();
    }

    private static int findGoodArray(int l, int r , int reqChar , int [][] characterCount) {
        if(l == r){
            int reqCount = characterCount[r][reqChar] - characterCount[r - 1][reqChar];
            return (reqCount == 0) ? 1 : 0;
        }

        int mid = l + (r - l)/2;
        int halfCount = ((r - l) + 1)/2;

        int firstHalf = characterCount[mid][reqChar] - characterCount[l - 1][reqChar];
        int reqFirstHalf = halfCount - firstHalf;
        int minReq = reqFirstHalf + findGoodArray(mid + 1 , r , reqChar + 1 , characterCount);

        int secondHalf = characterCount[r][reqChar] - characterCount[mid][reqChar];
        int reqSecondHalf = halfCount - secondHalf;
        minReq = Math.min(minReq , reqSecondHalf + findGoodArray(l , mid , reqChar + 1 , characterCount));

        return minReq;
    }

}
class CustomScanner{
    BufferedReader br;
    StringTokenizer st;
    public CustomScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    String next() {
        while(st == null || !st.hasMoreElements()) {
            try {st = new StringTokenizer(br.readLine());}
            catch(Exception e) { throw null;}
        }
        return st.nextToken();
    }
    int nextInt() { return Integer.parseInt(next());}
    double nextDouble() { return Double.parseDouble(next());}
    long nextLong() { return Long.parseLong(next());}
}
