from math import ceil

def main(n, s):
    alpha = 97
    moves = 0
    while True:
        print(s)
        pos = 0
        leftCount = s[:n//2].count(chr(alpha))
        rightCount = s[n//2:].count(chr(alpha))
        if leftCount >= rightCount:
            pos = -1
        else: pos = 1
        if pos == -1:
            moves += (n//2) - leftCount
            s = s[n//2:]
        elif pos == 1:
            moves += (n//2) - rightCount
            s = s[:n//2]
        alpha += 1
        n = n//2
        if len(s) == 1:
            if chr(alpha) != s: moves +=1
            break
        
    return moves
        


for _ in range(int(input())):
    n = int(input())
    s = input()
    print(main(n, s))
