import sys,math,itertools
from collections import Counter,deque,defaultdict
from bisect import bisect_left,bisect_right 
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def dfs(l,r,c,res):
    if r-l == 1:
        if s[l] != chr(ord('a') + c):
            res += 1
        global ans
        ans = min(ans,res)
        return
    ch = chr(ord('a') + c)
    L = R = 0
    mid = (l+r)//2
    for i in range(l,mid):
        if s[i] != ch: L += 1
    for i in range(mid,r):
        if s[i] != ch: R += 1
    dfs(mid,r,c+1,res+L)
    dfs(l,mid,c+1,res+R)
for _ in range(inp()):
    n = inp()
    s = sys.stdin.readline()
    s = s[:len(s)-1]
    ans = INF
    dfs(0,n,0,0)
    print(ans)