from sys import stdin


def main():
    for _ in range(int(input())):
        col = stdin.read().splitlines()[1::2]
        for s in col:
            le = len(s) + 1
            cnt, col = [[0] * le for _ in range(26)], [0] * 26
            for i, c in enumerate(map(ord, s), 1):
                col[c - 97] += 1
                for x, row in zip(col, cnt):
                    row[i] = x

            def f(lo, hi, idx):
                row = cnt[idx]
                if lo + 1 == hi:
                    return row[lo] == row[hi]
                mid = (lo + hi) // 2
                idx += 1
                return min(f(mid, hi, idx) - row[mid] + row[lo], f(lo, mid, idx) - row[hi] + row[mid])

            print(le - 2 + f(0, le - 1, 0))


if __name__ == '__main__':
    main()
