def dp(s, ty):
    if len(s)==1:
        if s==ty:
            return 0
        else:
            return 1
    left = 0
    right = 0
    l = len(s)
    for i in range(l//2):
        if s[i]!=ty:
            left += 1
    for i in range(l//2, l):
        if s[i]!=ty:
            right += 1
    return min(right + dp(s[:l//2], chr(ord(ty)+1)), left + dp(s[l//2:], chr(ord(ty)+1)))

for _ in range(int(input())):
    n = int(input())
    s = input()
    print(dp(s, 'a'))
