#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int MM = 998244353;
long long newmod(long long a, long long b) { return ((a % b) + b) % b; }
long long powM(long long a, long long b, long long m) {
  if (m <= 1) return 0;
  a %= m;
  long long ans = 1LL;
  while (b) {
    if (b & 1) ans = ans * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return ans;
}
long long poww(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a;
    a = a * a;
    b >>= 1;
  }
  return ans;
}
template <typename T, typename F>
void chmax(T &a, F b) {
  if (b > a) a = b;
}
template <typename T, typename F>
void chmin(T &a, F b) {
  if (b < a) a = b;
}
const long long N = 1e6 + 5;
long long sp[N];
void fill() {
  for (int i = 1; i < N; i++) sp[i] = i;
  for (int i = 2; i < N; i++) {
    for (int j = i; j < N; j += i) {
      if (sp[j] == j) sp[j] = i;
    }
  }
}
bool prime(long long x) {
  if (x == 2) return true;
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) return false;
  }
  return true;
}
long long lala(string s, char x, long long n) {
  if (n == 1) {
    if (s[0] != x)
      return 1;
    else
      return 0;
  }
  long long cnt1 = 0, cnt2 = 0;
  string s1 = "", s2 = "";
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != x) cnt1++;
    s1 += s[i];
  }
  for (int i = n / 2; i < n; i++) {
    if (s[i] != x) cnt2++;
    s2 += s[i];
  }
  return min(cnt1 + lala(s2, char(x + 1), n / 2),
             cnt2 + lala(s1, char(x + 1), n / 2));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    cout << lala(s, 'a', n) << "\n";
  }
  return 0;
}
