from string import ascii_lowercase as alph


def min_turns(l, r, ch):
    if l == r:
        return 0 if s[l] == alph[ch] else 1

    h = (r - l + 1) // 2
    m = l + h
    lc = sum(1 for i in range(l, m) if s[i] == alph[ch])
    rc = sum(1 for i in range(m, r + 1) if s[i] == alph[ch])

    if lc > rc:
        return h - lc + min_turns(m, r, ch + 1)
    elif rc > lc:
        return h - rc + min_turns(l, m - 1, ch + 1)
    else:
        return h - lc + min(min_turns(m, r, ch + 1), min_turns(l, m - 1, ch + 1))


for i in range(int(input())):
    n = int(input())
    s = input()



    print(min_turns(0, n - 1, 0))
