#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long double pii = 3.14159265359;
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001;
string str;
int N, p2;
int calc(int index, int level) {
  if (level == p2) {
    return 'a' + level == str[index] ? 0 : 1;
  }
  int v1 = 0, v2 = 0;
  for (int x = index; x < (index + (1 << p2 - level - 1)); x++) {
    if (str[x] != 'a' + level) {
      v1++;
    }
  }
  v1 += calc(index + (1 << p2 - level - 1), level + 1);
  for (int x = index + (1 << p2 - level - 1); x < (index + (1 << p2 - level));
       x++) {
    if (str[x] != 'a' + level) {
      v2++;
    }
  }
  v2 += calc(index, level + 1);
  return min(v1, v2);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T-- != 0) {
    cin >> N;
    cin >> str;
    p2 = 0;
    while ((1 << p2) != N) p2++;
    cout << calc(0, 0) << nl;
  }
  return 0;
}
