def make_good(instr,ind1,ind2,inchar):
	if ind1==ind2:
		if instr[ind1]==inchar:
			return 0
		else:
			return 1
	
	mid=(ind1+ind2)//2
	nextchar=chr(ord(inchar)+1)
	c1=make_good(instr,ind1,mid,nextchar) + make_all_char_same(instr,mid+1,ind2,inchar)
	c2=make_all_char_same(instr,ind1,mid,inchar) + make_good(instr,mid+1,ind2,nextchar)
	return min(c1,c2)
	

def make_all_char_same(instr,ind1,ind2,inchar):
	count=0
	for i in range(ind1,ind2+1):
		if instr[i]!=inchar:
			count+=1
	return count

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