import math
ALP ='abcdefghijklmnopqrstuvwxyz'

for i in range(int(input())):
    t = int(input())
    u = int(math.log(t,2))
    A = input().strip()
    CS = [[] for _ in range(26)] #[alpha][i]
    cost_min = 131072
    

    for l in range(u+1):
        cnt = 0
        CS[l].append(0)
        for n in A:
            if ALP[l] == n:cnt += 1
            CS[l].append(cnt)
    
    for p in range(1<<u):
        cost = 0
        start = 0
        end   = t
        tmp = t
        for j in range(u):
            tmp = tmp//2
            if cost > cost_min:break
            if ((p >> j) & 1):
                cost += tmp - (CS[j][end] - CS[j][start+tmp])
                end -= tmp
            else:
                cost += tmp - (CS[j][start+tmp]-CS[j][start])
                start += tmp
        else:
            cost += 1-(CS[u][end]-CS[u][start])
            cost_min = min(cost_min,cost)
        
    print(cost_min)