import math
import sys
input=sys.stdin.readline
t=int(input())
#t=1
def solve(s,l,r,c):
    ans1,ans2=0,0
    mid=(l+r)//2
    #print(l,r,s[l:r+1],c)

    
    c1=chr(ord(c)+1)
    if len(s[l:r+1])==1:
            if s[l]==c:
                return 0
                
            return 1
    elif len(s[l:r+1])>1:
        
        for i in range(l,mid+1):
            if s[i]!=c:
                ans1+=1
        
        for i in range(mid+1,r+1):
            if s[i]!=c:
                ans2+=1
                
        ans1+=solve(s,mid+1,r,c1)
        
        ans2+=solve(s,l,mid,c1)
        #print(l,r,min(ans1,ans2))
        
        return (min(ans1,ans2))    
    
for _ in range(t):
    n=int(input())
    #n,m=map(int,input().split())
    s=input()
    print(solve(s,0,n-1,'a'))
    #l=list(map(int,input().split()))
    