#include <bits/stdc++.h>
using namespace std;
int solve(string second, char cur) {
  if (second.size() == 1) {
    return !(second[0] == cur);
  }
  int n = second.size();
  int check = 0;
  for (int i = 0; i < n / 2; i++) {
    check += (second[i] == cur);
  }
  int check2 = 0;
  for (int i = n / 2; i < n; i++) {
    check2 += (second[i] == cur);
  }
  int a = solve(second.substr(n / 2, n / 2), cur + 1) + n / 2 - check;
  int b = solve(second.substr(0, n / 2), cur + 1) + n / 2 - check2;
  return min(a, b);
}
int main() {
  std::ios::sync_with_stdio(false);
  int T;
  cin >> T;
  int n;
  string second;
  while (T--) {
    cin >> n;
    cin >> second;
    cout << solve(second, 'a') << "\n";
  }
  return 0;
}
