from sys import stdout
from sys import stdin
def get():
    return stdin.readline().strip()
def getf():
    return [int(i) for i in get().split()]
def put(a, end = "\n"):
    stdout.write(str(a) + end)
def putf(a, sep = " ", end = "\n"):
    stdout.write(sep.join(map(str, a)) + end)

def dist(a, b, n):
    cnt = 0
    for i in range(n):
        if(a[i] != b[i]):
            cnt += 1
    return cnt

def rec(s, n, c, cost):
    if(n == 1):
        return cost + dist(s, chr(c), 1)
    s1, s2 = s[:n//2], s[n//2:]
    t = chr(c)*(n // 2)
    return min(rec(s2, n // 2, c + 1, cost + dist(s1, t, n // 2)), rec(s1, n // 2, c + 1, cost + dist(s2, t, n // 2)))

def solve(n, s):
    return rec(s, n, 97, 0)

def main():
    t = int(get())
    for i in range(t):
        n, s = int(get()), get()
        put(solve(n, s))
main()
