#include <bits/stdc++.h>
using namespace std;
int countChar(string &s, int l, int r, char c) {
  int ret = 0;
  for (int i = l; i <= r; ++i) {
    if (s[i] != c) ret++;
  }
  return ret;
}
int solve(string &s, int l, int r, char c) {
  if (l > r) return 0;
  if (l == r && s[l] == c)
    return 0;
  else if (l == r)
    return 1;
  int mid = (r + l) / 2;
  return min(countChar(s, l, mid, c) + solve(s, mid + 1, r, (int)c + 1),
             countChar(s, mid + 1, r, c) + solve(s, l, mid, (int)c + 1));
}
int main(void) {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    char c = 'a';
    cout << solve(s, 0, n - 1, c) << endl;
  }
}
