from math import *


def delta(s, left, right, ch):
    dif = 0
    for ind in range(left, right + 1):
        if s[ind] != ch:
            dif += 1
    return dif


# n, k = map(int, input().split())
tests = int(input())
for t in range(tests):
    n = int(input())
    s = input()
    
    chars = ['a']
    k = 0
    pw = 1
    ch = 'a'
    while pw < n:
        k += 1
        pw *= 2
        ch = chr(ord(ch) + 1)
        chars.append(ch)
    
    fixes = [0] * n
    for i in range(n):
        fx = 0 if s[i] == chars[k] else 1
        fixes[i] = [0] * 20
        fixes[i][0] = fx

    shift = 1
    for j in range(1, k + 1):
        ch = chars[k - j]
        shift2 = 2 * shift
        max_i = n - shift2 + 1
        for i in range(0, max_i, shift2):
            fx1 = delta(s, i, i + shift - 1, ch) + fixes[i + shift][j - 1]
            fx2 = fixes[i][j - 1] + delta(s, i + shift, i + shift2 - 1, ch)
            fixes[i][j] = min(fx1, fx2)
        shift = shift2
    
    print(fixes[0][k])
