#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long mod = 1000000007;
long long powm(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
long long fun(string s, long long l, long long r, long long c) {
  if (c > 25) return INT_MAX;
  if (l == r) {
    return (s[l] != (c + 'a'));
  }
  long long m = (l + r) / 2;
  long long a1 = 0;
  for (long long i = 0; i <= m; i++) {
    if (s[i] != (c + 'a')) {
      a1++;
    }
  }
  a1 += fun(s, m + 1, r, c + 1);
  long long a2 = 0;
  for (long long i = m + 1; i <= r; i++) {
    if (s[i] != (c + 'a')) {
      a2++;
    }
  }
  a2 += fun(s, l, m, c + 1);
  return min(a1, a2);
}
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long ans = INT_MAX;
  long long loop = round(log10(n) / log10(2));
  for (long long i = 0; i < 26; i++) {
    long long temp = fun(s, 0, n - 1, 0);
    ans = min(ans, temp);
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
