from sys import stdin


def inp():
    return stdin.buffer.readline().rstrip().decode("utf8")


def itg():
    return int(stdin.buffer.readline())


def mpint():
    return map(int, stdin.buffer.readline().split())


# ############################## import
# ############################## main

def dfs(s, c):
    if len(s) == 1:
        return 0 if s == c else 1
    size = len(s) >> 1
    s1 = s[:size]
    s2 = s[size:]
    left_c = s1.count(c)
    right_c = s2.count(c)
    cost1 = size - left_c
    cost2 = size - right_c
    next_char = chr(ord(c)+1)
    return min(cost1 + dfs(s2, next_char), cost2 + dfs(s1, next_char))

for case in range(itg()):
    n = itg()
    S = inp()
    print(dfs(S, 'a'))

# Please check!
