import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
#from decimal import Decimal
from fractions import Fraction
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+7

ans=INF

def recur(l,r,c,v):
    global ans
    if l-r==0:
        if s[l]!=c:
            v+=1
        ans=min(ans,v)
        return
    v1=0
    for i in range(l,(l+r)//2+1):
        if s[i]!=c:
            v1+=1
    recur((l+r)//2+1,r,chr(ord(c)+1),v+v1)
    v2=0
    for i in range((l+r)//2+1,r+1):
        if s[i]!=c:
            v2+=1
    recur(l,(l + r) // 2, chr(ord(c) + 1), v + v2)


for t in range(int(data())):
    n=int(data())
    s=data()
    ans=INF
    recur(0,n-1,'a',0)
    out(ans)

