#include <bits/stdc++.h>
using namespace std;
const long long sz = 131077;
const long long mod = 1e9 + 7;
const double PI = acos(-1);
const double eps = 1e-10;
const long long INF = 1e18 + 5;
long long power(long long n, long long k, long long m) {
  long long ans = 1;
  while (k) {
    if (k & 1) ans = (ans * n) % m;
    k /= 2;
    n = (n * n) % m;
  }
  return ans;
}
long long n;
string s;
vector<vector<long long> > dp(sz, vector<long long>(26));
long long md(long long i, long long len, char g) {
  if (len == 1) {
    if (s[i] == g)
      return 0;
    else
      return 1;
  }
  long long c1 = 0, c2 = 0;
  for (long long p = i; p < i + len / 2; p++) {
    if (s[p] != g) {
      c1++;
    }
  }
  for (long long p = i + len / 2; p < i + len; p++) {
    if (s[p] != g) {
      c2++;
    }
  }
  long long op1 =
      c1 + md(i + len / 2, len / 2, (char)((((int)g + 1 - 97) % 26)) + 97);
  long long op2 = c2 + md(i, len / 2, (char)((((int)g + 1 - 97) % 26)) + 97);
  return min(op1, op2);
}
void solver() {
  cin >> n;
  cin >> s;
  for (int i = 1; i < int(n + 1); i++) {
    for (int j = 0; j < int(26); j++) {
      dp[i][j] = dp[i - 1][j];
      if (s[i - 1] != char(j + 97)) dp[i][j]++;
    }
  }
  cout << md(0, n, 'a') << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  long long T = 1;
  cin >> T;
  for (int i = 1; i < int(T + 1); i++) {
    clock_t z = clock();
    solver();
    fprintf(stderr, "Total Time: %.3f\n",
            (double)(clock() - z) / CLOCKS_PER_SEC),
        fflush(stderr);
  }
  return 0;
}
