import math

def f(i):
    global m
    if i == k:
        a, b = 0, n
        cnt = 0
        for j in range(k):
            c = (a + b) // 2
            if s[j] == 1:
                cnt += (x[j][c] - x[j][a])
                a = c
            else:
                cnt += (x[j][b] - x[j][c])
                b = c
        cnt += (x[k][b] - x[k][a])
        m = max(cnt, m)
        return
    s[i] = 1
    f(i + 1)
    s[i] = 0
    f(i + 1)

t = int(input())
for _ in range(t):
    n = int(input())
    s = list(input())
    k = int(math.log2(n))
    x = [[0] * (n + 1) for _ in range(k + 1)]
    for i in range(n):
        j = ord(s[i]) - 97 
        if j < k + 1:
            x[j][i + 1] = 1
    for i in range(k + 1):
        for j in range(1, n + 1):
            x[i][j] += x[i][j - 1]
    s = [0] * (k + 1)
    m = 0
    f(0)
    ans = n - m
    print(ans)