def dfs(l,r,n,s,letter):
    if n==1:
        if s[l]!=letter:
            return 1
        else:
            return 0
    m=l+(r-l)//2
    cl=0
    cr=0
    for i in range(l, m+1):
        if s[i]!=letter:
            cl+=1
    for i in range(m+1, r+1):
        if s[i]!=letter:
            cr+=1
    newletter=chr(ord(letter)+1)
    return min(cl+dfs(m+1, r, n//2, s, newletter),
               cr+dfs(l, m, n//2, s, newletter))



def solve():
    # put code here
    n=int(input())
    s=input()
    """
    letter='a'
    l=0
    r=n-1
    tempn=n
    total=0
    while tempn>=1:
        m=l+(r-l)//2
        cl=0
        cr=0
        for i in range(l, m+1):
            if s[i]!=letter:
                cl+=1
        for i in range(m+1, r+1):
            if s[i]!=letter:
                cr+=1
        if tempn==1:
            total+=cl
        elif cl<cr:
            l=m+1
            total+=cl
        else:
            r=m
            total+=cr
        tempn//=2
        letter=chr(ord(letter)+1)
        #print('tempn: ', tempn)
    """
    print(dfs(0, n-1, n, s, 'a'))



t = int(input())
for _ in range(t):
    solve()
