def find_cost(arr,a,b,l):
    le = alpha[l]
    if (b-a)==1:
        return int(arr[a]!=le)
    cost1=0
    cost2=0
    mid = (a+b)//2
    for i in range(a,mid):
        if arr[i]!=le:
            cost1+=1
    for i in range(mid,b):
        if arr[i]!=le:
            cost2+=1
    return min(cost1+find_cost(arr,mid,b,l+1),
                cost2+find_cost(arr,a,mid,l+1))

alpha = list('abcdefghijklmnopqrstuvwxyz')
def main():
    for _ in range(int(input())):
        n = int(input())
        arr = input().strip()
        cost = find_cost(arr,0,n,0)
        print(cost)

main()