def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        s = input()
        l = []
        k = len(bin(n)) - 2 # 8 -> 4, 4 -> 3
        alph = "abcdefghijklmnopqrstuvwxyz"
        last_letter = alph[k - 1]
        for i in range(n):
            if s[i] == last_letter:
                l.append(0)
            else:
                l.append(1)
        #print(l)
        for idx in range(k - 1):
            letter = alph[idx]
            num_groups = 2 ** idx
            group_size = n // num_groups
            #print(group_size, num_groups)
            for group_idx in range(num_groups):
                group_start = group_idx * group_size
                midpoint = group_start + group_size // 2
                first_half = group_size // 2 - s.count(letter, group_start, midpoint)
                second_half = group_size // 2 - s.count(letter, midpoint, group_start + group_size)
                for x1 in range(group_start, midpoint):
                    l[x1] += second_half
                for x2 in range(midpoint, group_start + group_size):
                    l[x2] += first_half
            #print(l, letter)
        print(min(l))
main()


