from sys import setrecursionlimit,stdout,stdin

setrecursionlimit(100000)


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


for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	s = stdin.readline()
	print(solve(0, n - 1, 'a'))
