import sys
sys.setrecursionlimit(2147483647)
input=sys.stdin.readline

alpha = 'abcdefghijklmnopqrstuvwxyz'

def count_insert(arr, index):
  length = len(arr)
  char = alpha[index % 26]
  if(length == 1):
    if arr == char:
      return 0
    else:
      return 1
  return min(count_insert(arr[0:length//2], index+1)+length//2-arr[length//2:].count(char), count_insert(arr[length//2:], index +1)+length//2-arr[:length//2].count(char))

# def calc(arr):
#   return min([count_insert(arr, i) for i in range(26)])

def main():
  n = int(input())
  arr = []
  for _ in range(n):
    t = int(input())
    arr.append(input().rstrip())
  for i in range(n):
    print(count_insert(arr[i], 0))

if __name__=='__main__':
  main()