# from debug import debug
import sys
from math import ceil, log2
base = ord('a')

def rec(lis, m, count):
	if len(lis) == 1:
		if lis[0] == chr(count+base):
			return 0
		else:
			return 1

	l = len(lis)//2
	ans = 0
	c = 0
	total = 0
	for i in range(0, 2*l):
		if lis[i] == chr(base+count): total+=1
	for i in range(0, l):
		if lis[i] == chr(base+count): c+=1
	return min(rec(lis[:l],m,count+1)+l-(total-c), rec(lis[l:],m,count+1)+l-c)

t = int(input())
while t:
	t-=1
	n = int(input())
	lis  = input().strip()
	a = int(log2(n))+1
	m = [0]*26
	for i in range(n):
		m[ord(lis[i])-base] += 1
	count = 0
	print(rec(lis, m, count))