from collections import deque
import sys
def inp():
    return sys.stdin.readline().strip()
def f(l,r,c,s):
    if l>r:
        return 0
    if l==r:
        if s[l]==c:
            return 0
        return 1 
    mid=(l+r)//2
    
    left=0
    for i in range(l,mid+1):
        if s[i]!=c:
            left+=1 
    right=0
    for i in range(mid+1,r+1):
        if s[i]!=c:
            right+=1
    ans=min(left+f(mid+1,r,c+1,s),right+f(l,mid,c+1,s))
    return ans
        
    
for _ in range(int(inp())):
    n=int(inp())
    s=inp()
    s=[ord(i)-ord('a') for i in s]
    print(f(0,n-1,0,s))