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

public class CF1385D extends PrintWriter {
	CF1385D() { super(System.out); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1385D o = new CF1385D(); o.main(); o.flush();
	}

	byte[] cc;
	int solve(int l, int r, byte c) {
		if (r - l == 1)
			return cc[l] == c ? 0 : 1;
		int m = (l + r) / 2;
		int kl = 0, kr = 0;
		for (int i = l; i < m; i++)
			if (cc[i] != c)
				kl++;
		for (int i = m; i < r; i++)
			if (cc[i] != c)
				kr++;
		c++;
		return Math.min(solve(l, m, c) + kr, kl + solve(m, r, c));
	}
	void main() {
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt();
			cc = sc.next().getBytes();
			println(solve(0, n, (byte) 'a'));
		}
	}
}
