def solve(s,low,high,character):
    if(low==high):
        if(s[low]!=character):
            return 1
        else:
            return 0
    mid=(low+high)//2
    temp1,temp2=0,0
    for i in range(low,mid+1):
        temp1+=(s[i]!=character)
    for i in range(mid+1,high+1):
        temp2+=(s[i]!=character)
    temp1+=solve(s,mid+1,high,character+1)
    temp2+=solve(s,low,mid,character+1)
    return min(temp1,temp2)


t=int(input())
for s in range(t):
    n=int(input())
    b=input()
    s=[ord(b[i]) for i in range(n)]
    print(solve(s,0,n-1,97))