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

public class Main {
    private static Map<Integer, Integer> index = new HashMap<>();
    private static int[][][] dp;

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int t = in.nextInt();
        int id = 0;
        for (int i = 1; i <= 131072; i *= 2) {
            index.put(i, id++);
        }
//        dp = new int[18][29][131073];
        while (t-- > 0) {
            int n = in.nextInt();

            char[] c = in.next().toCharArray();
            int ans = calc(c, 0, n - 1, 'a');
            out.println(ans);
        }
        out.close();
    }

    private static int calc(char[] c, int l, int r, char a) {
        if (l > r) {
            return 0;
        }

        if (l == r) {
            if (c[l] != a) {
                return 1;
            }
            return 0;
        }

        int mid = (l + r) / 2;
        int cnt = 0;
        for (int i = l; i <= mid; i++) {
            if (c[i] != a) {
                cnt++;
            }
        }
        int f = cnt + calc(c, mid + 1, r, (char) (a + 1));

        int cnt1 = 0;
        for (int i = mid + 1; i <= r; i++) {
            if (c[i] != a) {
                cnt1++;
            }
        }
        int f2 = cnt1 + calc(c, l, mid, (char) (a + 1));
        return Math.min(f, f2);
    }

    private  static void swap(int i, int k, char[] c) {
        int i1 = i;
        int j1 = i + k;
        for (int j = 0; j < k; j++) {
            char tmp = c[i1];
            c[i1] = c[j1];
            c[j1] = tmp;
            i1++;
            j1++;
        }
    }

    // k = 1, 2, 4, 8, 16
    private static boolean compare(int i, int k, char[] c) {
        int i1 = i;
        int j1 = i + k;
        for (int j = 0; j < k; j++) {
            if (c[i1] < c[j1]) {
                return true;
            } else if (c[i1] > c[j1]) {
                return false;
            }            if (c[i1] < c[j1]) {
                return true;
            } else if (c[i1] > c[j1]) {
                return false;
            }
            i1++;
            j1++;
        }
        return true;
    }

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner(InputStream io) {
            br = new BufferedReader(new InputStreamReader(io));
        }

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

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