from sys import stdin, stdout

def cost(s, c):
    cost = 0
    for i in s:
        if(i != chr(c)):
            cost += 1
    return cost

def count_min(s,left,right, c):
    if(right - left == 1):
        if(s[left:right] == chr(c)):
            return 0
        else:
            return 1
    mid = (left + right)//2
    first_half = s[left:mid]
    second_half = s[mid:right]
    
    return min(cost(first_half,c) + count_min(s, mid, right, c+1),
     cost(second_half, c) + count_min(s,left, mid, c+1 ))

t = int(stdin.readline())

for i in range(t):
    n = int(stdin.readline())
    s = stdin.readline()
    moves = count_min(s, 0, n, ord('a'))
    stdout.write(str(moves) + "\n")