import sys

input=sys.stdin.readline

alphabetlist=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

for _ in range(int(input())):
    n=int(input())
    s=input()
    s=s[:n]
    data=[[0 for i in range(26)] for j in range(n+1)]
    for i in range(1,n+1):
        for j in range(26):
            data[i][j]=(s[i-1]==alphabetlist[j])+data[i-1][j]

    memo={}
    def dp(i,k,j):
        if (i,k,j) in memo:
            return memo[(i,k,j)]

        if k==1:
            res=1-(s[i]==alphabetlist[j])
            memo[(i,k,j)]=0
            memo[(i,k,j)]=res
            return res

        res=0
        test1=dp(i,k//2,j+1)+(k//2-(data[i+k][j]-data[i+k//2][j]))
        test2=dp(i+k//2,k//2,j+1)+(k//2-(data[i+k//2][j]-data[i][j]))
        res=min(test1,test2)
        memo[(i,k,j)]=0
        memo[(i,k,j)]=res
        return res

    #print("ans:{}".format(dp(0,n,0)))
    print(dp(0,n,0))
    #print(memo)
