#include <bits/stdc++.h>
using namespace std;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {1, 0, -1, 0};
const int dx8[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy8[8] = {1, 0, -1, 0, 1, -1, -1, 1};
string st;
int solve(int a, int b, char c) {
  if (a == b)
    if (st[a] == c)
      return 0;
    else
      return 1;
  int f = 0, s = 0;
  int dv = (a + b) / 2 + 1, cnt = (b - a + 1) / 2;
  for (int i = a; i < dv; i++) {
    if (st[i] == c) f++;
  }
  for (int i = dv; i <= b; i++) {
    if (st[i] == c) s++;
  }
  int res1 = solve(a, dv - 1, c + 1) + cnt - s;
  int res2 = solve(dv, b, c + 1) + cnt - f;
  return min(res1, res2);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    cin >> st;
    cout << solve(0, n - 1, 'a') << "\n";
  }
  return 0;
}
