import sys
sys.setrecursionlimit(131073)
def solve(curcost,index1,index2,layer):
    pp=2
    if layer==len(cnt)-1:
        return curcost+min(cnt[layer][index1],cnt[layer][index2])
    else:
        if layer!=len(cnt)-2:
            return min(solve(curcost+cnt[layer][index1],(pp)*index2,pp*index2+1,layer+1),solve(curcost+cnt[layer][index2],pp*index1,pp*index1+1,layer+1))
        else:
            return min(solve(curcost+cnt[layer][index1],index2,index2,layer+1),solve(curcost+cnt[layer][index2],index1,index1,layer+1))

for _ in range(input()):
    n=input()
    s=raw_input()
    if n==1:
        if s=='a':
            print 0
            continue
        else:
            print 1
            continue
    cnt=[]
    kk=n
    u=1
    for i in range(26):
        u*=2
        yy=kk/u
        cur=chr(97+i)
        if yy==0:
            break
        uu=[]
        for j in range(u):
            tt=j*kk/u
            cn=0
            for k in range(tt,tt+yy):
                if s[k]!=cur:
                    cn+=1
            uu.append(cn)
        cnt.append(uu)
    yy=[]
    for i in s:
        if i!=cur:
            yy.append(1)
        else:
            yy.append(0)
    cnt.append(yy)

    print solve(0,0,1,0)
"""ceaaaabb"""

