from sys import stdin
                        
t = int(stdin.readline().strip())
for i in range(t):                           
    n = int(stdin.readline().strip())
    S = stdin.readline().strip()
    S = [ord(c) - ord('a') for c in S]
    k = 0
    while n > 1:
        k += 1
        n = n >> 1
    last = [0 if c == k else 1 for c in S]
    for i in range(k-1, -1, -1):
        block_length = int((1<<k) / len(last))
        next = []
        for j in range(len(last)):
            total = 0
            for l in range(block_length):
                if S[j*block_length + l] != i:
                    total += 1
            next.append(total)
        newlast = []
        for j in range(0, len(last), 2):
            newlast.append(min(last[j]+next[j+1], last[j+1]+next[j]))
        last = newlast
    print(last[0])




