d = {chr(ord('a') + i): i for i in range(26)}


def f(left, right, level) -> int:
    if left + 1 == right:
        if d[string[left]] != level:
            return 1
        return 0

    middle = (left + right) // 2

    ans_left = f(left, middle, level + 1)

    for i in range(middle, right):
        if d[string[i]] != level:
            ans_left += 1

    ans_right = f(middle, right, level + 1)

    for i in range(left, middle):
        if d[string[i]] != level:
            ans_right += 1

    return min(ans_right, ans_left)


if __name__ == '__main__':
    t = int(input())

    for _ in range(t):
        n = int(input())
        string = str(input())

        print(f(0, n, 0))
