import math
t = int(input())
infinty = math.inf

def solve(char,l,r):
    if l>r:
        return infinty
    
    c = chr(char)
    
    if l == r:
        return int(s[l]!=c)

    mid = (l+r)//2
    s_left = s[l:mid+1]
    s_right = s[mid+1:r+1]
    nby2 = len(s_left)
    
    # Convert right to c and left to c+1
    cnt_right = nby2 - s_right.count(c)
    cnt_right += solve(char+1,l,mid)
    
    # Convert left to c and right to c+1
    cnt_left = nby2 - s_left.count(c)
    cnt_left += solve(char+1,mid+1,r)  

    return min(cnt_right,cnt_left)


for _ in range(t):
    n = int(input())
    s = input()
    print(solve(97,0,n-1))      # chr(97)='a',start to end 