from collections import deque

t = int(input())

for _ in range(t):
    ans = 9999999
    n = int(input())
    st = input()
    stck = deque()
    stck.append([0,n,0,0])
    while len(stck):
        l,r,c,s = stck.pop()
        s1,s2 = 0,0
        if r-l==1:
            ans = min(ans,s+(1-int(st[l]==chr(97+c))))
            continue
        for i in range(l,(l+r)//2):
            if st[i]!=chr(97+c):
                s1+=1
        for i in range((l+r)//2,r):
            if st[i]!=chr(97+c):
                s2+=1
        stck.append([(l+r)//2,r,c+1,s1+s])
        stck.append([l,(l+r)//2,c+1,s2+s])
    print(ans)