import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n = mint()
	s = [ord(i)-ord('a') for i in minp()]
	for k in range(100):
		if 2**k == n:
			break
	p = [[0]*n for i in range(26)]
	for i in range(n):
		for j in range(s[i]):
			p[j][i] += 1
		for j in range(s[i]+1, 26):
			p[j][i] += 1
	for i in range(26):
		p[i].insert(0,0)
		for j in range(1, n+1):
			p[i][j] += p[i][j-1]

	dp = [[0]*(n//(2**i)) for i in range(k+1)]
	for i in range(n):
		dp[0][i] = int(s[i] != k)
	#print(dp[0])
	for i in range(1,k+1):
		z = (2**(i-1))
		zz = 2*z
		pp = p[k-i]
		for j in range(n//zz):
			dp[i][j] = min(pp[j*zz+z] - pp[j*zz] + dp[i-1][2*j+1], \
							pp[j*zz+zz] - pp[j*zz+z] + dp[i-1][2*j])
		#print([pp[j+1]-pp[j] for j in range(n)])
		#print(dp[i])
	print(dp[k][0])

for i in range(mint()):
	solve()
