for t in range(int(input())):
    n = int(input())
    s = [ord(c) - ord('a') for c in input()]

    def solve(l, r, target):
        if r - l == 1:
            return 0 if s[l] == target else 1
        m = (l + r) // 2
        return min(
            sum(v != target for v in s[l:m]) + solve(m, r, target + 1),
            sum(v != target for v in s[m:r]) + solve(l, m, target + 1)
        )
    
    print(solve(0, n, 0))
