from sys import stdin,stdout
def fn(s,e,ch):
    if s==e:
        if ord(s1[s])!=ch:return 1
        return 0
    mid=(s+e)>>1;left=right=0
    for i in range(s,mid+1):
        if ord(s1[i])!=ch:left+=1
    for i in range(mid+1,e+1):
        if ord(s1[i])!=ch:right+=1
    return min(left+fn(mid+1,e,ch+1),right+fn(s,mid,ch+1))
for _ in range(int(stdin.readline())):
    n=int(stdin.readline())
    # a=list(map(int,stdin.readline().split()))
    s1=input()
    print(fn(0,n-1,97))