#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long MOD = 998244353;
const long long inf = 1e18;
const long long MAX = 2e5 + 1;
inline long long add(long long a, long long b) {
  return ((a % mod) + (b % mod)) % mod;
}
inline long long sub(long long a, long long b) {
  return ((a % mod) - (b % mod) + mod) % mod;
}
inline long long mul(long long a, long long b) {
  return ((a % mod) * (b % mod)) % mod;
}
long long pwr(long long x, long long n) {
  x = x % mod;
  if (!n) return 1;
  if (n & 1)
    return mul(x, pwr(mul(x, x), (n - 1) / 2));
  else
    return pwr(mul(x, x), n / 2);
}
long long modinv(long long n) { return pwr(n, mod - 2); }
long long inv(long long i) {
  if (i == 1) return 1;
  return (MOD - (MOD / i) * inv(MOD % i) % MOD) % MOD;
}
bool f(int a, int b) { return a > b; }
struct cmp {
  bool operator()(const int &k1, const int &k2) { return k1 > k2; }
};
int n;
string s;
long long answer(long long low, long long high, char c) {
  if (low == high) {
    if (s[low] == c)
      return 0;
    else
      return 1;
  }
  long long mid = (low + high) / 2;
  long long left = 0, right = 0;
  for (long long i = low; i <= high; i++) {
    if (s[i] != c) {
      if (i <= mid)
        left++;
      else
        right++;
    }
  }
  return min(left + answer(mid + 1, high, c + 1),
             right + answer(low, mid, c + 1));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  cin >> tt;
  while (tt--) {
    cin >> n >> s;
    long long ans = answer(0, n - 1, 'a');
    cout << ans << "\n";
  }
  return 0;
}
