t = int(input())


def equal(c, l, r):
    to_change = 0
    for i in range(l, r):
        if code[i] != c:
            to_change += 1
    return to_change


def changes(c, l, r):
    if r - l == 1:
        if code[l] == c:
            return 0
        else:
            return 1
    else:
        return min(equal(c, l, (l + r) // 2) + changes(c + 1, (l + r) // 2, r),
                   changes(c + 1, l, (l + r) // 2) + equal(c, (l + r) // 2, r))


for _ in range(t):
    n = int(input())
    s = input()
    code = []
    for elem in s:
        code.append(ord(elem))
    print(changes(ord('a'), 0, n))
