T, = map(int, input().split())
alpha = "abcdefghijklmnopqrstuvwxyz"
for _ in range(T):
    N, = map(int, input().split())
    s = input().strip()
    S = [[0]*(len(s)+1) for i in range(26)]
    for c in range(26):
        for i in range(len(s)):
            S[c][i+1] = S[c][i] + (alpha[c] == s[i])

    tmp = N
    mk = 0
    while tmp:
        tmp//=2
        mk += 1
    RR = 10**18
    for k in range(2*N):
        R = 0
#        print(k)
        st, en = 0, len(s)
        for i in range(mk):
            k, m = divmod(k, 2)
            if m:
                st2 = st + (en-st)//2
#                print((S[i][en2]-S[i][st]))
                R += en-st2-(S[i][en]-S[i][st2])
                en = en - (en-st)//2
            else:
                en2 = en - (en-st)//2
#                print((S[i][en2]-S[i][st]))
                R += en2-st-(S[i][en2]-S[i][st])
                st = st + (en-st)//2
#            print(st, en, R)
#        print(R)
        RR = min(R, RR)
    print(RR)

