T = int(input())
import itertools
import math

for _ in range(T):
    n = int(input())
    nn = int(math.log2(n))
    s = input()
    ans = 0
    
    x = [[0]*(n+1) for _ in range(nn+1)]
    for i in range(n):
        r = ord(s[i]) - 97
        if r <= nn:
            x[r][i+1] = 1
        for j in range(nn+1):
            x[j][i+1] += x[j][i]
            
    h_list = list(itertools.product([0,1], repeat=nn))
    
    ans = n
    for ll in h_list:
        ss = n
        l,r = 0,n
        l2,r2 = 0,n
        aa = 0
        for i in range(nn):
            ss //= 2
            if ll[i] == 0:
                r2 = r
                r = l + ss
                l2 = r
                aa += ss - (x[i][r2] - x[i][l2])
            else:
                l2 = l
                l = r - ss
                r2 = l
                aa += ss - (x[i][r2] - x[i][l2])
                
        aa += 1 - (x[nn][r] - x[nn][l])
        
        ans = min(aa,ans)
        
    print(ans)