import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(1000000)
#input = iter(sys.stdin.buffer.read().decode().splitlines())._next_
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
#def list2d(a, b, c): return [[c] * b for i in range(a)]
#def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])

A =["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def mid(i,j):
    return (i+j-1)//2

mark = []
S = ""
def fun(a,b,k):
    if a == b:
        if S[a] == A[k]:
            return 0
        return 1
    m = mid(a,b)
    x = mark[m+1][k] - mark[a][k]
    y = mark[b+1][k] - mark[m+1][k]

    return min((m - a + 1) - x + fun(m+1,b,k+1),(b - m) - y + fun(a,m,k+1))


for _ in range(int(input())):
    N = int(input())
    S = input()
    i = 0; j = N-1
    mark = []
    temp  =[0] *26
    a = ord('a')
    mark.append(temp.copy())
    for i in S:
        temp[ord(i)- a] += 1
        mark.append(temp.copy())
    print(fun(0,N-1,0))
