def rec(arr,mapp,l,r,c):
    if (l==r):
        if (arr[l]==chr(ord("a")+c)):
            return 0
        return 1
    if ((l,r) in mapp):
        return mapp[(l,r)]
    A = (l+r)//2
    count1 = 0
    for i in range(l,A+1):
        if (arr[i]!=chr(ord("a")+c)):
            count1 += 1
    count2 = 0
    for i in range(A+1,r+1):
        if (arr[i]!=chr(ord("a")+c)):
            count2 += 1
    # print(l,r,count1,count2)
    A = min(rec(arr,mapp,l,A,c+1)+count2,rec(arr,mapp,A+1,r,c+1)+count1)
    mapp[(l,r)] = A
    return A
T = int(input())
for _ in range(T):
    n = int(input())
    Str = input()
    mapp = {}
    print(rec(Str,mapp,0,n-1,0))