def res(x,b,l,r):
    s = chr(x)
    if l==r:

        if b[l]==s:
            return 0
        else:
            return 1


    else:
        m = (l + r) // 2

        if b[l] == s:
            k1 = (a[x-97][m] - a[x-97][l] + 1)
        else:
            k1 = (a[x-97][m] - a[x-97][l])
        if b[m + 1] == s:
            k2 = (a[x-97][r]-a[x-97][m + 1] + 1)
        else:
            k2 = (a[x-97][r]-a[x-97][m + 1])

        return min((m + 1-l - k1 + res(x + 1, b, m + 1, r)), (m + 1-l - k2 + res(x + 1, b, l, m)))




t=int(input())
for i in range(t):
    n=int(input())
    b=[]
    s=input()
    a=[[0]*(n) for j in range(26)]
    for j in s:
        b.append(j)
    for j in range(n):
        q=ord(b[j])-97
        for p in range(26):
            if p==q:
                if j!=0:
                    a[p][j]=a[p][j-1]+1
                else:
                    a[p][j]=1
            else:
                if j!=0:
                    a[p][j]=a[p][j-1]
    print(res(97,b,0,n-1))













