def check_left(s, left, right, cur, ch):
    if right - left == 1:
        return 0 if s[left] == ch else 1

    mid = (left + right) // 2
    cnt = 0
    ii = left
    while right - ii != ii - left:
        if s[ii] != ch:
            cnt += 1
        ii += 1
    return cnt + check(s, mid, right, cur, ch + 1)

def check_right(s, left, right, cur, ch):
    if right - left == 1:
        return 0 if s[left] == ch else 1
    mid = (left + right) // 2
    cnt = 0
    ii = right
    while right - ii != ii - left:
        ii -= 1
        if s[ii] != ch:
            cnt += 1
    return cnt + check(s, left, mid, cur, ch + 1)


def check(s, left = None, right = None, cur = 0, ch = 0):
    if left is None:
        left = 0
    if right is None:
        right = len(s)

    return cur + min(check_left(s, left, right, cur, ch), check_right(s, left, right, cur, ch))


ans = []
for _ in range(int(input())):
    n = int(input())
    s = input()
    s = [ord(ch) - ord('a') for ch in s]
    ans.append(check(s))

print('\n'.join(map(str, ans)))
