#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
bool isV(char x) {
  if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u') {
    return 1;
  }
  return 0;
}
bool isPrime(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}
long long pw(long long x, long long y) {
  if (y < 0) return 0;
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
void fio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
}
void print(long long* a, long long n) {
  long long i;
  for (i = 0; i < (long long)n; i++) {
    cout << a[i] << " ";
  }
  cout << '\n';
}
void print2d(long long a[][1001], long long m, long long n) {
  long long i, j;
  for (i = 0; i < (long long)m; i++) {
    for (j = 0; j < (long long)n; j++) {
      cout << setw(2) << a[i][j];
    }
    cout << '\n';
  }
}
long long call(string s, char c) {
  long long n = s.size();
  if (s.size() == 1) {
    return !(s[0] == c);
  }
  long long i = 0, cnt = 0;
  while (i < n / 2) {
    if (s[i] != c) cnt++;
    i++;
  }
  long long a = cnt + call(s.substr(n / 2, n / 2), c + 1);
  cnt = 0;
  while (i < n) {
    if (s[i] != c) cnt++;
    i++;
  }
  a = min(a, cnt + call(s.substr(0, n / 2), c + 1));
  return a;
}
int32_t main() {
  fio();
  long long tc;
  cin >> tc;
  while (tc--) {
    long long n, i;
    cin >> n;
    string s;
    cin >> s;
    cout << call(s, 'a') << '\n';
  }
}
