'''
Wrong logic Greedy doesn't work for this
1
16
decaaaaaaaaazzzz
Code output: 11
Correct output: 9

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 n:
        if n==1:
            if s!=c:
                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+1):
                y = chr(96 + i)
                if d[y]<e[y]:
                    f = 2
                    break
                elif d[y]>e[y]:
                    f = 1
                    break
        if d[c]<e[c] or f==1:
            ans += n/2 - e[c]
            s = a
        if d[c]>e[c] or f==2 or f==0 :
            ans += n/2 - d[c]
            s = b        
        c = chr(ord(c) + 1)
        n=n/2
    print ans
'''
def f(s,c):
    if len(s)==1:
        if s!=c:return 1
        else:return 0
    n = len(s)
    cnt1 = n/2 + f(s[:n/2],chr(ord(c)+1)) - s[n/2:].count(c)
    cnt2 = n/2 + f(s[n/2:],chr(ord(c)+1)) - s[:n/2].count(c)
    return min(cnt1,cnt2)
for _ in range(input()):
    n = input()
    s = raw_input()
    print f(s,'a')
