t = int(input())
cnt = 0
while (cnt < t):
    cnt += 1
    n = int(input())
    s = input()
    dp = [0] * n
    tmp = n
    deg = 0
    while (tmp != 1):
        tmp //= 2
        deg += 1
    p = deg
    for i in range(n):
        if s[i] == str(chr(97 + deg)):
            dp[i] = 0
        else:
            dp[i] = 1
    while (n > 1):
        n //= 2
        deg -= 1
        tmp = 2 ** (p - deg - 1)
        for i in range(n):
            dp[i] = min(dp[2 * i] + tmp - s[2 * tmp * i + tmp:2 * tmp * i + 2 * tmp].count(chr(97 + deg)), 
                        dp[2 * i + 1] + tmp - s[2 * tmp * i:2 * tmp * i + tmp].count(chr(97 + deg)))
    print(dp[0])
            
    
