def findans(s,beg,end,ans,i,cv,fa):
    #print(beg,end,ans)
    if (beg==end):
        if (ord(s[beg-1])-97!=i):
            ans=ans+1
        fa[0]=min(fa[0],ans)
        return

    mid=(beg+end)//2
    
    findans(s,mid+1,end,ans+cv[i][mid]-cv[i][beg-1],i+1,cv,fa)
    findans(s,beg,mid,ans+cv[i][end]-cv[i][mid],i+1,cv,fa)
    return

T=int(input())
for _ in range(T):
    n=int(input())
    s=input()
    ans=0
    cv=[[0 for j in range(n+1)] for i in range(26)]
    
    A=[n//(2**(i+1)) for i in range(26)]
    for i in range(n):
        for j in range(26):
            if (A[j]==0):
                break

            else:
                if (ord(s[i])-97!=j):
                    cv[j][i+1]=1
    
    for i in range(26):
        for j in range(1,n+1):
            cv[i][j]=cv[i][j-1]+cv[i][j]
            
    #print(cv)
    fa=[n]
    findans(s,1,n,ans,0,cv,fa)
    print(fa[0])
            
            
    
