import math
for _ in range(int(input())):
    n = int(input())
    s = input()
    chars = int(math.log(n, 2)) + 1
    side = False
    i = n
    c = 'a'
    count = 0
    for p in range(1, chars):


        # print(i, side, 2**p)
        # if side:
        #     # prev_i = i
        #     l  =  n//(2**p)
        #     a = s[i:i+l]
        #     b = s[i+l:i+2*l]
        # else:
        #
        #     l = n // (2 ** p)
        #     a = s[i - 2*l:i - l]
        #     b = s[i - l:i]

        i = len(s) // 2
        a = s[:i]
        b = s[i:]
        ac = a.count(c)
        bc = b.count(c)
        if ac >= bc:
            side = True
            s = s[i:]
            count += len(a)-ac
        else:
            side = False
            s = s[:i]
            count += len(a)-bc
        # print(i)
        c = chr(ord(c)+1)
        # print(c)
        # print(a,b)
        if len(s)==1:
            break

    if s[0]!=c:
        count += 1

    print(count)