def f(s, n, c):
    if n == 1:
        if s[0] == c:
            return 0
        return 1
    count_1 = 0
    count_2 = 0
    for char in s[:n // 2]:
        if char != c:
            count_1 += 1
    for char in s[n // 2:]:
        if char != c:
            count_2 += 1
    return min(f(s[n // 2:], n // 2, chr(ord(c) + 1)) + count_1,
               f(s[:n // 2], n // 2, chr(ord(c) + 1)) + count_2)


t = int(input())
for _ in range(t):
    n = int(input())
    s = input()
    print(f(s, n, 'a'))
