from sys import stdin, stdout
import math

def main():
    t = int(stdin.readline())
    for _ in range (t):
        n= int(stdin.readline())
        st = stdin.readline().rstrip()
        p = int(math.log2(n))
        alp = ord('a')
        total_dp = [0] * n
        for char_int in range(alp+p,alp-1,-1):
            pp = int(pow(2,alp+p-char_int))
            half_pp = int(pp/2)
            char = chr(char_int)
            cnt = 0
            dp = [0] * n
            for i,s in enumerate(st):
                if s == char:
                    cnt += 1
                if pp == 1:
                    total_dp[i] = 1 - cnt
                    cnt = 0
                    continue
                if (i+1) % half_pp == 0:
                    dp[i] = half_pp - cnt
                    cnt = 0
                if (i+1) % pp == 0:
                    #print(char, pp, dp, total_dp)
                    total_dp[i] = min(total_dp[i] + dp[i-half_pp], total_dp[i-half_pp] + dp[i])
            #print (total_dp)
        stdout.write(str(total_dp[n-1]) + "\n")

main()