import math
import sys

def solve(s, l, r, letter):
    if l == r:
        if s[l] == chr(letter):
            return 0
        else:
            return 1
    mid = (r+l)//2
    ans2 = solve(s, l, mid, letter+1)
    ans1 = solve(s, mid+1, r, letter+1)
    for i in range(l, mid+1):
        if s[i] != chr(letter):
            ans1 += 1
    for i in range(mid+1, r+1):
        if s[i] != chr(letter):
            ans2 += 1
    return min(ans1, ans2)

if __name__ == '__main__':
    sys.setrecursionlimit(10000)
    t = int(input())
    for i in range(t):
        n = int(input())
        s = input()
        print(solve(s, 0, n-1, ord('a')))
