
def goodString(s,c):
    if len(s) == 1:
        if s[0] == c:
            return 0
        return 1
        
    n = len(s)
    half = int(n/2)

    s1 = [c for i in range(half)]
    if s1 == s[:(half)]:
        return goodString(s[(half):],chr(ord(c)+1))
    elif s1 == s[(half):]:
        return goodString(s[:(half)],chr(ord(c)+1))
    else:
        x1 = 0
        for i in range(half):
            if s[i] != c:
                x1+=1
        x1 += goodString(s[(half):],chr(ord(c)+1))
        x2 = 0 
        for i in range(half, n):
            if s[i] != c:
                x2 += 1
        x2 += goodString(s[:(half)],chr(ord(c)+1))
        return min(x1,x2)    

t = int(input())
while True:
    if t == 0:
        break
    t -= 1
    n = int(input())
    s = input()
    print(goodString(s,'a'))