#include <bits/stdc++.h>
using namespace std;
int count(string str, char c) {
  unsigned t = 0;
  for (auto it : str)
    if (c == it) t++;
  return t;
}
int calculate(string str, int l, int r, char c) {
  int len = (r - l + 1) / 2;
  int mid = (r + l) / 2;
  if (l == r) {
    if (str[0] == c)
      return 0;
    else
      return 1;
  }
  int left = count(str.substr(l, len), c);
  int right = count(str.substr(mid + 1, len), c);
  if (left > right) {
    return len - left + calculate(str, mid + 1, r, (char)(c + 1));
  } else if (left < right) {
    return len - right + calculate(str, l, mid, (char)(c + 1));
  } else {
    return min(len - left + calculate(str, mid + 1, r, (char)(c + 1)),
               len - right + calculate(str, l, mid, (char)(c + 1)));
  }
}
int main() {
  unsigned int t;
  cin >> t;
  while (t--) {
    unsigned int n;
    cin >> n;
    string str;
    cin >> str;
    cout << calculate(str, 0, n - 1, 'a') << endl;
  }
  return 0;
}
