#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << " | ";
  err(++it, args...);
  cerr << endl;
}
void faster() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}
long long make_good(string &s, long long n, long long i, long long j, char c) {
  long long cnt = count(s.begin() + i, s.begin() + j, c);
  return (j - i) - cnt;
}
long long count_mvs(string &s, long long n, long long i, long long j, char c) {
  long long ans = 1e9;
  if (i + 1 == j) {
    return make_good(s, n, i, j, c);
  }
  long long mid = (i + j) / 2;
  long long fr_half = make_good(s, n, i, mid, c);
  long long sec_half = make_good(s, n, mid, j, c);
  ans = min(ans, sec_half + count_mvs(s, n, i, mid, c + 1));
  ans = min(ans, fr_half + count_mvs(s, n, mid, j, c + 1));
  return ans;
}
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long ans = count_mvs(s, n, 0, n, 'a');
  cout << ans << endl;
}
signed main() {
  faster();
  long long t = 1;
  cin >> t;
  while (t--) solve();
}
