from math import log
from sys import stdin,stdout
for query in range(int(stdin.readline())):
    n=int(stdin.readline())
    s=[ord(x)-96 for x in list(stdin.readline().strip())]
    mylist=[[] for x in range(int(log(n,2))+1)]
    for x in range(1,int(log(n,2)+1)):
        for y in range(2**x):
            count=0
            for z in range((n//2**x)*y,(n//2**x)*(y+1)):
                if s[z]==x:
                    count+=1
            mylist[x-1].append(n//2**x-count)
    b=int(log(n,2)+1)
    for x in range(n):
        if s[x]==b:
            mylist[b-1].append(0)
        else:
            mylist[b-1].append(1)
    current=mylist[b-1][:]
    for x in range(b-2,-1,-1):
        newcurrent=[]
        for y in range(0,2**(x+1),2):
            p=current[y]+mylist[x][y+1]
            q=current[y+1]+mylist[x][y]
            newcurrent.append(min(p,q))
        current=newcurrent[:]
    stdout.write(str(current[0])+'\n')
    
