def make (st , last , type) :
    if st==last :
        return 0 if s[st]==alpha[type] else 1
    mid=(st+last)//2
    lcost=0
    rcost=make(mid+1 , last, type+1)
    for i in range (st,mid+1) :
        if s[i]!=alpha[type] :
            lcost+=1
    ans=lcost+rcost
    rcost = 0
    lcost = make(st, mid, type + 1)
    for i in range(mid+1, last + 1):
        if s[i] != alpha[type]:
            rcost += 1
    return min(ans, lcost+rcost)

alpha='abcdefghijklmnopqrstuvwxyz'
for _ in range(int(input())) :
    n=int(input())
    s=input().strip()
    print(make(0 , n-1 , 0))