import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class code {
	public static void main(String[] args)throws IOException {
		FastReader sc = new FastReader();
		PrintWriter pw = new PrintWriter(System.out);

		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt();
			String s = sc.next();
			char arr[] = new char[n + 1];
			for (int i = 1; i <= n; i++)
				arr[i] = s.charAt(i - 1);
			int ans = getMin(arr, 1, n, 'a');
			System.out.println(ans);

		}
	}
	public static int getMin(char str[], int l, int r, char ch) {
		if (l == r) {
			if (str[l] == ch)
				return 0;
			return 1;
		}
		int mid = (l + r) / 2;
		int cost1 = getCost(str, l, mid, ch);
		int cost2 = getCost(str, mid + 1, r, ch);
		return Math.min(cost1 + getMin(str, mid + 1, r, (char)((int)ch + 1)), cost2 + getMin(str, l, mid, (char)((int)(ch + 1))));
	}
	public static int getCost(char str[], int l, int r, char ch) {
		int count = 0;
		for (int i = l; i <= r; i++) {
			char c = str[i];
			if (c != ch)
				count++;
		}
		return count;
	}
}





class FastReader {
	BufferedReader br;
	StringTokenizer st;

	public FastReader() {
		br = new BufferedReader(new
		                        InputStreamReader(System.in));
	}

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

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

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

	double nextDouble() {
		return Double.parseDouble(next());
	}

	String nextLine() {
		String str = "";
		try {
			str = br.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return str;
	}
}