for _ in range(int(input())):
    
    n=int(input())
    a=input()
    def solve(a,k,low,high):
        # print(k,low,high)
        if low==high:
            if a[low]==chr(ord('a') + k):
                return 0
            else:
                return 1
        else:
            ans1,ans2=0,0
            mid=(low+high)//2
            for i in range(low,mid+1):
                if a[i]!=chr(ord('a') + k):
                    ans1+=1
            for i in range(mid+1,high + 1):
                if a[i]!=chr(ord('a') + k):
                    ans2+=1
            val1=ans2 + solve(a,k+1,low,mid)
            val2=ans1 + solve(a,k+1,mid+1,high)
            # print(k,low,high,val1,val2,ans1,ans2)
            return min(val1 , val2 )
    print(solve(a,0,0,n-1))        