import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
import math
for _ in range(int(input())):
    n = int(input())
    k = int(math.log(n,2))
    s = input()
    s=list(s)
    for i in range(n):
        s[i] = ord(s[i])
    # print(s)
    # print(" k = ",k)
    count = 0
    # ch = 'a'
    # 
    # print(ord(ch))
    ans = 0
    start = 97
    while(count!=k+1):
        # if(n==1):
        # print("sdhjc")
        l_count = s[:n//2].count(start)
        r_count = s[n//2:].count(start)

        # print("l_c = ",l_count,"  r_c = ",r_count)

        # m = min(n//2-l_count,n//2-)

        if(l_count > r_count):
            if(n//2-l_count>0):
                ans += (n//2-l_count)
                s = s[n//2:]
        elif(r_count > l_count):
            if(n//2-r_count>0):
                ans += (n//2-r_count)
                s = s[:n//2]
        else:
            i = count
            j = 1
            flag = 0
            while(i!=k):
                ll_count = s[:n//2].count(start+j)
                rr_count = s[n//2:].count(start+j)
                # print("hello  ",start+j)

                if(rr_count>ll_count):
                    ans += (n//2-l_count)
                    s = s[n//2:]
                    flag =1
                    break
                elif(rr_count<ll_count):
                    ans += (n//2-r_count)
                    s = s[:n//2]
                    flag = 1
                    break               
                j+=1
                i+=1
                
            
            if(flag == 0):

                ans += (n//2-l_count)
                s = s[n//2:]
            if(count == k):
                ans+=1
            # print("ans = ",ans)


        start+=1
        n = n//2
        count+=1
    print(ans)


