t=int(input())
def func(a,b,c):
	if a==b:
		return int(s[a]!=c)
	v=(b-a+1)//2
	v1=0
	for i in range(v):
		if s[a+i]!=c:
			v1+=1
	v2=0
	for i in range(v):
		if s[b-i]!=c:
			v2+=1
	return min(v1+func(a+v,b,chr(ord(c)+1)),v2+func(a,b-v,chr(ord(c)+1)))

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