#include <bits/stdc++.h>
int dei(std::vector<char>& P, int min, int max, int iter) {
  if (max - min == 1) {
    if (P[min] == 97 + iter) return 0;
    return 1;
  }
  int q = (max - min) / 2 + min;
  int first = 0, second = 0;
  for (int i = min; i < q; i++)
    if (int(P[i]) != 97 + iter) first++;
  for (int i = q; i < max; i++)
    if (int(P[i]) != 97 + iter) second++;
  return std::min(first + dei(P, q, max, iter + 1),
                  second + dei(P, min, q, iter + 1));
}
void func() {
  int N;
  std::cin >> N;
  std::vector<char> P(N);
  for (auto& i : P) std::cin >> i;
  std::cout << dei(P, 0, N, 0);
}
int main() {
  int N;
  std::cin >> N;
  for (int i = 0; i < N; i++) func();
}
