import heapq as hp
import collections
import bisect


def unpack(func=int):
    return map(func, input().split())


def l_unpack(func=int):
    """list unpack"""
    return list(map(func, input().split()))


def s_unpack(func=int):
    """sorted list unpack"""
    return sorted(map(func, input().split()))


def range_n():
    return range(int(input()))


def getint():
    return int(input())


def foo(s, l, r, c,memo):
    t=l,r,c
    if t in memo:
        return memo[t]
    ans = 0
    if l == r:
        return 1 if s[l] != c else 0
    half = (r - l + 1) // 2
    a = abs(s[l:l + half].count(c) - half)
    b = abs(s[r - half + 1:r + 1].count(c) - half)
    ans += min(a + foo(s, l + half, r, chr(ord(c) + 1),memo),
               b + foo(s, l, l + half - 1, chr(ord(c) + 1),memo)
               )
    memo[t]=ans
    return ans


def main():
    for _ in range_n():
        n = getint()
        s = list(input())
        memo={}
        a = foo(s, 0, n - 1, 'a',memo)
        print(a)


main()
