import math

def ans(arr,n,d,n_global):
    v = n_global/n
    v = math.log(v,2)+1
    var = d[v]
    if n==1:
        if arr[0]==var:
            return(0)
        return(1)
    
    sub1 = arr[:n//2]
    sub2 = arr[n//2:]
    count1=0
    count2=0
    for i in sub1:
        if i==var:
            count1+=1
            
    for i in sub2:
        if i==var:
            count2+=1

    v+=1
    
    ans1 = len(sub1)-count1 + ans(sub2,n//2,d,n_global)
    ans2 = len(sub2)-count2 + ans(sub1,n//2,d,n_global)
    return(min(ans1,ans2))

m = int(input())
for i in range(m):
    n = int(input())
    arr = input()
    answer = 0
    d = {1:'a',2:'b',3:'c',4:'d',5:'e',6:'f',7:'g',8:'h',9:'i',10:'j',11:'k',12:'l',13:'m',14:'n',15:'o',16:'p',17:'q',18:'r',19:'s',20:'t',21:'u',22:'v',23:'w',24:'x',25:'y',26:'z'}
    n_global = n
    print(ans(arr,n,d,n_global))

    
