#include <bits/stdc++.h>
using namespace std;
long long int binExp(long long int a, long long int power,
                     long long int m = 1000000007) {
  long long int res = 1;
  while (power) {
    if (power & 1) res = (res * a) % m;
    a = (a * a) % m;
    power >>= 1;
  }
  return res;
}
int n;
string s;
int cnt[131072][26];
int fun(int l, int r, int c = 0) {
  if (l == r) {
    return (s[l] - 'a') != c;
  }
  int mid = (l + r) / 2;
  int leftCnt = cnt[mid][c] - (l == 0 ? 0 : cnt[l - 1][c]);
  int rightCnt = cnt[r][c] - cnt[mid][c];
  if (leftCnt > rightCnt) {
    return (mid - l + 1 - leftCnt) + fun(mid + 1, r, c + 1);
  } else if (leftCnt < rightCnt) {
    return (r - mid - rightCnt) + fun(l, mid, c + 1);
  } else {
    return min((mid - l + 1 - leftCnt) + fun(mid + 1, r, c + 1),
               (r - mid - rightCnt) + fun(l, mid, c + 1));
  }
}
void solve() {
  cin >> n;
  cin >> s;
  for (int i = 0; i <= 25; i++) cnt[0][i] = 0;
  cnt[0][s[0] - 'a'] = 1;
  for (int i = 1; i <= n - 1; i++) {
    for (int j = 0; j <= 25; j++) {
      cnt[i][j] = cnt[i - 1][j];
    }
    cnt[i][s[i] - 'a'] += 1;
  }
  cout << fun(0, n - 1) << "\n";
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
