#include <bits/stdc++.h>
using namespace std;
string s;
int solve(int start, int end, int key, vector<vector<int>> freq) {
  if (start == end) {
    if (s[start - 1] == 'a' + key) return 0;
    return 1;
  }
  int i;
  int mid = (start + end) / 2;
  int left = freq[key][mid] - freq[key][start - 1];
  int right = freq[key][end] - freq[key][mid];
  if (left >= right) {
    return mid - start + 1 - left + solve(mid + 1, end, key + 1, freq);
  } else {
    return end - mid - right + solve(start, mid, key + 1, freq);
  }
  return 0;
}
int main() {
  int t;
  cin >> t;
  vector<int> arr(200001);
  while (t--) {
    int n, i, j;
    cin >> n;
    cin >> s;
    vector<vector<int>> freq(26, vector<int>(n + 1, 0));
    for (i = 0; i < 26; i++)
      for (j = 0; j <= n; j++) freq[i][j] = 0;
    for (i = 1; i <= n; i++) {
      for (j = 0; j < 26; j++) {
        if (j == s[i - 1] - 'a') {
          freq[j][i] = freq[j][i - 1] + 1;
          continue;
        }
        freq[j][i] = freq[j][i - 1];
      }
    }
    cout << solve(1, n, 0, freq) << "\n";
  }
  return 0;
}
