#!/bin/python3

import math
import os
import random
import re
import sys
from collections import defaultdict


# # def getMapCount(mapping, key):



# #     if key in mapping:
# #         return mapping[key]
# #     else:
# #         return 0

# def binSearch(arr, item):
#     low, hi = 0, len(arr) - 1
#     while low <= hi:
#         mid = (low + hi) // 2

#         if arr[mid] < item:
#             low = mid + 1
#         else:
#             hi = mid -1 
#             ans = mid
#         mid = (low + hi )// 2
    
#     return mid


# #exact binarySearch
# def binarySearch (arr, item): 
#     low, hi = 0, len(arr) - 1
    
#     while low <= hi:
#         mid = (low + hi) // 2

#         if arr[mid] == x: 
#             return mid 
        
#          if arr[mid] < item:
#             low = mid + 1
#         else:
#             hi = mid -1 
#     return -1

  

# # print(binSearch([1,2,4,5,9,11,13,99,100], 8))
# def countTriplets(arr, r):
#     # arr = sorted(arr)
#     countMap = dict()
#     index = 0
#     for item in arr:
#         if item not in countMap:
#             countMap[item] = [index]

#         else:
#             countMap[item].append(index)

#         index += 1

#     count = 0
#     print(countMap)
#     indx  = 0
#     for key in countMap:
#         for indx in countMap[key]:
#             if r == 1:
#                 count += (countMap[key] * (countMap[key] - 1) * (countMap[key] - 2)) // 6
#             else:
#                 count += countMap[key] * getMapCount(countMap, indx, key * r) * getMapCount(countMap, key * r * r)
#         indx += 1

#     return count

# fib_ara = [1,1]
# def fib():
#     while fib_ara[-1] < 10**9:
#         fib_ara.append(fib_ara[-1] + fib_ara[-2])

# fib()
def isGood(ara):
    result = -1
    frst,lst = 0, len(ara) -1 
    for i in range(len(ara)):
        if result>min(ara[frst], ara[lst]):
            return False
        if ara[frst] <= ara[lst]:
            
            result = ara[frst]
            frst+=1
        else:
            result = ara[lst]
            lst -=1 
    return True
def makeAraGood(araStr, isLeft, ch):
    cnt = 0
    if len(araStr) == 1:
        return 1 if araStr[0] != ch else 0
    
    nextChar = chr(ord(ch)+1)
    leftStr = araStr[:len(araStr)//2]
    rightStr = araStr[len(araStr)//2:]
    if isLeft:
        for item in leftStr:
            if item != ch:
                cnt += 1
            
        cnt += min( makeAraGood(rightStr, False, nextChar),
                    makeAraGood(rightStr, True, nextChar) 
                )
    
    else:
        for item in rightStr:
            if item != ch:
                cnt += 1
        cnt += min( makeAraGood(leftStr, False, nextChar),
                    makeAraGood(leftStr, True, nextChar) 
                )
    return cnt

case = int(input())
 
for i in range(case):
    n = int(input())
    araStr = input()
    
    ans = min( makeAraGood(araStr, False, 'a'),
                    makeAraGood(araStr, True, 'a')
                )

    print(ans)