t = int(input())
def find(s,ch):
    if len(s)==1:
        return 0 if s[0]==ch else 1
    n = len(s)
    a = s[0:n//2]
    b = s[n//2:n]
    acount=a.count(ch)
    bcount=b.count(ch)
    ch=chr(ord(ch)+1)
    return min(len(a)-acount+find(b,ch),len(b)-bcount+find(a,ch))
for _ in range(t):
    n = int(input())
    s = input()
    print(find(s,'a'))

