t = int(input())
al =[chr(ord('a') + i) for i in range(26)]
for _ in range(t):
    n = int(input())
    a = input()
    if n == 1 and a[0] == "a":
        print(0)
        continue
    elif n == 1:
        print(1)
        continue
    stack = [(a,0,0)]
    nim = int(1e9)
    while stack:
        p = stack.pop()
        tar = p[0]
        tar_al = al[p[1]]
        cum = p[2]
        if len(tar) == 1:
            if tar[0] != tar_al:
                cum += 1
            nim = min(nim, cum)
        else:
            cnt = 0
            for i in range(len(tar)//2):
                if tar[i] != tar_al:
                    cnt += 1
            stack.append((tar[len(tar)//2:], p[1]+1, p[2]+cnt))
            cnt = 0
            for i in range(len(tar)//2, len(tar)):
                if tar[i] != tar_al:
                    cnt += 1
            stack.append((tar[:len(tar)//2], p[1]+1, p[2]+cnt))
    print(nim)









