from functools import lru_cache
for _ in range(int(input())):
    n = int(input())
    a = input().strip()
    # st = [(0,n)]
    # while st:
    #     l,r = st.pop()
    #     mid = l+r>>1
    #     st.append
    @lru_cache(None)
    def rec(l,r,cur):
        if l==r:
            return (cur!=a[l])*1
        mid = l+r>>1
        res = (r-mid)-a[mid+1:r+1].count(cur)+rec(l,mid,chr(ord(cur)+1))
        res = min(res,(mid-l+1)-a[l:mid+1].count(cur)+rec(mid+1,r,chr(ord(cur)+1)))
        return res
    print(rec(0,n-1,"a"))
