def ans(c,ss,se):
    if ss==se:
        if s[ss]==c:
            return 0
        else:
            return 1
    a=0
    b=0
    for i in range(ss,(ss+se)//2+1):
        if s[i]!=c:
            a+=1
    for i in range((ss+se)//2+1,se+1):
        if s[i]!=c:
            b+=1
    x=min(a+ans(chr(ord(c)+1),(ss+se)//2+1,se),b+ans(chr(ord(c)+1),ss,(ss+se)//2))
    return x
t=int(input())
for i in range(t):
    n=int(input())
    s=input()
    print(ans('a',0,n-1))
    
