import sys
sys.setrecursionlimit(100000)
from collections import defaultdict
from collections import deque
import heapq

I=lambda : list(map(int,input().split(' ')))
'''
for _ in range(int(input())):
    x,y,z=I()
    if x==y==z:
        print('YES')
        print(str(x)+' '+str(x)+' '+str(x))
    elif x==y and x>z :
        print('YES')
        print(str(x)+' '+str(z)+' '+str(z))
    elif x==z and x>y:
        print('YES')
        print(str(y)+' '+str(x)+ ' '+str(y))
    elif y==z and y>x:
        print('YES')
        print(str(x)+' '+str(x)+ ' '+str(y))
    else:
        print('NO')
'''
'''
for _ in range(int(input())):
    n=int(input())
    lst=I()      
    dct=defaultdict(int)
    for i in range(n):
        dct[i+1]
    for j,ele in enumerate(lst):
        if dct[ele]==0:
            dct[ele]=j+1
    print(" ".join(map(str,[e[1] for e in sorted([(dct[ele],ele) for ele in range(1,n+1)])])))
'''
'''
for _ in range(int(input())):
    n=int(input())
    lst=I()
    max_ind=None   
    for i in range(n-2,-1,-1):
        if lst[i]>=lst[i+1]:
            continue
        else:
            max_ind=i+1
            break
    #Max index
    if max_ind==None:
        print(0)
    else:
        min_ind=0
        for i in range(max_ind-1,-1,-1):
            if lst[i]<=lst[i+1]:
                continue
            else:
                min_ind=i+1
                break
        print(min_ind)    
'''
def search(start,end,c,s,dist):
    #case 1 first half c good and secode half c+1 good
    mid=int(start+end)//2                
    if end>start:
        a=search(mid+1,end,dct_a[1+dct[c]],s,dist)+get_freq(start,mid,dist,c)    
        b=search(start,mid,dct_a[1+dct[c]],s,dist)+get_freq(mid+1,end,dist,c)
        return max(a,b)
    elif end==start:
        return get_freq(start,end,dist,c)
    else:
        return 0
        

    
def get_freq(start,end,dist,c):
    j=dct[c]-1
    return dist[end+1][j]-dist[start][j]
        
        

for _ in range(int(input())):
    
        
    n=int(input())
    s=input()

    alphabet=('abcdefghijklmnopqrstuvwxyz')
    dct={}
    dct_a={}
    for i,a in enumerate(alphabet):
        dct[a]=i+1
        dct_a[i+1]=a
    
    
    ss=[0 for i in range(26)]
    dist=[ss]
    for a in s:
        new_=[ele for ele in dist[-1]]
        new_[dct[a]-1]+=1
        dist.append(new_)
    
    print(n-search(0,n-1,'a',s,dist))