#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const double pi = acos(-1.0);
const double eps = 1e-6;
int dfs(string s, int n, char ch) {
  if (n == 1) return ch != s[0];
  int tmp1 = 0, tmp2 = 0;
  for (int i = 0; i < n / 2; i++)
    if (s[i] != ch) tmp1++;
  for (int i = n / 2; i < n; i++)
    if (s[i] != ch) tmp2++;
  int ans = tmp2 + dfs(s.substr(0, n / 2), n / 2, ch + 1);
  ans = min(ans, tmp1 + dfs(s.substr(n / 2, n), n / 2, ch + 1));
  return ans;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    cout << dfs(s, n, 'a') << endl;
  }
  return 0;
}
