import sys
input = sys.stdin.readline
def f(s,n):
	if len(s) == 1:
		if s[0] != n: return 1
		else: return 0
	a = 0
	for i in range(len(s)//2):
		if s[i] != n: a +=1
	b = 0 
	for i in range(len(s)//2):
		if s[len(s)-1-i] != n: b +=1
	return min(a+f(s[len(s)//2:],n+1), b+f(s[:len(s)//2],n+1))

def main():
	for t in range(int(input())):
		n = int(input())
		s = list(input())[:n]
		for i in range(len(s)): s[i] = ord(s[i])-ord('a')
		print(f(s,0))
main()
