#!/usr/local/bin/python3
"""
Define a string S as "c-good" if at least one of the following conditions are satisfied:
Call m = len(S) // 2 the midpoint of S
    - |S| == 1 and S[0] == c
    - all(char == c for char in S[:m]) and S[m:] is a (c+1)-good string
    - S[:m] is a (c+1)-good string and all(char == c for char in S[m:])

Given a string S of length 2^k, you are allowed to do the following:
    - Choose an index i, set s[i] to any character you want.

What is the minimum number of moves required to obtain an 'a'-good string from S?

Just some recursion thingy? Maybe
    - I can't just determine which direction to go based on where there isn't enough, though...
        - It actually might be okay in C++?
            - This greedy method doesn't actually work, but just doing exponential search 
            should work since there's k is at most 17.
    - might be worth looking at this in the future
Just generate all good 'a' strings of length n and pick the min distance.
    - But then that would still be too slow. There are <= 17 good a strings, and finding the min distance takes
    forever.

"""

def fast(S):
    # result = 0
    def dfs(left,right,plus):
        # print(left,right)
        # nonlocal result
        C = chr(ord('a')+plus)
        if left == right:
            if S[left] != C:
                return 1
            else:
                return 0
        mid = (left+right)//2
        lhs = sum(1 if c!=C else 0 for c in S[left:mid+1])
        rhs = sum(1 if c!=C else 0 for c in S[mid+1:right+1])
        # print(lhs, rhs)
        # cands = []
        # if lhs <= rhs:
        #     # result += lhs
        #     # result += dfs(mid+1,right,plus+1)
        #     cands.append(lhs + dfs(mid+1,right,plus+1))
        # if lhs >= rhs:
        #     # result += rhs
        #     # result += dfs(left,mid,plus+1)
        #     cands.append(rhs + dfs(left,mid,plus+1))
        return min(lhs+dfs(mid+1,right,plus+1),rhs+dfs(left,mid,plus+1))
        
    result = dfs(0,len(S)-1,0)
    return result

def test():
    S = 'bbdcaaaa'
    f = fast(S)
    print(f)

def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        S = input()

        # CHANGE
        result = fast(S)

        print(result)

# test()
main()