def solve(s,x,size,ans):
    if size==1: 
        if s[0]!=x:
            ans[0] += 1
        return
    l = s[:size//2].count(x)
    r = s[size//2:].count(x)
    if l>r:
        ans[0] += size//2-l
        x = chr(ord(x)+1)
        solve(s[size//2:],x,size//2,ans)
    elif l<r:
        ans[0] += size//2-r
        x = chr(ord(x)+1)
        solve(s[:size//2],x,size//2,ans)
    else:
        ll = s[:size//2].count(chr(ord(x)+1))
        rr = s[size//2:].count(chr(ord(x)+1)) 
        if ll>rr:
            ans[0] += size//2-r
            x = chr(ord(x)+1)
            solve(s[:size//2],x,size//2,ans)
        else:
            ans[0] += size//2-l
            x = chr(ord(x)+1)
            solve(s[size//2:],x,size//2,ans)

for _ in range(int(input())):
    n = int(input())
    s = input()
    ans = [0]
    solve(s,"a",n,ans)
    print(ans[0])

        
