def solve(s,idx,c):
    if len(s)==1:
        if alpha[idx]!=s[0]:
            return c + 1 
        else:
            return c
    else:
        a1 = c
        a2 = c 
        for i in range(len(s)//2):
            if s[i]!=alpha[idx]:
                a1 = a1 + 1 
        j = len(s)-1
        while j>=len(s)//2:
            if s[j]!=alpha[idx]:
                a2 = a2 + 1 
            j = j  - 1 
        
        return min(solve(s[len(s)//2:len(s)],idx+1,a1),solve(s[0:len(s)//2],idx+1,a2))
        
alpha = []
x = 'abcdefghijklmnopqrstuvwxyz'
for item in x:
    alpha.append(item)
    
    
for _ in range(int(input())):
    n = int(input())
    s = input()
    ans = solve(s,0,0)
    print(ans)