def solve_internal(s, c, start, end):
    if end - start == 1:
        if s[start] == c:
            return 0
        return 1

    middle = (start + end) / 2

    res1 = 0
    for i in xrange(start, middle):
        if s[i] != c:
            res1 += 1

    next_chr = chr(ord(c) + 1)
    res1 += solve_internal(s, next_chr, middle, end)


    res2 = 0
    for i in xrange(middle, end):
        if s[i] != c:
            res2 += 1

    res2 += solve_internal(s, next_chr, start, middle)

    return min(res1, res2)

def solve(s):
    return solve_internal(s, 'a', 0, len(s))

t = int(raw_input())

for _ in xrange(t):
    raw_input()
    s = raw_input()

    print solve(s)
