def cost(L,R,i,PST):
	return (R-(L-1))-(PST[i][R]-PST[i][L-1])
def solve(L,R,i,PST,s):
	if L==R:
		return 0 if s[L]==i else 1
	else:
		M = (L+R)//2
		return min(cost(L,M,i,PST)+solve(M+1,R,i+1,PST,s),solve(L,M,i+1,PST,s)+cost(M+1,R,i,PST))
for t in range(int(input())):
	n = int(input())
	s = [27]+[ord(d)-ord('a') for d in input()]
	PST = [[0 for i in range(n+1)] for j in range(26)]
	for c in range(26):
		for i in range(1,n+1):
			PST[c][i] = PST[c][i-1] + (1 if s[i]==c else 0)

	print(solve(1,n,0,PST,s))
