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

// abbaaabb
public class codeforces656_D {
    private static void solve(FastIOAdapter ioAdapter) {
        var n = ioAdapter.nextInt();
        char[] s = ioAdapter.next().toCharArray();

        char cur = 'a';
        int halfLength = n / 2;
        int start = 0;
        int end = n;
        int res = 0;
        while (halfLength > 0) {
            int countCurLeft = 0;
            int countCurRight = 0;
            for (int i = start; i < end; i++) {
                if (s[i] == cur) {
                    if (i - start < halfLength) {
                        countCurLeft++;
                    } else {
                        countCurRight++;
                    }
                }
            }

            if (countCurLeft > countCurRight) {
                start = start + halfLength;
                res += halfLength - countCurLeft;
            } else if (countCurLeft < countCurRight) {
                end = end - halfLength;
                res += halfLength - countCurRight;
            } else if (halfLength > 1) {
                int halfhalf = halfLength / 2;
                char next = (char) (cur + 1);
                int countNextLeft = 0;
                int countNextRight = 0;
                int max1 = 0;
                for (int i = start; i < halfLength; i++) {
                    if (s[i] == next) {
                        if (i - start < halfhalf) {
                            countNextLeft++;
                        } else {
                            countNextRight++;
                        }
                    }
                }
                max1 = Math.max(countNextLeft, countNextRight);

                countNextLeft = 0;
                countNextRight = 0;
                for (int i = halfLength; i < end; i++) {
                    if (s[i] == next) {
                        if (i - halfLength < halfhalf) {
                            countNextLeft++;
                        } else {
                            countNextRight++;
                        }
                    }
                }
                int max2 = Math.max(countNextLeft, countNextRight);
                if (max1 > max2) {
                    end = end - halfLength;
                    res += halfLength - countCurRight;
                } else {
                    start = start + halfLength;
                    res += halfLength - countCurLeft;
                }
            } else {
                end -= halfLength;
                res += halfLength - countCurRight;
            }

            cur++;
            halfLength /= 2;
        }
        ioAdapter.out.println(s[start] == cur ? res : res + 1);
    }

    public static void main(String[] args) throws Exception {
        try (FastIOAdapter ioAdapter = new FastIOAdapter()) {
            int count = 1;
            count = ioAdapter.nextInt();
            while (count-- > 0) {
                solve(ioAdapter);
            }
        }
    }

    static void shuffleSort(int[] arr) {
        int n = arr.length;
        Random rnd = new Random();
        for (int i = 0; i < n; ++i) {
            int tmp = arr[i];
            int randomPos = i + rnd.nextInt(n - i);
            arr[i] = arr[randomPos];
            arr[randomPos] = tmp;
        }
        Arrays.sort(arr);
    }

    static class FastIOAdapter implements AutoCloseable {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        public PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter((System.out))));
        StringTokenizer st = new StringTokenizer("");

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

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

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

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

        @Override
        public void close() throws Exception {
            out.flush();
            out.close();
            br.close();
        }
    }
}