from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop,heapify
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)
 
def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n')]
def li3():return [int(i) for i in input().rstrip('\n')]

# sys.setrecursionlimit(131072)


for _ in range(val()):
    n = val()
    l = [ord(i) - ord('a') for i in st()]
    cnt = Counter()
    l1 = []
    l1.append(cnt.copy())
    for i in l:
        cnt[i] += 1
        l1.append(cnt.copy())

    he = deque()
    he.append([0, n - 1, 0, 0])
    ans = n + 1
    while he:
        left, right, costyet, curr = he.popleft()
        # print(left,right, costyet, curr)
        if left == right:
            costyet += 1 if l[left] != curr else 0
            ans = min(ans,costyet)
            continue

        le = right - left + 1
        i, j = left, right

        c1 = (le // 2) - (l1[left + (le // 2)][curr] - l1[left][curr])
        c2 = (le // 2) - (l1[right + 1][curr] - l1[left + (le // 2)][curr])


        he.append([i, i + (le // 2) - 1, costyet + c2, curr + 1])
        he.append([i + (le // 2), j, costyet + c1, curr + 1])
    print(ans)
    # print('\n\n\n\n')