#!/usr/bin/env python3

import bisect


def calc(v_i, l, r):
    l_i = bisect.bisect_left(v_i, l)
    r_i = bisect.bisect_left(v_i, r)
    return r_i - l_i


def ans(v, ch, l, r):
    if r - l == 0:
        return 0

    if ch == 25 or r - l == 1:
        return r - l - calc(v[ch], l, r)
    else:
        m = (l + r) // 2
        return min(
            ans(v, ch + 1, l, m) + r - m - calc(v[ch], m, r),
            ans(v, ch + 1, m, r) + m - l - calc(v[ch], l, m))


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

    v = []
    for i in range(26):
        v.append([])
    for i in range(n):
        s_i = s[i]
        v[ord(s_i) - ord('a')].append(i)
    print(ans(v, 0, 0, n))
