from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

def rl():
    return list(map(int, input().split()))


def solve():
    n = ri()
    s = input()
    partials = {}
    for l in 'qwertyuiopasdfghjklzxcvbnm':
        partials[l] = [0] * n

    partials[s[0]][0] = 1
    for i, c in enumerate(s[1:]):
        partials[c][i + 1] = 1 + partials[c][i]


    def opt(lo, hi, letter):
        if lo == hi:
            if letter == s[lo]:
                return 0
            else:
                return 1
        else:
            mid = (lo + hi) // 2

            cost1 = mid - lo + 1 + opt(mid + 1, hi, chr(ord(letter) + 1))
            if lo == 0:
                cost1 -= partials[letter][mid]
            else:
                cost1 -= partials[letter][mid] - partials[letter][lo - 1]

            cost2 = hi - mid + opt(lo, mid, chr(ord(letter) + 1))
            cost2 -= partials[letter][hi] - partials[letter][mid]

            # print (lo, hi, cost1, cost2)
            return min(cost1, cost2)

    print (opt(0, n - 1, 'a'))









mode = 'T'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()
