

def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def cost(s, c, start, end):
    if start == end:
        return int(c != s[end])
    mid = (start+end)//2
    # make first half c-good
    cost0 = sum(c0 != c for c0 in s[start:mid+1])+cost(s, c+1, mid+1, end)
    # make second half c-good
    cost1 = sum(c0 != c for c0 in s[mid+1:end+1])+cost(s, c+1, start, mid)
    return min(cost0, cost1)


def solve():
    n = read_int()
    s = [ord(c)-ord('a') for c in input().strip()]
    return cost(s, 0, 0, n-1)


if __name__ == '__main__':
    T = read_int()
    for _ in range(T):
        print(solve())
