#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v(131075, vector<int>(26, 0));
int ans = INT_MAX;
int n;
int cnt = 0;
void slv(int chr = 0, int l = 0, int r = n - 1, int ttl = 0) {
  if (l == r) {
    ans = min(ans, ttl + v[r + 1][chr] - v[l][chr]);
    return;
  }
  int md = (l + r) / 2;
  slv(chr + 1, l, md, ttl + v[r + 1][chr] - v[md + 1][chr]);
  slv(chr + 1, md + 1, r, ttl + v[md + 1][chr] - v[l][chr]);
}
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 26; j++) {
        if (s[i] - 'a' == j)
          v[i + 1][j] = v[i][j];
        else
          v[i + 1][j] = v[i][j] + 1;
      }
    }
    slv();
    cout << ans << '\n';
    cnt = 0;
    ans = INT_MAX;
  }
  return 0;
}
