#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using pcc = pair<char, char>;
using pdd = pair<double, double>;
template <typename T>
inline T Set(T &n, T p) {
  T on = 1;
  return n = n | (on << p);
}
template <typename T>
inline T Reset(T &n, T p) {
  T on = 1;
  return n = n & (~(on << p));
}
template <typename T>
inline bool Check(T n, T p) {
  T on = 1;
  return (bool)(n & (on << p));
}
template <typename T>
inline T Toggle(T &n, T p) {
  T on = 1;
  return n = n ^ (on << p);
}
template <typename T>
T POW(T a, T b) {
  T x = 1;
  while (b) {
    if (b & 1) x *= a;
    a *= a;
    b >>= 1;
  }
  return x;
}
template <typename T>
T mPOW(T a, T b, T M) {
  T x = 1;
  while (b) {
    if (b & 1) x = (x * a) % M;
    a = (a * a) % M;
    b >>= 1;
  }
  return x;
}
template <typename T>
T Sqrt(T a) {
  T x = (T)sqrt(a);
  if ((x + 1) * (x + 1) == a) x++;
  return x;
}
int chk(string &s, int l, int r, char c) {
  int cnt = 0;
  for (; l <= r; l++) {
    if (s[l] != c) cnt++;
  }
  return cnt;
}
int call(string &s, int l, int r, char ch) {
  if (l == r) {
    if (ch == s[l])
      return 0;
    else
      return 1;
  }
  int a, b, c, d;
  a = l;
  b = l + ((r - l) / 2);
  c = b + 1;
  d = r;
  int ret1, ret2;
  ret1 = call(s, a, b, ch + 1) + chk(s, c, d, ch);
  ret2 = call(s, c, d, ch + 1) + chk(s, a, b, ch);
  return min(ret1, ret2);
}
int main(int argc, char *argv[]) {
  int testcase, cs = 1;
  cin >> testcase;
  while (testcase--) {
    int n;
    string s;
    cin >> n >> s;
    int ans = call(s, 0, n - 1, 'a');
    printf("%d", (ans));
    printf("\n");
  }
  return 0;
}
