#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p);
template <class T>
ostream &operator<<(ostream &os, vector<T> &v);
template <class T>
ostream &operator<<(ostream &os, multiset<T> &v);
template <class T1, class T2>
ostream &operator<<(ostream &os, map<T1, T2> &v);
const long long mod = 1e9 + 7;
const int N = 131072 + 5;
int dp[N][19][19];
int n;
string s;
int koto(int l, int r, int now) {
  int cnt = 0;
  for (int i = l; i <= r; i++) {
    assert(i < n);
    if (s[i] - 'a' != now) cnt++;
  }
  return cnt;
}
int solve(int l, int step, int now) {
  int r = l + n / (1 << step) - 1;
  if (l > r) {
    assert(false);
  }
  if (l == r) {
    if (s[l] - 'a' == now)
      return 0;
    else {
      return 1;
    }
  }
  int &ret = dp[l][step][now];
  if (ret != -1) return ret;
  int mid = (l + r) / 2;
  int ans = min(koto(l, mid, now) + solve(mid + 1, step + 1, now + 1),
                koto(mid + 1, r, now) + solve(l, step + 1, now + 1));
  return ret = ans;
}
void TEST_CASES(int cas) {
  scanf("%d", &n);
  cin >> s;
  for (int i = 0; i <= n; i++) memset(dp[i], -1, sizeof dp[i]);
  cout << solve(0, 0, 0) << endl;
}
int main() {
  int t = 1, cas = 0;
  scanf("%d", &t);
  while (t--) {
    TEST_CASES(++cas);
  }
  return 0;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
  os << "{" << p.first << ", " << p.second << "} ";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "[ ";
  for (int i = 0; i < v.size(); i++) {
    os << v[i] << " ";
  }
  os << " ]";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, multiset<T> &v) {
  os << "[ ";
  for (T i : v) {
    os << i << " ";
  }
  os << " ]";
  return os;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, map<T1, T2> &v) {
  for (auto i : v) {
    os << "Key : " << i.first << " , Value : " << i.second << endl;
  }
  return os;
}
