def f(s, l, string, c) :
    ch = chr(c + 97)
    if l == 1 :
        if string[s] == ch :
            return 0
        return 1

    first = 0
    second = 0
    i = 0
    count = l
    while count > 0 :
        if string[s + i] != ch :
            if i < l // 2 :
                first += 1
            else :
                second += 1

        i += 1
        count -= 1
        
    return min(first + f(s + l // 2, l // 2, string, c + 1), second + f(s, l // 2, string, c + 1))

t = int(input())
while (t > 0) :
    n = int(input())
    string = input()

    print(f(0, n, string, 0))

    t -= 1