def make_equal(st,n,c):
    num=0
    for i in range(n):
        if(st[i]!=c):
            num+=1
    return num

def find(st,n,c):
    if(n==1):
        if(st[0]==c):
            return 0
        else:
            return 1
    return min(make_equal(st[0:n//2],n//2,c)+find(st[n//2:],n//2,chr(ord(c)+1)),make_equal(st[n//2:],n//2,c)+find(st[0:n//2],n//2,chr(ord(c)+1)))

t=int(input())
for _ in range(t):
    n=int(input())
    s=input()
    print(find(s,n,'a'))