def task(char,list1):
    map1[char]=[0]
    count=0
    for i in range(len(list1)):
        if list1[i]==char:
            count+=1
            
        map1[char].append(count)

def recur(char,start,end,moves,count):
    if 2**count==n:
        if list1[start]==char:
            ans.append(moves+1)
        else:
            ans.append(moves)
        return
    
    recur(chr(ord(char)+1),start,(start+end-1)//2,moves+map1[char][end+1]-map1[char][(start+end+1)//2],count+1)
    recur(chr(ord(char)+1),(start+end+1)//2,end,moves+map1[char][(start+end-1)//2+1]-map1[char][start],count+1)
    
        

t=int(input())
for _ in range(t):
    n=int(input())
    list1=input().strip()
    
    map1=dict()
    for i in range(97,122+1):
        ch=chr(i)
        task(ch,list1)
    
    ans=[]
    recur("a",0,n-1,0,0)
    #print(ans)
    print(n-max(ans))
    
    
    
    
   
    
    
    
    
    
    
    
