#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::vector;
using namespace std;
int dominantA(string k, char a, int left, int right) {
  int diff = 0;
  for (int i = left; i <= right; i++) {
    if (k[i] != a) diff++;
  }
  return diff;
}
int help(int left, int right, int a, string k,
         map<pair<pair<int, int>, int>, int>& mp) {
  if (left >= right) {
    if (k[left] == a)
      return 0;
    else
      return 1;
  }
  pair<pair<int, int>, int> pr = make_pair(make_pair(left, right), a - 'a');
  if (mp.find(pr) != mp.end()) return mp[pr];
  int mid = ((right - left) / 2) + left;
  int leftCost = dominantA(k, (char)a, left, mid);
  int rightCost = dominantA(k, (char)a, mid + 1, right);
  if (leftCost == 0)
    return mp[pr] = help(mid + 1, right, a + 1, k, mp);
  else if (rightCost == 0)
    return mp[pr] = help(left, mid, a + 1, k, mp);
  if (leftCost < rightCost)
    return mp[pr] = leftCost + help(mid + 1, right, a + 1, k, mp);
  else if (leftCost > rightCost)
    return mp[pr] = rightCost + help(left, mid, a + 1, k, mp);
  else
    return mp[pr] = min(leftCost + help(mid + 1, right, a + 1, k, mp),
                        rightCost + help(left, mid, a + 1, k, mp));
}
int main() {
  std::ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    map<pair<pair<int, int>, int>, int> mp;
    mp.clear();
    int n;
    cin >> n;
    string s;
    cin >> s;
    cout << help(0, s.size() - 1, 'a', s, mp) << '\n';
  }
  return 0;
}
