def pre(s):
    dp = []
    letters = [0]*26
    dp.append(letters)
    for i in s:
        letters = dp[-1][:]
        letters[ord(i)-ord('a')] += 1
        dp.append(letters)

    return dp

def solve(s,n,ans):
    dp = pre(s)
    moves = {}
    stack = [(1,n,0)]
    while stack:
        curr = stack[-1]
        l,r,index = curr
        terms = r-l+1
        if l == r:
            total = int(not (ord(s[l-1])-ord('a') == index))
            #print(total,'here')
            moves[(l,r,index)] = total
            stack.pop()
            continue
        left = l+(terms//2)-1
        right = left+1
        count = 0
        if (l,left,index+1) in moves.keys():
            count += 1
        else:
            stack.append((l,left,index+1))

        if (right,r,index+1) in moves.keys():
            count += 1
        else:
            stack.append((right,r,index+1))

        if count == 2:
            total = (terms//2)-(dp[left][index]-dp[l-1][index])+moves[(right,r,index+1)]
            total = min(total,moves[(l,left,index+1)]+(terms//2)-(dp[r][index]-dp[right-1][index]))
            moves[(l,r,index)] = total
            stack.pop()

    ans.append(moves[(1,n,0)])

def main():
    t = int(input())
    ans = []
    for i in range(t):
        n = int(input())
        s = input()
        solve(s,n,ans)

    for i in ans:
        print(i)
        
main()
