from math import log2

def g(s,pos,length):
	c = chr(int(log2(len(s)/(length))) + ord('a')-1)
	out = 0
	for i in range(pos,pos+length):
		if s[i] != c:
			out += 1
	return out

def f(s,pos,length):
	c =  chr(int(log2(len(s)/(length))) + ord('a')-1)
	if length == 1:
		return 0 if s[0] == 'a' else 1 
	elif length == 2:
		c = chr(ord(c)+1)
		c2 = chr(ord(c)+1)
		out = 2
		if s[pos] == c or s[pos+1] == c:
			out -= 1
		if s[pos] == c2 or s[pos+1] == c2:
			out -= 1
		return out
	else:
		out = min(g(s,pos,length//2) + f(s,pos+length//2,length//2),
			f(s,pos, length//2) + g(s,pos+length//2,length//2))
		return out

t = int(input())

for _ in range(t):
	n = int(input())
	s = input()
	print(f(s,0,n))

