import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int ntests = in.nextInt();
            for (int itest = 0; itest < ntests; itest++) {
                int len = in.nextInt();
                char[] s = in.nextLine().toCharArray();
                int ans = rec(s, 0, s.length - 1, 'a');
                out.println(ans);
            }
        }

        private int rec(char[] s, int le, int ri, char c) {
            if (le == ri) {
                return s[le] == c ? 0 : 1;
            }

            int mid = le + (ri - le) / 2;
            //1
            int ans1 = 0;
            for (int i = le; i <= mid; i++) {
                if (s[i] != c) {
                    ans1++;
                }
            }
            ans1 += rec(s, mid + 1, ri, (char) (c + 1));

            //2
            int ans2 = 0;
            for (int i = mid + 1; i <= ri; i++) {
                if (s[i] != c) {
                    ans2++;
                }
            }
            ans2 += rec(s, le, mid, (char) (c + 1));

            return Math.min(ans1, ans2);
        }

    }

    static class InputReader {
        final InputStream is;
        final byte[] buffer = new byte[1024];
        int curCharIdx;
        int nChars;

        public InputReader(InputStream is) {
            this.is = is;
        }

        public int read() {
            if (curCharIdx >= nChars) {
                try {
                    curCharIdx = 0;
                    nChars = is.read(buffer);
                    if (nChars == -1) {
                        return -1;
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return buffer[curCharIdx++];
        }

        public int nextInt() {
            int sign = 1;
            int c = skipDelims();
            if (c == '-') {
                sign = -1;
                c = read();
                if (isDelim(c)) {
                    throw new RuntimeException("Incorrect format");
                }
            }
            int val = 0;
            while (c != -1 && !isDelim(c)) {
                if (!isDigit(c)) {
                    throw new RuntimeException("Incorrect format");
                }
                val = 10 * val + (c - '0');
                c = read();
            }
            return val * sign;
        }

        public String nextLine() {
            return nextLine(16);
        }

        public String nextLine(int size) {
            int c = read();
            while (c == '\n' || c == '\t' || c == '\r') {
                c = read();
            }
            if (c == -1) {
                return null;
            }
            StringBuilder sb = new StringBuilder(size);
            while (c != -1 && c != '\n' && c != '\t' && c != '\r') {
                sb.appendCodePoint(c);
                c = read();
            }
            return sb.toString();
        }

        private final int skipDelims() {
            int c = read();
            while (isDelim(c)) {
                c = read();
            }
            return c;
        }

        private static boolean isDelim(final int c) {
            return c == ' ' ||
                   c == '\n' ||
                   c == '\t' ||
                   c == '\r' ||
                   c == '\f';
        }

        private static boolean isDigit(final int c) {
            return '0' <= c && c <= '9';
        }

    }
}

