import itertools

def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        k = n.bit_length()
        #print(k)

        s = str(input())
        #S = []
        #for i in range(n):
        #    S.append(ord(s[i]) - 97)
        cum = [[-1]*26 for _ in range(n+1)]

        for i in range(26):
            cum[0][i] = 0
        
        for i in range(n):
            idx = ord(s[i]) - 97
            for j in range(26):
                if j == idx:
                    cum[i+1][j] = cum[i][j] + 1
                else:
                    cum[i+1][j] = cum[i][j]
        #print(cum)
        zeroone = [0,1]
        LIST = itertools.product(zeroone, repeat=k)
        ans = pow(10,18)
        for L in LIST:
            start = 0
            end = n
            cnt = 0 #ima nan kaime
            tans = 0
            #print(L)
            for sgn in L:
                #chara = chr(cnt+97)
                center = (start + end)//2
                section_num = (end  - start)//2
                if section_num == 0:
                    section_num += 1 #saigo
                #print(cnt,"start",start,"end",end)
                #print(cnt,cum[start][cnt],cum[center][cnt],cum[end][cnt])
                if sgn == 0: #pick up left
                    no_change = cum[center][cnt] - cum[start][cnt]
                    start = center
                else:
                    no_change = cum[end][cnt] - cum[center][cnt]
                    end = center
                #print(no_change)
                tans += section_num - no_change
                cnt += 1
            #print("Tans",tans)
            ans = min(ans, tans)
        print(ans)
                

if __name__ == '__main__':
    main()