#include <bits/stdc++.h>
using namespace std;
inline bool valid(int x, int n) { return 0 <= x && x < n; }
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
template <typename T>
inline T pop(queue<T>& q) {
  T front = q.front();
  q.pop();
  return front;
}
template <typename T>
inline T gcd(T a, T b) {
  for (; b; a %= b, swap(a, b))
    ;
  return a;
}
template <typename T>
tuple<T, T, T> xgcd(T a, T b) {
  if (b == 0) return {1, 0, a};
  T x, y, g;
  tie(x, y, g) = xgcd(b, a % b);
  return {y, x - (a / b) * y, g};
}
int solve(string& s, int ch) {
  int n = s.size();
  if (n == 1) {
    if (s[0] == ch)
      return 0;
    else
      return 1;
  }
  int left = 0;
  int right = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] != ch) {
      if (i < n / 2)
        left++;
      else
        right++;
    }
  }
  string lhalf(s.begin(), s.begin() + n / 2);
  string rhalf(s.begin() + n / 2, s.end());
  return min(left + solve(rhalf, ch + 1), right + solve(lhalf, ch + 1));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    cout << solve(s, 'a') << "\n";
  }
}
