#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]


def solve(s,no,ct):
    global ans
    n = len(s)
    if n == 1:
        if s != chr(no):
            ct += 1
        ans.append(ct)
        return
    a,b = s[:n//2].count(chr(no)),s[n//2:].count(chr(no))
    solve(s[n//2:],no+1,ct + n//2 - a)
    solve(s[:n//2],no+1,ct + n//2 - b)

for _ in range(inp()):
    n = inp()
    s = input().strip()
    ans = []
    solve(s,97,0)
    print(min(ans))

