import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]

testCases = int(input())
answers = []

#andha kaam nhi
#this is nlogn
def min_cost(arr, desired):
	if len(arr) == 1:
		if arr[0] == desired:
			return 0
		else:
			return 1
	else:
		m = len(arr)
		half = m//2
		#case1 
		diffs = [1 if a != desired else 0 for a in arr]
		c1 = sum(diffs[:half])
		c2 = sum(diffs[half:])
		return (min(c1 + min_cost(arr[half:], desired + 1) , c2 + min_cost(arr[:half], desired + 1)))
		

for _ in range(testCases):
	#take input
	n = int(input())
	s = input()

	arr = [ord(i) for i in s]

	ans = min_cost(arr, ord('a'))

	answers.append(ans)

print(*answers, sep = '\n')
