import sys
input = lambda :sys.stdin.readline().rstrip()
v = lambda x:ord(x)-ord('a')
def f(l,r,ch):
    ct=0
    for i in range(l,r+1):
        if a[i]==ch:
            ct+=1
    return ct
for _ in range(int(input())):
    n = int(input())
    a = list(map(lambda x:v(x),input()))
    if n==1:
        print(0 if a==[0] else 1)
        continue
    l = n>>1
    ch = 0
    i,j=0,n-1
    ans = 0
    while l>1:
        ct=f(i,i+l-1,ch)
        ct1=f(j-l+1,j,ch)
        if ct>ct1:
            i+=l
            ans+=l-ct
        elif ct1>ct:
            j-=l
            ans+=l-ct1
        else:
            x=f(i,i+l-1,ch+1)
            y=f(j-l+1,j,ch+1)
            if x>y:
                j-=l
                ans+=l-ct1
            else:
                i+=l
                ans+=l-ct
        ch+=1
        l>>=1
    # print(i,j)
    v1 = f(i,i,ch)+f(j,j,ch)
    v2 = f(i,i,ch+1)+f(j,j,ch+1)
    if v1==0:
        ans+=1
    if v2==0:
        ans+=1
    print(ans)