import sys
input = sys.stdin.readline
from collections import *
sys.setrecursionlimit(100)

def f(l, r, d):
    if r-l==1:
        return 0 if ord(s[l])-ord('a')==d else 1
        
    m = (l+r)//2
    res = 10**18
    res = min(res, m-l-(acc[d][m]-acc[d][l])+f(m, r, d+1))
    res = min(res, f(l, m, d+1)+r-m-(acc[d][r]-acc[d][m]))
    return res

t = int(input())

for _ in range(t):
    n = int(input())
    s = input()[:-1]
    acc = [[0] for _ in range(26)]
    
    for i in range(n):
        for j in range(26):
            acc[j].append(acc[j][-1]+(1 if ord(s[i])-ord('a')==j else 0))
    
    print(f(0, n, 0))