# https://codeforces.com/contest/1385/problem/D
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
# do magic here


def solve(nums, ch, left, right):
    if left == right:
        return (0 if nums[left] == ch else 1)
    cnt1, cnt2 = 0, 0
    mid = (left+right)//2
    for x in range(left, mid+1):
        if nums[x] != ch:
            cnt1 += 1
    for x in range(mid+1, right+1):
        if nums[x] != ch:
            cnt2 += 1
    a = cnt2 + solve(nums, ch + 1, left, mid)
    b = cnt1 + solve(nums, ch + 1, mid + 1, right)
    return min(a, b)


t = int(input())
for _ in range(t):
    n = int(input())
    arr = [x for x in input()]
    nums = [0] + [ord(item)-97 for item in arr]
    print(solve(nums, 0, 1, n))