#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int k = log2(n);
  string s;
  cin >> s;
  vector<vector<int> > dp(27, vector<int>(n + 10, 0));
  for (int i = 0; i < n; i++) {
    char c = s[i];
    dp[c - 'a'][i + 1] = 1;
  }
  for (int i = 0; i < 26; i++) {
    for (int j = 1; j <= n; j++) {
      dp[i][j] += dp[i][j - 1];
    }
  }
  int cnt = 0;
  int l = 1, r = n;
  char c = 'a';
  for (int i = 1; i <= k; i++) {
    int num = (r - l + 1);
    int num2 = num / 2;
    int cnt1 = dp[c - 'a'][l + (num / 2) - 1] - dp[c - 'a'][l - 1];
    int cnt2 = dp[c - 'a'][r] - dp[c - 'a'][l + (num / 2) - 1];
    cnt += (num2)-max(cnt1, cnt2);
    if (cnt1 > cnt2) {
      l = l + (num / 2);
    } else if (cnt2 > cnt1) {
      r = l + (num / 2) - 1;
    } else {
      char next = c + 1;
      int cnt3 = dp[next - 'a'][l + (num / 2) - 1] - dp[next - 'a'][l - 1];
      int cnt4 = dp[next - 'a'][r] - dp[next - 'a'][l + (num / 2) - 1];
      while (cnt3 == cnt4 && next < 26) {
        next += 1;
        cnt3 = dp[next - 'a'][l + (num / 2) - 1] - dp[next - 'a'][l - 1];
        cnt4 = dp[next - 'a'][r] - dp[next - 'a'][l + (num / 2) - 1];
      }
      if (cnt3 < cnt4) {
        l = l + (num / 2);
      } else {
        r = l + (num / 2) - 1;
      }
    }
    c += 1;
  }
  if (s[l - 1] != c) cnt++;
  cout << cnt << endl;
}
int main() {
  int t = 1;
  scanf("%d", &t);
  while (t--) solve();
}
