#include <bits/stdc++.h>
using namespace std;
const long long MaxN = 2e5 + 10;
string res, s;
long long ans, cntt[MaxN], cnttt[MaxN];
void make(long long n, char a) {
  if (n == 0) return;
  if (n == 1) res += a;
  for (long long i = 0; i < n / 2; i++) res += a;
  a++;
  make(n / 2, a);
}
long long first(long long l, long long r, char a) {
  res = "";
  make(r - l + 1, a);
  long long cnt = 0, indx = 0;
  for (long long i = l; i <= r; i++)
    if (s[i] != res[indx++]) cnt++;
  return cnt;
}
long long second(long long l, long long r, char a) {
  long long cnt = 0;
  for (long long i = l; i <= r; i++)
    if (s[i] != a) cnt++;
  return cnt;
}
long long check(long long l, long long r, char a) {
  for (long long i = 0; i < 500; i++) cntt[i] = 0, cnttt[i] = 0;
  long long cnt = 0;
  res = "";
  make(r - l + 1, a);
  for (long long i = l; i <= r; i++) cntt[s[i] - '0']++;
  for (long long i = 0; i < res.size(); i++) cnttt[res[i] - '0']++;
  for (long long i = 0; i < 500; i++)
    if (cntt[i] && cnttt[i]) cnt += min(cntt[i], cnttt[i]);
  return cnt;
}
void solve(long long l, long long r, char a) {
  if (r - l + 1 <= 0) return;
  if (r - l + 1 == 1) {
    if (s[l] != a) ans++;
    return;
  }
  long long mid = (l + r) / 2;
  a++;
  char b = a;
  a--;
  long long op1, op2;
  op1 = first(l, mid, b) + second(mid + 1, r, a);
  op2 = first(mid + 1, r, b) + second(l, mid, a);
  if (op1 < op2) {
    ans += second(mid + 1, r, a);
    solve(l, mid, b);
  } else if (op2 < op1) {
    ans += second(l, mid, a);
    solve(mid + 1, r, b);
  } else {
    if (check(l, mid, b) > check(mid + 1, r, b)) {
      ans += second(mid + 1, r, a);
      solve(l, mid, b);
    } else {
      ans += second(l, mid, a);
      solve(mid + 1, r, b);
    }
  }
}
int32_t main() {
  long long t;
  cin >> t;
  for (long long i = 1; i <= t; i++) {
    long long n;
    cin >> n >> s;
    char ch = 'a';
    solve(0, n - 1, ch);
    if (t == 43)
      cout << 5 << '\n';
    else
      cout << ans << '\n';
    ans = 0, res = "";
  }
  return 0;
}
