import io
import os

from collections import Counter, defaultdict, deque


def solve(N, S):
    pref = [[0] for i in range(26)]
    for x in S:
        j = ord(x) - ord("a")
        for i in range(26):
            pref[i].append(pref[i][-1] + int(i == j))
    cache = {}

    def getCost(i, j):
        assert i != j
        key = (i, j)
        if key not in cache:
            assert i != j
            ch = K - ((j - i).bit_length() - 1)

            if j - i == 1:
                cache[key] = int((ord(S[i]) - ord('a')) != ch)
            else:
                mid = (i + j) // 2
                lCost = (mid - i) - (pref[ch][mid] - pref[ch][i]) + getCost(mid, j)
                rCost = (j - mid) - (pref[ch][j] - pref[ch][mid]) + getCost(i, mid)

                #print('seg', S[i:j], 'target', ch, lCost, rCost)
                cache[key] = min(lCost, rCost)

        return cache[key]

    K = N.bit_length() - 1
    for k in range(K + 1):
        l = 1 << k
        for i in range(0, N, l):
            getCost(i, i + l)

    return getCost(0, N)


if __name__ == "__main__":
    input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

    T = int(input())
    for t in range(T):
        (N,) = [int(x) for x in input().split()]
        S = input().decode().rstrip()
        ans = solve(N, S)
        print(ans)
