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

public class Problem_D {
	static final int INF = Integer.MAX_VALUE / 2;

	public static void main(String[] args) {
		InputReader in = new InputReader();
		StringBuilder out = new StringBuilder();

		int T = in.nextInt();
		while (T-- > 0) {
			int N = in.nextInt();
			char[] S = in.nextLine().toCharArray();
			int len = 0;
			for (int i = N; i > 0; i /= 2, len++)
				;
			int[][][] dp = new int[len][][];
			dp[0] = new int[N][26];
			for (int i = 1; i < len; i++) {
				dp[i] = new int[dp[i - 1].length / 2][26];
			}
			for (int i = 0; i < len; i++) {
				for (int j = 0; j < dp[i].length; j++) {
					Arrays.fill(dp[i][j], INF);
				}
			}
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < 26; j++) {
					dp[0][i][j] = S[i] - 97 == j ? 0 : 1;
				}
			}
			int[][] psum = new int[N + 1][26];
			for (int i = 1; i <= N; i++) {
				for (int j = 0; j < 26; j++) {
					psum[i][j] = psum[i - 1][j] + 1;
				}
				psum[i][S[i - 1] - 97]--;
			}
			for (int i = 1; i < len; i++) {
				for (int j = 0; j < dp[i].length; j++) {
					for (int k = 0; k < 25; k++) {
						dp[i][j][k] = Math.min(
								psum[(1 << (i - 1)) + (j << i)][k] - psum[j << i][k] + dp[i - 1][2 * j + 1][k + 1],
								psum[(1 + j) << i][k] - psum[(1 << (i - 1)) + (j << i)][k] + dp[i - 1][2 * j][k + 1]);
					}
				}
			}
			out.append(dp[len - 1][0][0]).append('\n');
		}

		System.out.print(out);
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer st;

		public InputReader() {
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

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

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return null;
		}

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