from sys import stdin
input = lambda: stdin.readline().rstrip("\r\n")
from collections import deque as que, defaultdict as vector
from heapq import*
inin = lambda: int(input())
inar = lambda: list(map(int,input().split()))
from math import log2
def solve(c,st):
	cnt=0
	for i in st:
		if i!=c:
			cnt+=1
	return cnt
alp='abcdefghijklmnopqrstuvwxyz'
Testcase=inin()
for i in range(Testcase):
	n=inin()
	s=input()
	sc=s
	k=int(log2(n)+1)
	copy=k
	#print(k)
	ans=0
	while(k):
		c=alp[copy-k]
		k-=1
		#print(c)
		n=len(s)
		if len(s)==1:
			ans+= solve(c,s)
			break
		
		l=solve(c,s[0:2**(k-1)])
		r=solve(c,s[2**(k-1):n])
		#print(s[0:2**(k-1)],s[2**(k-1):n])
		#print(l,r)
		if l<r:
			s=s[2**(k-1):n]
			ans+=l 
		else:
			s=s[0:2**(k-1)]
			#print(s[0:2**(k-1)])
			ans+=r 
	ans1=0
	k=copy 
	s=sc
	while(k):
		c=alp[copy-k]
		k-=1
		#print(c)
		n=len(s)
		if len(s)==1:
			ans1+= solve(c,s)
			break
		
		l=solve(c,s[0:2**(k-1)])
		r=solve(c,s[2**(k-1):n])
		#print(s[0:2**(k-1)],s[2**(k-1):n])
		#print(l,r)
		if l<=r:
			s=s[2**(k-1):n]
			ans1+=l 
		else:
			s=s[0:2**(k-1)]
			#print(s[0:2**(k-1)])
			ans1+=r
	print(min(ans,ans1))