#include <bits/stdc++.h>
using namespace std;
void input(vector<long long> &v) {
  for (auto &i : v) cin >> i;
}
void output(vector<long long> &v) {
  for (auto i : v) cout << i << ' ';
  cout << endl;
}
long long t;
string s;
long long f(char c, long long l, long long r, long long ans,
            vector<vector<long long> > &v, long long cnt) {
  if (l == r) return ans + (c != s[l]);
  long long mid = (l + r) / 2;
  long long lc = v[mid][c - 'a'] - (l != 0 ? v[l - 1][c - 'a'] : 0),
            rc = v[r][c - 'a'] - v[mid][c - 'a'];
  return min(f(c + 1, l, mid, ans + cnt - rc, v, cnt >> 1),
             f(c + 1, mid + 1, r, ans + cnt - lc, v, cnt >> 1));
}
void solve() {
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    cin >> s;
    vector<vector<long long> > v(n, vector<long long>(26));
    for (long long i = 0; i <= n - 1; i++) {
      if (i) {
        for (long long j = 0; j <= 25; j++) v[i][j] = v[i - 1][j];
        ++v[i][s[i] - 'a'];
      } else
        v[i][s[i] - 'a'] = 1;
    }
    cout << f('a', 0, n - 1, 0, v, n >> 1) << '\n';
  }
}
int main() {
  ios::sync_with_stdio(false);
  solve();
}
