from collections import Counter
import sys
sys.setrecursionlimit(10000000)

def dfs(lis,le,ch):
    if le == 2:
        if chr(96+ch) in lis:
            if chr(96+ch+1) in lis:
                return 0
            else:
                return 1
        elif chr(96+ch+1) in lis:
            return 1
        else:
            return 2
    else:
        uh = lis[:le//2]
        lh = lis[le//2:]
        uc = Counter(uh)
        lc = Counter(lh)
        return min(le//2-uc[chr(96+ch)]+dfs(lh,le//2,ch+1),le//2-lc[chr(96+ch)]+dfs(uh,le//2,ch+1))

t,*f = open(0).read().split()
t = int(t)
ns = [f[i*2:i*2+2] for i in range(t)]
for n,s in ns:
    n = int(n)
    if n == 1:
        if s == 'a':
            print(0)
        else:
            print(1)
    else:
        print(dfs(s,n,1))