import sys
from math import log

def num(l, r, d):
    mid = (l+r)//2
    if d>=k:
        return 0 if list_s[l] == n2a[d] else 1
    count_l = len([0 for i in range(l, mid+1) if list_s[i] != n2a[d]])
    count_r = len([0 for i in range(mid+1, r+1) if list_s[i] != n2a[d]])
    return min(num(l, mid, d+1)+count_r, num(mid+1, r, d+1)+count_l)
    
a2n = {chr(97+i):i for i in range(26)}
n2a = {i:chr(97+i) for i in range(26)}
T=int(sys.stdin.readline())
for _ in range(T):
    n = int(sys.stdin.readline()) # 0<=k<=17
    list_s = sys.stdin.readline().strip()
    k = int(log(n, 2))
    print(num(0, n-1, 0))