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

// Created by @thesupremeone on 09/05/21
public class AGoodStrings {
    int[][] superPrefix;

    HashMap<String, Long> dp = new HashMap<>();

    long countString(String s, int start, int end, char c, int size){
        if(start==end)
            return s.charAt(start)!=c ? 1 : 0;
        String key = start+":"+end+":"+c;
        if(dp.containsKey(key))
            return dp.get(key);
        int[] prefix = superPrefix[c-'a'];
        int mid = (start+end)/2;
        long ans1 = 0;
        ans1 += size-Math.max(prefix[mid]-((start-1)>=0 ? prefix[start-1] : 0), 0);
        ans1 += countString(s, mid+1, end, (char) (c+1), size>>1);
        long ans2 = 0;
        ans2 += size-Math.max(prefix[end]-prefix[mid], 0);
        ans2 += countString(s, start, mid, (char) (c+1), size>>1);
        long ans = Math.min(ans1, ans2);
        dp.put(key, ans);
        return ans;
    }

    void solve() throws IOException {
        int ts = getInt();
        for (int t = 1; t <= ts; t++){
            dp.clear();
            int n = getInt();
            String s = getLine();
            superPrefix = new int[26][s.length()];
            for (int i = 0; i < s.length(); i++) {
                char c = s.charAt(i);
                for (char j='a'; j<='z'; j++) {
                    int count = 0;
                    if(i!=0) count = superPrefix[j-'a'][i-1];
                    if(j==c) count++;
                    superPrefix[j-'a'][i] = count;
                }
            }
            long ans = countString(s, 0, s.length()-1, 'a', n/2);
            println(ans);
        }
    }

    public static void main(String[] args) throws Exception {
        if (isOnlineJudge()) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new BufferedWriter(new OutputStreamWriter(System.out));
            new AGoodStrings().solve();
            out.flush();
        } else {
            Thread judge = new Thread();
            in = new BufferedReader(new FileReader("input.txt"));
            out = new BufferedWriter(new FileWriter("output.txt"));
            judge.start();
            new AGoodStrings().solve();
            out.flush();
            judge.suspend();
        }
    }
    static boolean isOnlineJudge(){
        try {
            return System.getProperty("ONLINE_JUDGE")!=null
                    || System.getProperty("LOCAL")==null;
        }catch (Exception e){
            return true;
        }
    }
    // Fast Input & Output
    static BufferedReader in;
    static StringTokenizer st;
    static BufferedWriter out;
    static String getLine() throws IOException{
        return in.readLine();
    }
    static String getToken() throws IOException{
        if(st==null || !st.hasMoreTokens())
            st = new StringTokenizer(getLine());
        return st.nextToken();
    }
    static int getInt() throws IOException {
        return Integer.parseInt(getToken());
    }
    static long getLong() throws IOException {
        return Long.parseLong(getToken());
    }
    static void print(Object s) throws IOException{
        out.write(String.valueOf(s));
    }
    static void println(Object s) throws IOException{
        out.write(String.valueOf(s));
        out.newLine();
    }
}