import sys
# sys.setrecursionlimit(10**6) 
input=sys.stdin.readline
t=int(input())
def func(arr,ind,start,end,ans,l):
    check=ind+97
    n=(end-start+1)
    if(n==1):
        if(ord(arr[start])!=check):
            return ans+1
        return ans
    else:
        n=n//2
        # print(arr[start:end+1])
        if(start==0):
            extra1=n-(l[start+n-1].get(chr(check),0))
        else:
            # print(start-1,start+n-1)
            extra1=n+(l[start-1].get(chr(check),0))-(l[start+n-1].get(chr(check),0))
        extra2=n+(l[end-n].get(chr(check),0))-(l[end].get(chr(check),0))
        # print(ans+extra1,ans+extra2,start,end)
        return min(func(arr,ind+1,start+n,end,ans+extra1,l),func(arr,ind+1,start,end-n,ans+extra2,l))

    

for t1 in range(t):
    n=int(input())
    s=input()
    s=s.strip()
    l=[]
    d={}
    d[s[0]]=1
    l.append(d)

    for i in range(1,n):
        t={}
        d=l[-1]
        for j in d:
            t[j]=d[j]
        t[s[i]]=t.get(s[i],0)+1
        l.append(t)
    # print(l)
    print(func(s,0,0,n-1,0,l))
    
        
