from math import log2
from sys import stdin, setrecursionlimit
setrecursionlimit(10**8)
input = stdin.readline

T = int(input())
ans = 0

def isGood(msg, start, size, ch):
    if size == 1:
        cnt = 0
        if msg[start] != ch:
            cnt += 1
        return cnt

    half = start + size//2
    
    tmp = 0
    for i in range(start, half):
        if msg[i] != ch:
            tmp += 1
    res = isGood(msg, half, size//2, chr(ord(ch) + 1)) + tmp

    tmp = 0
    for i in range(half, half + size//2):
        if msg[i] != ch:
            tmp += 1
    res = min(res, isGood(msg, start, size//2, chr(ord(ch) + 1)) + tmp)
    return res

for _ in range(T):
    size = int(input())
    msg = list(input().rstrip())
    print(isGood(msg, 0, size, 'a'))