#Divide-and-conquer
import collections

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
        firstHalfCnts=collections.Counter(s[startIndex:(startIndex+endIndex+1)//2])
        firstHalfChange=(endIndex+1-startIndex)//2-firstHalfCnts[c]
        firstHalfMin=firstHalfChange+minMoves(chr(ord(c)+1),(startIndex+endIndex+1)//2,endIndex)
        #make second half all c
        secondHalfCnts=collections.Counter(s[(startIndex+endIndex+1)//2:endIndex+1])
        secondHalfChange=(endIndex+1-startIndex)//2-secondHalfCnts[c]
        secondHalfMin=secondHalfChange+minMoves(chr(ord(c)+1),startIndex,(startIndex+endIndex)//2)
#    print('str:{} c:{} firstHalfMin:{} secondHalfMin:{}'.format(s[startIndex:endIndex+1],c,firstHalfMin,secondHalfMin))
    return min(firstHalfMin,secondHalfMin)

t=int(input())
for _ in range(t):
    n=int(input())
    s=input()
    ans=minMoves('a',0,n-1)
    print(ans)