import sys

sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def cost(l,r,x):
    if r-l==1:return (aa[l]!=x)*1
    if (l,r,x) in memo:return memo[l,r,x]
    m=(l+r)//2
    ret1=m-l-(cs[x][m]-cs[x][l])+cost(m,r,x+1)
    ret2=r-m-(cs[x][r]-cs[x][m])+cost(l,m,x+1)
    memo[l,r,x]=res=min(ret1,ret2)
    return res

for _ in range(II()):
    memo = {}
    n=II()
    aa=[ord(c)-97 for c in SI()]
    cs=[[0]*(n+1) for _ in range(26)]
    for i,a in enumerate(aa):cs[a][i+1]=1
    for i in range(26):
        csi=cs[i]
        for j in range(n):
            csi[j+1]+=csi[j]
    print(cost(0,n,0))
