T = int(input())
for _ in range(T):
    n, s = int(input()), input()
    m, tn = 0, n
    while tn: tn //= 2; m += 1

    mem = [0]*n
    for p in range(m):
        r, ch = 2**p, chr(ord('a')+m-p-1)
        for i in range(0, n, r):
            if p == 0:
                mem[i] = 1 if s[i] != ch else 0
            else:
                lcc = sum([1 for j in range(i, i+r//2) if s[j] != ch])
                rcc = sum([1 for j in range(i+r//2, i+r) if s[j] != ch])
                mem[i] = min(mem[i]+rcc, lcc+mem[i+r//2])
    print(mem[0])
