# -*- coding: utf-8 -*-
"""
#k,m=map(int,input().split())
t=int(input())
for _ in range(t):
    n=int(input())
    x=list(map(int,input().split()))
    
"""
import math
t=int(input())
for _ in range(t):
    k=int(input())
    s=input()
    count=[0]
    m=int(math.log(k)/math.log(2))
    def check(s1,i):
       # print(s1,i)
        n=len(s1)
        if n==1:
            if s1[0] != chr(ord('a')+i):
                count[0]+=1
            return True,''
        right=0
        left=0
        for j in range(n//2):
           # print('@',i,s[j])
            if s1[j] != chr(ord('a')+i):
                left=left+1  
       # print('left', left)
        for j in range(n//2,n):
            #print('#',i,s[j])
            if s1[j] != chr(ord('a')+i):
                right=right+1
        #print(left,right)
        #print('right', right)
        count[0]+=min(left,right)
       # print(count[0],'@')
        if left < right:
            s1=s1[n//2:]
            return True,s1
        elif right > left:
            s1=s1[:n//2]
            return False,s1
        else:
            a1=s1[n//2:].count(chr(ord('a')+i+1))
            a2=s1[:n//2].count(chr(ord('a')+i+1))
            if a2<a1:
                s1=s1[n//2:]
                return True,s1    
            else:
                s1=s1[:n//2]
                return False,s1               
    y,s1=check(s,0)
    #print(count[0])
    for i in range(1,m+1):
        if  y:
            y,s1=check(s1,i)
        else:
            y,s1=check(s1,i)
    print(count[0])
 
        
#    m=n
#    def check (s,i,count):
#        n=len(s)
#        print(s,i,count,'&')
#        if n==1:
#            if s[0] != chr(ord('a')+i):
#                count+=1
#                return
#        right=0
#        left=0
#        for j in range(n//2):
#           # print('@',i,s[j])
#            if s[j] != chr(ord('a')+i):
#                left=left+1  
#       # print('left', left)
#        for j in range(n//2,n):
#            #print('#',i,s[j])
#            if s[j] != chr(ord('a')+i):
#                right=right+1
#        #print('right', right)
#        if right < left:
#            
#            count =count+right
#           # print(count,right,'@')
#            #print(n)
#            check(s[:n//2],i+1,count)
#        else:
#           # print(count,left,'#')
#           # print(n)
#            count=count+left
#            check(s[n//2:],i+1,count)            
#    count=check(s,0,0)
        
    
