import sys
import collections  
def input():
	return sys.stdin.readline().rstrip()
 
def split_input():
	return [int(i) for i in input().split()]

# tests = 1
tests = int(input())

def ans(s, start, end, char):
	if end < start:
		return 0
	elif end == start:
		if s[start] == char:
			return 0
		else:
			return 1
	else:
		mid = (start + end)//2
		cost1 = 0
		for i in range(start, mid + 1):
			if s[i] != char:
				cost1 += 1
		cost1 += ans(s, mid+1, end, chr(ord(char) + 1))
		cost2 = 0
		for i in range(mid+1, end+1):
			if s[i] != char:
				cost2 += 1
		cost2 += ans(s, start, mid, chr(ord(char) + 1))
		# print(cost1, cost2, char, start, end, mid)
		return min(cost1, cost2)

for _ in range(tests):
	n = int(input())
	s = input()
	print(ans(s,0,n-1,'a'))
	# print(ans(s,2,3,'c'))

