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

public class D {

	static long m = (long) (1e9 + 7);

	public static void main(String[] args) throws IOException {
		Scanner scn = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int T = scn.nextInt(), tcs = 0;
		D: while (tcs++ < T) {
			int n = scn.nextInt();
			String s = scn.next();
			System.out.println(fn(s, 0, n - 1, 'a'));
			sb.append("\n");
		}
		System.out.print(sb);
	}

	public static int fn(String s, int id, int n, char c) {
		if (id >= n) {
			return s.charAt(id) == c ? 0 : 1;
		}
		int c1 = 0, c2 = 0;
		int mi = (id + n) / 2;
		for (int i = id; i <= mi; i++)
			if (s.charAt(i) != c)
				c1++;
		for (int i = mi + 1; i <= n; i++)
			if (s.charAt(i) != c)
				c2++;
		return Math.min(c1 + fn(s, mi + 1, n, (char) (c + 1)), c2 + fn(s, id, mi, (char) (c + 1)));
	}

	static class Scanner {

		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

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

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

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