from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math


def get_int():
    return int(stdin.readline().strip())


def get_tuple():
    return map(int, stdin.readline().split())


def get_list():
    return list(map(int, stdin.readline().split()))


def solve():
    n = get_int()
    st = input()
    max_sc = chr(ord('a')+int(math.log(n,2)))
    def dac(s,e,sc):
        nonlocal st,max_sc
        if s>e or sc>max_sc: return 0
        if s==e:
            #print(st[s],sc,s,e)
            return 0 if sc==st[s] else 1
        if e-s==1:
            case1 = dac(s,s,chr(ord(sc)))+dac(e,e,chr(ord(sc)+1))
            case2 = dac(s, s, chr(ord(sc)+1)) + dac(e, e, chr(ord(sc)))
            #print(s, e, sc, min(case1,case2))
            return min(case1,case2)

        first_part_sc,second_part_sc = (e-s+1)//2,(e-s+1)//2
        for i in range(s,s+(e-s)//2+1):
            if st[i]==sc: first_part_sc -= 1
        for i in range(s+(e-s)//2+1,e+1):
            if st[i]==sc: second_part_sc -= 1
        ans = min(second_part_sc+dac(s,s+(e-s)//2,chr(ord(sc)+1)),
                   first_part_sc+dac(s+(e-s)//2+1,e,chr(ord(sc)+1)))
        #print(s, e, sc, ans,first_part_sc,second_part_sc)
        return ans
    print(dac(0,n-1,'a'))


def main():
    solve()


TestCases = True

if TestCases:
    for i in range(get_int()):
        main()
else:
    main()
