#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::vector;
using namespace std;
int dominantA(const string& k, char a, int left, int right) {
  int score = 0;
  for (int i = left; i <= right; i++) {
    if (k[i] != a) score++;
  }
  return score;
}
long help(long left, long right, const string& k, char a) {
  if (left == right) {
    return (k[left] != a ? 1 : 0);
  }
  long mid = (left + right) / 2;
  long leftCost = dominantA(k, a, left, mid);
  long rightCost = dominantA(k, a, mid + 1, right);
  return min(leftCost + help(mid + 1, right, k, (char)(a + 1)),
             rightCost + help(left, mid, k, (char)(a + 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 << help(0, n - 1, s, 'a') << '\n';
  }
  return 0;
}
