from collections import deque
from collections import OrderedDict
import math
 
import sys
import os
import threading
import bisect
 
import operator
 
import heapq
 
 
from atexit import register
from io import BytesIO
 
#sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
#sys.stdout = BytesIO()
#register(lambda: os.write(1, sys.stdout.getvalue()))
 
 
import io
#input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
#sys.stdin = open("F:\PY\\test.txt", "r")
input = lambda: sys.stdin.readline().rstrip("\r\n")
#input = sys.stdin.readline
 
for t in range(int(input())):
    n = int(input())
    s = [' ']+list(str(input()))
    
    if n==1:
        if s[1]=='a':
            print(0)
        else:
            print(1)
        continue
    if n==2:
        if s[1]=='a' or s[2]=='a':
            if s[1]=='b' or s[2]=='b':
                print(0)
            else:
                print(1)
        elif s[1]=='b' or s[2]=='b':
            print(1)
        else:
            print(2)
        continue
    
    
    ar26 = [[0]*(n+2) for i in range(26)]
    #print(ord('a'), ord('z'))
    for i in range(26):
        vA = ord('a')+i
        for j in range(1,n+1):
            ar26[i][j]=ar26[i][j-1]
            if ord(s[j])==vA:
                ar26[i][j]+=1
    
    #pre dynamic
    dp=[0]*(n*3)
    step, idp,sym = n//2, 3, 1
    dp[1]=step-(ar26[0][step]-ar26[0][0])
    dp[2]=step-(ar26[0][step*2]-ar26[0][step])
    step//=2
    answer = 999999999
    #print(chr(97))
    #sys.exit(0)
    while(step>=1):
        bol = 1
        for i in range(1, (n+1), step):
            #print((idp-1)//2, end=" ") right
            per = (step-(ar26[sym][i+step-1]-ar26[sym][i-1]))
            
            if bol%4==1 or bol%4==2:
                dp[idp]=dp[(idp-1)//2+1]+per
            else:
                dp[idp]=dp[(idp-1)//2-1]+per
            if step==1:
                st = chr(97+sym+1)
               #print(per," ", i, i+step-1, st)
                if (bol%4)%2==1 and s[i+1]!=st:
                    dp[idp]+=1
                elif (bol%4)%2==0 and s[i-1]!=st:
                    dp[idp]+=1
                answer = min(answer, dp[idp])
            bol+=1
            idp+=1
        #break
        sym+=1
        step//=2
    print(answer)
        #break
    
    