import sys
import math
from collections import defaultdict,Counter

# input=sys.stdin.readline
# def print(x):
#     sys.stdout.write(str(x)+"\n")

def find(s1,v,k):
    global f
    l=len(s1)
    if l==1:
        if s1!=chr(v):
            d[k]+=1
        return
    c1=s1[:l//2].count(chr(v))
    c2=s1[l//2:].count(chr(v))
    if c1>c2:
        d[k]+=l//2-c1
        find(s1[l//2:],v+1,k)
    elif c1<c2:
        d[k]+=l//2-c2
        find(s1[:l//2],v+1,k)
    else:
        d[k]+=l//2-c1
        f+=1
        d[f]=d[k]
        find(s1[:l//2],v+1,f)
        find(s1[l//2:],v+1,k)


# sys.stdout=open("CP3/output.txt",'w')
# sys.stdin=open("CP3/input.txt",'r')

# m=pow(10,9)+7
t=int(input())
for i in range(t):
    n=int(input())
    s=input()
    d={1:0}
    f=1
    find(s,97,1)
    print(min(list(d.values())))