from sys import stdin
input = stdin.readline


def soln(s, i, j, r):
    # print(i, j, r)
    # print(s[i : ((i + j) // 2) + 1])
    # print(s[((i + j) // 2) + 1 : j + 1])
    if i == j:
        if s[i] == r:
            return 0
        else:
            return 1
    else:
        cost1 = 0
        for x in range(i, ((i + j) // 2) + 1):
            if s[x] != r:
                cost1 += 1
        cost2 = 0
        for x in range(((i + j) // 2) + 1, j + 1):
            if s[x] != r:
                cost2 += 1
        # print(f'cost: {cost1}, {cost2}')
        return min(cost1 + soln(s, ((i + j) // 2) + 1, j, chr(ord(r) + 1)), cost2 + soln(s, i, ((i + j) // 2), chr(ord(r) + 1)))




t = int(input())




for _ in range(t):
    n = int(input())
    s = input().rstrip()
    print(soln(s, 0, n - 1, 'a'))