# ":"
from collections import defaultdict

lis = [chr(x) for x in range(ord('a'), ord('z') + 1)]


def go(l, r, length, char):
    if length == 1:
        if s[l] == lis[char]:
            return 0
        else:
            return 1
    count1 = count2 = 0
    mid = (l + r) // 2
    for i in range(l,mid+1):
        if s[i] != lis[char]:
            count1 += 1
    count1 += go(mid + 1, r, r - mid, char + 1)
    for i in range(mid+1, r+1):
        if s[i] != lis[char]:
            count2 += 1
    count2 += go(l, mid, mid - l + 1, char + 1)
    return min(count1, count2)


t = int(input())
for _ in range(t):
    n = int(input())
    s = input()
    print(go(0, n-1, n, 0))
