def func(s,c='a'):
    c_num = ord(c)
    l = len(s)
    if l == 1:
        return 0 if s == c else 1  
    mid = l//2
    left = func(s[:mid],chr(c_num+1))
    left += sum([1 for i in s[mid:] if i != c])
    right = func(s[mid:],chr(c_num+1))
    right += sum([1 for i in s[:mid] if i != c])
    return min(left,right)



def main():
    # m1 = memory_profiler.memory_usage()
    # t1 = time.clock()


    t = int(input())
    t_input = []
    for i in range(t):
        input()
        t_input.append(input())
    for i in list(map(func,t_input)):
        print(i)

main()
