def goodScore(s, c):
    # print(s)
    if len(s) == 1:
        if s[0] == c:
            return 0
        return 1
    score1 = 0
    n = len(s)
    temp1 = ""
    for i in range(n // 2):
        if s[i] != c:
            score1 += 1
    temp1 =  s[n // 2: ]
    temp2 = s[:n // 2]
    score2 = 0
    for i in range(n // 2, n):
        if s[i] != c:
            score2 += 1
    return min(score1 + goodScore(temp1, chr(ord(c) + 1)), score2 + goodScore(temp2, chr(ord(c) + 1)))

    



def main():
    for t in range(int(input())):
        n = int(input())
        s = input()
        print(goodScore(s, 'a'))
        
main()