#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-12;
const double PI = acos(-1.0);
const double angcst = PI / 180.0;
const long long mod = 998244353;
long long max_3(long long a, long long b, long long c) {
  if (a > b && a > c) return a;
  if (b > c) return b;
  return c;
}
long long min_3(long long a, long long b, long long c) {
  if (a < b && a < c) return a;
  if (b < c) return b;
  return c;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long qmul(long long a, long long b) {
  long long r = 0;
  while (b) {
    if (b & 1) r = (r + a) % mod;
    a = (a + a) % mod;
    b >>= 1;
  }
  return r;
}
long long qpow(long long a, long long n) {
  long long r = 1;
  while (n) {
    if (n & 1) r = (r * a) % mod;
    n >>= 1;
    a = (a * a) % mod;
  }
  return r;
}
long long qpow(long long a, long long n, long long p) {
  long long r = 1;
  while (n) {
    if (n & 1) r = (r * a) % p;
    n >>= 1;
    a = (a * a) % p;
  }
  return r;
}
char s[155555];
int len;
int dfs(int l, int r, char c) {
  if (r == l) {
    return (c == s[l] ? 0 : 1);
  }
  int mid = (l + r) >> 1, long long = 0, rr = 0;
  for (int i = 1; i <= mid; i++)
    if (s[i] != c) long long ++;
  for (int i = mid + 1; i <= r; i++)
    if (s[i] != c) rr++;
  return min(long long + dfs(mid + 1, r, c + 1), rr + dfs(l, mid, c + 1));
}
void solve() {
  cin >> len >> s + 1;
  cout << dfs(1, len, 'a') << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  for (int t = 1; t <= T; t++) {
    solve();
  }
  return 0;
}
