def calc(c,s,sum):
    n=len(s)
    if n==1:
        if s==c:
            print(sum)
            return
        else:
            print(sum+1)
            return
    first=s[:n//2]
    second=s[n//2:]
    if first.count(c)>second.count(c):
        sum+=n//2-first.count(c)
        calc(chr(ord(c)+1),second,sum)
    elif first.count(c)<second.count(c):
        sum+=n//2-second.count(c)
        calc(chr(ord(c)+1),first,sum)
    else:
        if first.count(c)==second.count(c)==0:
            s=n*c
            sum+=n//2
            calc(chr(ord(c)+1),first,sum)
        else:#first.count(s)==second.count(s):
            d=chr(ord(c)+1)
            if first.count(d)>second.count(d):
                sum+=n//2-first.count(d)
                calc(chr(ord(d)+1),second,sum)
            elif first.count(d)<second.count(d):
                sum+=n//2-second.count(d)
                calc(chr(ord(d)+1),first,sum)

for i in range(int(input())):
    sum=0
    n=int(input())
    str=input()
    calc("a",str,sum)
