t=int(input())
def recur(s,c,n):
    if n==1 and s[0]==chr(c):
        return 0
    if n==1 and s[0]!=chr(c):
        return 1
    c1=0
    c2=0
    for i in range(n//2):
        if s[i]!=chr(c):
            c1+=1
        if s[i+n//2]!=chr(c):
            c2+=1
    return min(c1+recur(s[n//2:],(c+1),n//2),
               c2+recur(s[:n//2],(c+1),n//2))

while(t>0):
    n=int(input())
    s=input()
    print(recur(s,97,n))
    
    t-=1
