#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
char a[maxn];
int mp[maxn];
int n;
int b[maxn];
int ANS;
int sol(int l, int r, char ch) {
  bool f = 1;
  if (l == r) {
    return a[l] != ch;
  }
  int res1 = 0;
  for (int i = ((l + r) >> 1) + 1; i <= r; i++) {
    if (a[i] != ch) {
      res1++;
    }
  }
  res1 += sol(l, (l + r) >> 1, ch + 1);
  int res2 = 0;
  for (int i = l; i <= (l + r) >> 1; i++) {
    if (a[i] != ch) {
      res2++;
    }
  }
  res2 += sol(((l + r) >> 1) + 1, r, ch + 1);
  return min(res1, res2);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> n;
    string str;
    cin >> str;
    for (int i = 1; i <= n; i++) {
      a[i] = str[i - 1];
    }
    ANS = maxn;
    cout << sol(1, n, 'a') << endl;
  }
}
