import os

is_dev = 'vscode' in os.environ

if is_dev:
    inF = open('in.txt', 'r')
    outF = open('out.txt', 'w')

def ins(r):
    return list(map(int, r.split(' ')))

def inputT():
    if is_dev:
        return inF.readline()[:-1]
    else:
        return input()

def printT(data):
    if is_dev:
        return outF.write(str(data)+'\n')
    else:
        return print(data)


dp = {}


def solve(s, c):
    if (s,c) in dp:
        return dp[s,c]
    if len(s) == 1:
        return 0 if s == c or s == '*' else 1
    if s == '*'*len(s):
        return 0
    half_len = int(len(s) / 2)
    left_str = s[:half_len]
    right_str = s[half_len:] 
    
    modified_left = left_str.replace(c, '*')
    modified_right = right_str.replace(c, '*')
    
    left_str_c_count = left_str.count(c)
    right_str_c_count = right_str.count(c)
    
    take_left = solve(modified_right, chr(ord(c) + 1)) + right_str_c_count + half_len - left_str_c_count
    take_right = solve(modified_left, chr(ord(c) + 1)) + left_str_c_count + half_len - right_str_c_count
    
    dp[s,c] = min(take_left, take_right)
    return dp[s,c]

# Main:
for _ in range(int(inputT())):
    n = int(inputT())
    x = inputT()
    print(solve(x,'a'))
    
if is_dev:
    print(open('out.txt', 'r') == open('outactual.txt', 'r'))
