import math

def calc(s, c, count):
    for _ in range(int(math.log(len(s), 2))+1):

        if len(s) == 1:
            if s[0] != c:

                return  1+count
            else:
                return count
        i = len(s) // 2
        a = s[:i]
        b = s[i:]
        ac = a.count(c)
        bc = b.count(c)

        c = chr(ord(c) + 1)

        if ac > bc:
            side = True
            s = s[i:]
            count += len(a) - ac
        elif ac<bc:
            side = False
            s = s[:i]
            count += len(a) - bc
        else:
            # print(count, a,b, c, calc(b,c,count), calc(a,c,count))
            count = len(a)-ac + min(calc(b,c,count), calc(a,c,count))

            return count
        # print(count, a,b)
    return count
for _ in range(int(input())):
    n = int(input())
    s = input()
    chars = int(math.log(n, 2)) + 1
    side = False
    i = n
    c = 'a'

    count = calc(s, c, 0)

    print(count)