#Divide-and-conquer
 
def minMoves(c,startIndex,endIndex): #indexes are inclusive
    if startIndex==endIndex: #1 char long
        if s[startIndex]==c:
            return 0
        else:
            return 1
    else: #more than 1 char long
        #make first half all c
        firstHalfChange=(endIndex+1-startIndex)//2
        for i in range(startIndex,(startIndex+endIndex+1)//2):
            if s[i]==c:firstHalfChange-=1
        firstHalfMin=firstHalfChange+minMoves(chr(ord(c)+1),(startIndex+endIndex+1)//2,endIndex)
        #make second half all c
        secondHalfChange=(endIndex+1-startIndex)//2
        for i in range((startIndex+endIndex+1)//2,endIndex+1):
            if s[i]==c:secondHalfChange-=1
        secondHalfMin=secondHalfChange+minMoves(chr(ord(c)+1),startIndex,(startIndex+endIndex)//2)
    return min(firstHalfMin,secondHalfMin)
 
t=int(input())
for _ in range(t):
    n=int(input())
    s=input()
    ans=minMoves('a',0,n-1)
    print(ans)