def best(s, c, l, r):
    if l+1 == r:
        return int(s[l] != c)
        
    half = (r-l)//2
    cost_l = half-s[l:l+half].count(c) + best(s, c+1, l+half, r)
    cost_r = half - s[l+half:r].count(c) + best(s, c+1, l, l+half)
    return min(cost_l, cost_r)

t = int(input())

for _ in range(t):
    n = int(input())
    
    s = [ord(c)-ord('a') for c in input()]
    
    print(best(s, 0, 0, n))
