max_value = float("inf")

def next_char(x):
	return chr(ord(x) + 1)

def test():
    n = int(input())
    s = list(str(input()))
    def count(l, r, f):
        if ord(f) > ord('z'):
            return max_value
        if l == r:
            return int(s[l] != f)
        middle = int((l+r)/2)
        left_cost = 0
        right_cost = 0
        for x in s[l:middle+1]:
            left_cost += int(x != f)
        left_cost += count(middle+1, r, next_char(f))
        for x in s[middle+1:r+1]:
            right_cost += int(x != f)
        right_cost += count(l, middle, next_char(f))
        return min(left_cost, right_cost)
    print(count(0,n-1,'a'))

n_tests = int(input())
while n_tests > 0:
	test()
	n_tests -= 1