import sys
def cost(l, r, c):
    res = 0
    for i in range(l, r + 1):
        if string[i] != chr(c):
            res += 1
    return res

def calc(l, r, c):
    if l == r:
        if string[l] == chr(c):
            return 0
        else:
            return 1
    mid = (l + r) // 2
    return min(cost(l, mid, c) + calc(mid + 1, r, c + 1), cost(mid + 1, r, c) + calc(l, mid, c + 1))

tc = int(sys.stdin.readline())
for _ in range(tc):
    n = int(sys.stdin.readline())
    string = sys.stdin.readline().rstrip()
    print(calc(0, n - 1, ord('a')))