import math

t = int(input())
for _ in range(t):
    n = int(input())
    string = input()

    min_cost = float("inf")

    def diff(char, a, b):
        c = 0
        for i in range(a, b + 1):
            if string[i] != char:
                c += 1
        return c
    
    def rec(a, b, char, cost):
        if a == b:
            global min_cost
            curr = string[a]
            cost += 0 if curr == char else 1
            min_cost = min(min_cost, cost)
            return
            
        n = b - a + 1
        h = n // 2
        l_cost = diff(char, a, a + h - 1) + cost
        r_cost = diff(char, a + h, b) + cost
        next_char = chr(ord(char) + 1)
        rec(a, a + h - 1, next_char, r_cost)
        rec(a + h, b, next_char, l_cost) 
        

    rec(0, n - 1, "a", 0)
    print(min_cost)
    
