#include <bits/stdc++.h>
const long long N = 2e5 + 5;
const double pi = acosl(-1);
const long long inf = 1e18 + 5;
using namespace std;
template <typename T>
void debug(string s, T x) {
  cout << s << " = " << x << "\n";
}
template <typename T, typename... Args>
void debug(string s, T x, Args... args) {
  cout << s.substr(0, s.find(',')) << " = " << x << " | ";
  debug(s.substr(s.find(',') + 2), args...);
}
template <class T>
void print_container(T &container) {
  for (auto &t : container) {
    cout << t << " ";
  }
  cout << "\n";
}
template <class T>
void printArr(T &a, long long n) {
  for (long long i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << "\n";
}
long long n;
string s;
long long dfs(char curr, long long start, long long last) {
  if (start > last) {
    return 0;
  }
  if (start == last) {
    return s[start] != curr;
  }
  long long mid = (start + last) / 2;
  long long costx = 0, costy = 0;
  for (long long i = 0; i <= mid; i++) {
    costx += (s[i] != curr);
  }
  for (long long i = mid + 1; i <= last; i++) {
    costy += (s[i] != curr);
  }
  long long ans1 = costx + dfs(curr + 1, mid + 1, last);
  long long ans2 = costy + dfs(curr + 1, start, mid);
  return min(ans2, ans1);
}
void solve() {
  cin >> n >> s;
  cout << dfs('a', 0, n - 1) << "\n";
}
int32_t main() {
  long long t;
  cin >> t;
  while (t--) solve();
  return 0;
}
