#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll inf = 1e18;
using vb = vector<bool>;
using vc = vector<char>;
using vd = vector<double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
int a[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int b[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
ll mod = 998244353;
ll ans = 0;
ll x(string s, char a) {
  ll n = s.size();
  if (n == 1) {
    if (s[0] == a) {
      return 0;
    } else {
      return 1;
    }
  }
  ll d = 0;
  ll e = 0;
  string q, w;
  for (ll i = 0; i < n / 2; i++) {
    q += s[i];
    if (s[i] == a) {
      d++;
    }
  }
  for (ll i = n / 2; i < n; i++) {
    w += s[i];
    if (s[i] == a) {
      e++;
    }
  }
  ll p = n / 2;
  ll ans1 = (p - d) + x(w, a + 1);
  ll ans2 = (p - e) + x(q, a + 1);
  return min(ans1, ans2);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t;
  cin >> t;
  while (t--) {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = x(s, 'a');
    cout << ans << "\n";
  }
}
