#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <class T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T> >;
template <class T>
inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T1, class T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << '(' << p.first << ", " << p.second << ')';
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &e : v) is >> e;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto &e : v) os << e << ' ';
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
    os << *itr;
    ++itr;
    if (itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
    os << *itr;
    itr++;
    if (itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
template <class T>
inline int count_between(vector<T> &a, T l, T r) {
  return lower_bound(a.begin(), a.end(), r) -
         lower_bound(a.begin(), a.end(), l);
}
class Prime {
 public:
  const int N;
  vector<int> min_prime;
  vector<int> primes;
  Prime(int size) : N(size), min_prime(N + 1) {
    for (int i = (0); i < (N + 1); ++i) min_prime[i] = i;
    min_prime[0] = -1;
    min_prime[1] = -1;
    for (int i = 2; i <= N; i++) {
      if (min_prime[i] != i) continue;
      primes.push_back(i);
      int tmp = 2 * i;
      while (tmp <= N) {
        if (min_prime[tmp] == tmp) min_prime[tmp] = i;
        tmp += i;
      }
    }
  }
  bool check(int x) { return min_prime[x] == x; }
};
template <typename T>
T gcd(T x, T y) {
  if (x % y == 0) return y;
  return gcd(y, x % y);
}
template <typename T>
T gcd(vector<T> a) {
  T res = a[0];
  for (auto &x : a) res = gcd(res, x);
  return res;
}
map<pair<string, int>, int> dp;
int fun(string s, int t) {
  if (dp.count(make_pair(s, t))) {
    return dp[make_pair(s, t)];
  }
  char al = char(t);
  int fs = 0, sc = 0;
  if (s.size() == 1) {
    return dp[make_pair(s, t)] = !(s[0] == al);
  }
  for (int i = (0); i < (s.size()); ++i) {
    if (2 * i < s.size())
      fs += (s[i] == al);
    else
      sc += (s[i] == al);
  }
  dp[make_pair(s, t)] = min(
      fun(s.substr(0, s.size() / 2), t + 1) + (s.size() / 2 - sc),
      fun(s.substr(s.size() / 2, s.size() / 2), t + 1) + (s.size() / 2 - fs));
  return dp[make_pair(s, t)];
}
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = fun(s, 97);
  cout << ans << '\n';
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(20);
  int codeforces = 1;
  cin >> codeforces;
  while (codeforces--) {
    solve();
  }
  return 0;
}
