t = int(input())

d = {}  # key is char
c = {}  # key is number

for i in range(26):
    d[chr(ord('a') + i)] = i
    c[i] = chr(ord('a') + i)


def f(s, lvl, ans, n):
    if len(s) == 1:
        if not (s == c[lvl]):
            ans += 1

        print(ans)
        return

    else:
        left = right = 0
        for i in range(0, n // 2):
            if d[s[i]] == lvl:
                left += 1

        for i in range(n // 2, n):
            if d[s[i]] == lvl:
                right += 1

    if left >= right:
        ans += n // 2 - left
        f(s[n // 2:], lvl + 1, ans, n // 2)
    else:
        ans += n // 2 - right
        f(s[:n // 2], lvl + 1, ans, n // 2)


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

    f(string, 0, 0, n)
