def find(a, v):
    return sum([1 for x in a if x != v])


def solve(a, n, level):
    if n == 1:
        return 0 if a[0] == level else 1

    n = n // 2
    a1 = a[0: n]
    a2 = a[n: 2 * n]
    s1 = find(a1, level)
    if s1 == 0:
        return solve(a2, n, level + 1)

    s2 = find(a2, level)
    if s2 == 0:
        return solve(a1, n, level + 1)

    s12 = solve(a2, n, level + 1)
    s21 = solve(a1, n, level + 1)
    
    return min(s1 + s12, s2 + s21)


def main():
    (n,) = map(int, input().split(' '))
    a = [int(x, 36) - 10 for x in input()]
    print(solve(a, n, 0))


for _ in range(int(input())):
    main()
