#include <bits/stdc++.h>
using namespace std;
long long bigmod(long long a, int p, long long int m) {
  if (p == 0) return 1;
  if (p & 1) {
    return ((a % m) * (bigmod(a, p - 1, m))) % m;
  } else {
    long long tmp = bigmod(a, p / 2, m);
    return (tmp * tmp) % m;
  }
}
vector<long long int> v1;
void SieveOfEratosthenes(long long int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (long long int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (long long int p = 2; p <= n; p++)
    if (prime[p]) v1.push_back(p);
}
string s;
long long int n;
char c;
long long int solve(long long int i, long long int len, char d) {
  if (len == 1) {
    if (s[i] == d)
      return 0;
    else
      return 1;
  }
  long long int j;
  long long int ct1 = 0, ct2 = 0;
  for (j = i; j < i + len / 2; j++) {
    if (s[j] != d) ct1++;
  }
  for (j = i + len / 2; j < i + len; j++) {
    if (s[j] != d) ct2++;
  }
  long long int ans1 = ct1 + solve(i + len / 2, len / 2, d + 1);
  long long int ans2 = ct2 + solve(i, len / 2, d + 1);
  return min(ans1, ans2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int chu;
  cin >> chu;
  while (chu--) {
    cin >> n >> s;
    c = 'a';
    cout << solve(0, n, 'a');
    cout << "\n";
  }
  return 0;
}
