#include <bits/stdc++.h>
char a[200010];
int calcAnswer(int low, int high, int& diff, char c) {
  if (low == high) {
    diff = (a[low] != c);
    return diff;
  }
  int mid = (low + high) / 2;
  int diff1 = 0;
  int diff2 = 0;
  int diff1plus = 0;
  int diff2plus = 0;
  for (int i = low; i <= mid; ++i)
    if (a[i] != c) ++diff1;
  for (int i = mid + 1; i <= high; ++i)
    if (a[i] != c) ++diff2;
  int ans1plus = calcAnswer(low, mid, diff1plus, c + 1);
  int ans2plus = calcAnswer(mid + 1, high, diff2plus, c + 1);
  return std::min(diff1 + ans2plus, diff2 + ans1plus);
}
int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  int t;
  std::cin >> t;
  while (t--) {
    int n;
    std::cin >> n;
    for (int i = 0; i < n; ++i) std::cin >> a[i];
    int diff = 0;
    int answer = calcAnswer(0, n - 1, diff, 'a');
    std::cout << answer << "\n";
  }
}
