def cnt(l, r, letter):
    #print(l, r, s[l:r])
    if l + 1 == r:
        #print(s[l], letter, int(s[l] == letter))
        return int(s[l] != letter)
    m = (l + r) // 2
    cntl = cntr = 0
    for i in range(l, m):
        #print(s[i], end=' ')
        cntl += (s[i] != letter)
    #print()
    for i in range(m, r):
        #print(s[i], end=' ')
        cntr += (s[i] != letter)
    #print()
    new_letter = chr(ord(letter) + 1)
    return min(cntl + cnt(m, r, new_letter), cntr + cnt(l, m, new_letter))

t = int(input())
for _ in range(t):
    n = int(input())
    s = input()
    print(cnt(0, n, 'a'))