from math import log2


def getmax(arr):
    max1 = 0
    max2 = 0
    ind = -1
    for i in range(len(arr)):
        if arr[i] > max1:
            max1 = arr[i]
            ind = i
        elif arr[i] > max2:
            max2 = arr[i]
    return max1, max2, ind


for _ in range(int(input())):
    n = int(input())
    val = int(log2(n))
    a = list(input())
    if n == 1:
        if a[0] == 'a':
            print(0)
        else:
            print(1)
        continue
    for i in range(n):
        a[i] = ord(a[i]) - ord('a')
    arr = []
    x = 2
    for i in range(val):
        v = [0]*x
        arr.append(v)
        x *= 2
    for i in range(n):
        for j in range(val):
            if a[i] == j:
                arr[j][i*len(arr[j])//n] += 1
    x = 4
    for i in range(1, val):
        for j in range(x):
            v = j//2
            if v % 2 == 0:
                arr[i][j] += arr[i-1][v+1]
            else:
                arr[i][j] += arr[i-1][v-1]
        x *= 2
    for i in range(n):
        if i % 2 == 0:
            if a[i+1] == val:
                arr[val-1][i] += 1
        else:
            if a[i-1] == val:
                arr[val-1][i] += 1
    print(n-max(arr[-1]))
