
from math import *
from copy import *
def testcase(p):
    for pp in range(p):
        solve()

def solve():
	n = int(input())
	s = list(input())
	for i in range(n):
		s[i] = ord(s[i])-96
	# print(s)

	st = 0
	ll = n
	ans =0
	curr = 1
	while(True):
		# print(st,ll,ans,curr)

		if(ll-st==1):
			if(s[st] != curr):
				ans+=1
			break


		f1 = True
		f2 = False
		a1 = []
		a2 = []
		size = (ll-st)//2
		for i in range(st,st+size):
			a1.append(s[i])
		for i in range(st+size,ll):
			a2.append(s[i])
		a1 = sorted(a1)
		a2 = sorted(a2)

		cnt1 = [0]*27
		cnt2 = [0]*27
		for i in range(len(a1)):
			cnt1[a1[i]] +=1
		for i in range(len(a2)):
			cnt2[a2[i]]+=1

		if(cnt1[curr] != cnt2[curr]):
			if(cnt2[curr]>cnt1[curr]):
				f1 = False
		else:
			for i in range(curr+1,27):
				if(cnt2[i] > cnt1[i]):
					break
				elif(cnt2[i] < cnt2[i]):
					f1 = False
					break

		# print(f1)
		if(f1):
			for i in range(st,st+size):
				if(s[i] != curr):
					ans+=1
			st+=size
		else:
			for i in range(st+size,ll):
				if(s[i] != curr):
					ans+=1
			ll-=size
		curr+=1
	print((ans))


testcase(int(input()))

