import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Learning {
    public static void main(String[] args) throws Exception {
        FastInput in = new FastInput();
        int t = in.nextInt();
        StringBuilder st = new StringBuilder();
        while (t-- > 0) {
            int n = in.nextInt();
            String s = in.next();
            HashMap<String, Integer> map = new HashMap<>();
            int ans = getMin(s, n, 'a', map);
            st.append(ans).append("\n");
        }
        System.out.print(st.toString());

    }

    private static int getMin(String s, int n, char a, HashMap<String, Integer> map) {
        if (n == 1) {
            return s.charAt(0) == a ? 0 : 1;
        }
        int con1 = 0;
        int con2 = 0;
        String s1 = s.substring(0, n / 2);
        String s2 = s.substring(n / 2);
        for (char c : s1.toCharArray()) {
            if (c != a) con1++;
        }
        for (char c : s2.toCharArray()) {
            if (c != a) con2++;
        }
        int val1 = con1 + getMin(s2, n / 2, (char) (a + 1), map);
        int val2 = con2 + getMin(s1, n / 2, (char) (a + 1), map);

        int val = Math.min(val1, val2);
        map.put(s + " " + a, val);
        return val;

    }
}

class FastInput {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;

    String next() throws IOException {
        if (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    Integer nextInt() throws IOException {
        return Integer.parseInt(next());
    }
}
