t = int(input())
for _ in range(t):
    n = int(input())
    s = input()
    def sol(l, r, a) -> int:
        if r - l == 1:
            return 1 if s[l] != a else 0
        m = (l + r) // 2
        c1 = sol(l, m, chr(ord(a) + 1))
        c2 = sol(m, r, chr(ord(a) + 1))
        for i in range(m, r):
            c1 += 1 if s[i] != a else 0
        for i in range(l, m):
            c2 += 1 if s[i] != a else 0
        return min(c1, c2)
    print(sol(0, n, 'a'))