def solve(s, l, r, c):
	if l == r:
		return 0 if s[l] == c else 1
	mid = (r + l) // 2
	l_moves = 0
	for i in range(l, mid+1):
		if s[i] != c:
			l_moves += 1
	l_moves += solve(s, mid+1, r, chr(ord(c)+1))
	r_moves = 0
	for i in range(mid+1, r+1):
		if s[i] != c:
			r_moves += 1
	r_moves += solve(s, l, mid, chr(ord(c)+1))
	return min(l_moves, r_moves)

t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	print(solve(s, 0, n - 1, 'a'))