from string import ascii_lowercase as alph
from itertools import product as combinations


def gen(l, r, ch, s0, s1):
    if l == r:
        s0[l] = alph[ch]
        # print("".join(s0))
        diff = 0
        for i in range(len(s0)):
            if s0[i] != s1[i]:
                diff += 1

        return diff

    h = (r - l + 1) // 2
    m = l + h
    sl = s0[:]
    for i in range(l, m):
        sl[i] = alph[ch]

    sr = s0
    for i in range(m, r + 1):
        sr[i] = alph[ch]
    return min(gen(l, m - 1, ch + 1, sr, s1), gen(m, r, ch + 1, sl, s1))


def min_turns(l, r, ch):
    if l == r:
        return 0 if s[l] == alph[ch] else 1

    h = (r - l + 1) // 2
    m = l + h
    lc = sum(1 for i in range(l, m) if s[i] != alph[ch])
    rc = sum(1 for i in range(m, r + 1) if s[i] != alph[ch])

    lm = min_turns(m, r, ch + 1)
    rm = min_turns(l, m - 1, ch + 1)

    if lc + lm < rc + rm:
        return lc + lm
    else:
        return rc + rm


# for s1 in combinations('abcdefhz', repeat=8):
#     s1 = "".join(s1)
#     n = len(s1)
#     s = s1
#     # print(s1)
#     a = gen(0, len(s1) - 1, 0, [""]*len(s1), s1)
#     b = min_turns(0, n - 1, 0)
#     if a != b:
#         print(s1, a, b)
#
# print("000")


for _ in range(int(input())):
    n = int(input())
    s = input()

    print(min_turns(0, n - 1, 0))

