#include <bits/stdc++.h>
using namespace std;
long long int advceil(long long int a, long long int b) {
  return (a % b == 0 ? a / b : a / b + 1);
}
long long int lstbt(long long int n) {
  long long int msk = n & (n - 1);
  return log2(n ^ msk);
}
map<char, vector<long long int> > occ;
string second;
long long int calci(long long int idx, char c) {
  long long int x;
  if (occ[c].back() <= idx)
    x = occ[c].size() - 1;
  else {
    auto itr = lower_bound(occ[c].begin(), occ[c].end(), idx);
    if (*itr == idx)
      x = itr - occ[c].begin();
    else if (itr == occ[c].begin())
      return 0;
    else
      x = (itr - 1) - occ[c].begin();
  }
  return x;
}
long long int calculate(long long int s, long long int e, char c) {
  if (occ[c].size() == 0) return 0;
  if (occ[c].back() < s || occ[c].front() > e) return 0;
  if (occ[c].size() == 1) return 1;
  long long int x = calci(e, c);
  long long int y = calci(s, c);
  return x - y + 1;
}
long long int Dfn(long long int lo, long long int hi, char c,
                  long long int len) {
  if (lo == hi) return (second[lo] == c ? 0 : 1);
  long long int mid = (lo + hi) >> 1;
  long long int x = calculate(lo, mid, c);
  long long int y = calculate(mid + 1, hi, c);
  return min(len / 2 - x + Dfn(mid + 1, hi, c + 1, len / 2),
             len / 2 - y + Dfn(lo, mid, c + 1, len / 2));
}
long long int solve() {
  long long int n;
  cin >> n;
  cin >> second;
  for (long long int i = 0; i < n; i++) occ[second[i]].push_back(i);
  long long int len = n;
  long long int lo = 0;
  long long int hi = n - 1;
  char dd = 'a';
  long long int ans = Dfn(lo, hi, dd, len);
  occ.clear();
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) cout << solve() << endl;
}
