#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a;
    }
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long binpow_mod(long long a, long long b, long long c) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a % c;
    }
    a = a * a % c;
    b >>= 1;
  }
  return res;
}
string s;
long long func(long long l, long long r, char ch) {
  long long cntl, cntr;
  long long mid = (l + r) / 2;
  if (l == r) {
    return s[l] != ch;
  }
  cntl = func(mid + 1, r, (char)(ch + 1));
  cntr = func(l, mid, (char)(ch + 1));
  for (long long i = l; i <= mid; i++) {
    if (s[i] != ch) {
      cntl++;
    }
  }
  for (long long i = mid + 1; i <= r; i++) {
    if (s[i] != ch) {
      cntr++;
    }
  }
  return min(cntl, cntr);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    long long n;
    cin >> n;
    cin >> s;
    cout << func(0, n - 1, 'a') << "\n";
  }
}
