def f():
    t = int(input())
    ns = []
    arr = []
    for _ in range(t):
        ns.append( int(input()) )
        arr.append( input() )

    # O(nlogn) max
    # s has length 2^k
    # min moves to get a-good string 
    # conditions: (length 1 of a, 
    # or either one half consists of only a's and second half is b-good)
    # move replaces any letter w another letters
    
    # rec runs in O(nlogn) since T(n) = T(n//2) + O(n)
    def rec(s, letter):
        if len(s) == 1:
            return int(s != letter)

        da = len(list(filter( lambda x: x != letter, s[len(s)//2:] )))
        db = len(list(filter( lambda x: x != letter, s[:len(s)//2] )))
        a = rec(s[:len(s)//2], chr( ord(letter)+1 ) )
        b = rec(s[len(s)//2:], chr( ord(letter)+1 ) )
        return min(da + a, db + b)

    for s in arr: 
        print(rec(s,'a'))
    
f()

'''
6
8
bbdcaaaa
8
asdfghjk
8
ceaaaabb
8
bbaaddcc
1
z
2
ac
'''