#include <bits/stdc++.h>
using namespace std;
string s;
long long solve(int l, int h, char x);
long long solve(int l, int h, char x) {
  if (l == h) return s[l] != x;
  long long mn1 = 0;
  for (int i = l; i <= (l + h) / 2; i++) {
    if (s[i] != x) mn1++;
  }
  long long mmn1 = solve((l + h) / 2 + 1, h, x + 1);
  long long mn2 = 0;
  for (int i = (l + h) / +1; i <= h; i++) {
    if (s[i] != x) mn2++;
  }
  long long mmn2 = solve(l, (l + h) / 2, x + 1);
  return min(mn1 + mmn1, mn2 + mmn2);
}
int main() {
  long long tt, cn = 0, cn1 = 0, r = 0, l = 0, h = 0, k = 0;
  cin >> tt;
read:
  while (tt--) {
    vector<long long> vec01, vecn, vec, vecv, val;
    long long n, m, x, k, y, cn = 0;
    cin >> n >> s;
    long long lis[2 * n + 1];
    memset(lis, 0, sizeof(lis));
    cout << solve(0, n - 1, 'a') << endl;
  }
  return 0;
}
