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

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int t = in.nextInt();
        Main m = new Main();
        while (t-- > 0) {
            m.run(in, out);
        }
        out.close();
    }

    int N;
    // prefix sum of character occurrence
    int[][] P = new int[26][132_000];

    void run(FastScanner in, PrintWriter out) {
        N = in.nextInt();
        char[] ca = in.next().toCharArray();

        for (int i = 0; i < 26; i++) {
            for (int j = 0; j < N; j++) {
                P[i][j+1] = P[i][j];
                if ((char)('a'+i) == ca[j]) P[i][j+1]++;
            }
        }

        out.println(go(0, N, 0));
    }

    // returns min cost to make sequence [l,r) 'c'-good
    int go(int l, int r, int c) {
        if (l+1 == r) {
            return P[c][r] - P[c][l] == 1 ? 0 : 1;
        }

        int mid = (r+l)>>1;
        int len = (r-l)>>1;
        // ways to make seq 'c'-good

        // first half contains c, second half is 'c+1'-good
        int leftCCount = P[c][mid]-P[c][l];
        int case1Count = (len-leftCCount) + go(mid, r, c+1);

        // first half is 'c+1'-good, second half contains c
        int rightCCount = P[c][r]-P[c][mid];
        int case2Count = go(l, mid, c+1) + (len-rightCCount);
        return Math.min(case1Count, case2Count);
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}
