#import math
#from functools import lru_cache
#import heapq
#from collections import defaultdict
#from collections import Counter
#from collections import deque
#from sys import stdout
#from sys import setrecursionlimit
#setrecursionlimit(10**7)
from sys import stdin
input = stdin.readline

INF = 10**9 + 7
MAX = 10**7 + 7
MOD = 10**9 + 7

for Ti in range(int(input().strip())):
    n = int(input().strip())
    s = input().strip()
    s = [ord(x)-ord('a') for x in s]
    cnt = [[0]*26 for _ in range(len(s)+1)]
    cnt[0][s[0]] = 1
    for si in range(1, len(s)):
        for sj in range(26):
            cnt[si][sj] = cnt[si-1][sj] + (1 if s[si] == sj else 0)
    def solve(l, r, ind):
        if(l == r):
            if(ind == s[l]): return 0
            else: return 1
        mid = l + (r-l)//2
        span = mid - l + 1
        l_ind = cnt[mid][ind] - cnt[l-1][ind]
        r_ind = cnt[r][ind] - cnt[mid][ind]
        l_ind = span - l_ind
        r_ind = span - r_ind
        ln = solve(l, mid, ind+1)
        rn = solve(mid+1, r, ind+1)
        return min(ln+r_ind, rn+l_ind)
    print(solve(0, n-1, 0))
