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

public class D {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        task solver = new task();
        int T = in.nextInt();
        for (int t = 1; t <= T; t++) solver.solve(in, out);
        out.close();
    }

    static class task {
        int[][] pre;
        String s;

        int F(int l, int r, char cur){
            if (l == r){
                return s.charAt(l - 1) == cur ? 0 : 1;
            }
            int x = 0; int y = 0;
            int m = (l + r) / 2;
            for (int i = l; i <= r; i++){
                if (i <= m) x += (s.charAt(i - 1) != cur ? 1 : 0);
                else y += (s.charAt(i - 1) != cur ? 1 : 0);
            }
            return Math.min(F(l, m, (char)(cur + 1))  + y, F(m + 1, r, (char)(cur + 1)) + x);
        }

        public void solve(InputReader in, PrintWriter out) {
            int n = in.nextInt();
            s = in.next();
            out.println(F(1, n, 'a'));
        }
    }

    static class InputReader {
        public BufferedReader br;
        public StringTokenizer st;

        public InputReader(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s), 32768);
        }

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

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

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