from math import log
from collections import Counter
for _ in range(input()):
    n = input()
    s = (raw_input())
    c = 'a'
    p = int(log(n,2)) + 1
    ans = 0
    while s!='':
        if n==1:
            if s[0]!=c:
                #print ans
                ans += 1
                s = ''
            break
        a = s[:n/2]
        b = s[n/2:]
        d = Counter(a)
        e = Counter(b)
        f = -1
        if d[c]==e[c]:
            f = 0
            for i in range(ord(c)-97 + 1+ 1,p):
                y = chr(97 + i)
                if d[y]<e[y]:
                    f = 1
                    break
                elif d[y]>e[y]:
                    f = 2
                    break
        if d[c]<e[c] or f==1:
            ans += n/2 - e[c]
            s = a
        if d[c]>e[c] or f==2:
            ans += n/2 - d[c]
            s = b
        if f==0:
            ans += n/2 - d[c]
            s = b
        #print d[c],e[c],s,ans,n
        c = chr(ord(c) + 1)
        n=n/2
    print ans
