######################################################
############Created by Devesh Kumar###################
#############devesh1102@gmail.com####################
##########For CodeForces(Devesh1102)#################
#####################2020#############################
######################################################
import sys
input = sys.stdin.readline
 
# import sys
import heapq 
import copy
import math
import decimal
 
# import sys.stdout.flush as flush
# from decimal import *
#heapq.heapify(li) 
#
#heapq.heappush(li,4) 
#
#heapq.heappop(li)
#
# &    Bitwise AND Operator    10 & 7 = 2
# |    Bitwise OR Operator    10 | 7 = 15
# ^    Bitwise XOR Operator    10 ^ 7 = 13
 
# <<    Bitwise Left Shift operator    10<<2 = 40
# >>    Bitwise Right Shift Operator
# '''############ ---- Input Functions ---- #######Start#####'''
 
 
def inp():
    return(int(input()))
def inlt(): 
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def insr2():
    s = input()
    return((s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
############ ---- Input Functions ---- #######End
# #####   
 
 
 

def pr_list(a):
    print(*a, sep=" ")
def main():
    tests =  inp()
    # tests = 1
    mod = 1000000007
    limit = 10**18
    ans = 0
    stack = []
    hashm = {}
    arr = []
    heapq.heapify(arr) 

    for test in range(tests):
        n = inp()
        s = insr()
        # s = 'a'*131072
        pre_sum = [[ 0 for i in range(len(s) + 1)] for j in range(26)]
        for i in range(len(s)):
            for j in range(26):
                if ord(s[i])-ord('a') != j:
                    pre_sum[j][i+1] = pre_sum[j][i]
                else:
                    pre_sum[j][i+1]= pre_sum[j][i] +1
        for i in range(26):
            pre_sum[i].pop(0)
        # print(pre_sum)
        def helper(s,l,r,hashm,c):
            if l == r:
                if ord(s[l])-ord('a') == c:
                    return 0
                else:
                    return 1
            mid = (l+r+1) //2
            # print(l,r,mid)
            # if hashm[c][r] -  hashm[c][l] +(ord(s[l])-ord('a') == c)  == r-l+1:
            #     return 0
            left = helper(s,l,mid-1,hashm,c+1) + (r-mid +1) - ( (hashm[c][r] - hashm[c][mid]) + (ord(s[mid])-ord('a') == c) )

            right =  helper(s,mid,r,hashm,c+1) + (mid-1 -l +1) - ( (hashm[c][mid-1] - hashm[c][l]) + (ord(s[l])-ord('a') == c) )
            # print(l,r,left,right,c)
            # print((r-mid +1),(hashm[c][r] - hashm[c][mid]) , (ord(s[mid])-ord('a') != c) )
            # print(l)
            return min(left,right)

        print(helper(s,0,len(s)-1,pre_sum,0))
        # print()


 
 
 
if __name__== "__main__":
    main()