def distance(s, left, right, num):
    length = right - left
    if length == 1:
        return 0 if s[left] == num else 1
    mid = left + length//2
    cnt = 0
    for i in range(left, mid):
        if s[i] != num:
            cnt += 1
    left_case = cnt + distance(s, mid, right, num + 1)
    cnt = 0
    for i in range(mid, right):
        if s[i] != num:
            cnt += 1
    right_case = distance(s, left, mid, num + 1) + cnt
    return min(left_case, right_case)


if __name__ == "__main__":
    for _ in range(int(input())):
        n = int(input())
        s = list(map(lambda c: ord(c) - ord('a'), list(input())))
        print(distance(s, 0, n, 0))
