#include <bits/stdc++.h>
using namespace std;
void testCase() {
  long long n, n1, i = 0;
  cin >> n;
  vector<char> s(n);
  vector<vector<long long>> fre(n + 1, vector<long long>(26, 0));
  for (long long i = 0; i < n; i++) cin >> s[i];
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 0; j < 26; j++) {
      if (s[i - 1] - 'a' == j)
        fre[i][j] = fre[i - 1][j] + 1;
      else
        fre[i][j] = fre[i - 1][j];
    }
  }
  long long l = 1, r = n, req = n / 2, k = 0, mn = 0;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (l == r) {
      if (s[l - 1] - 'a' != k) mn += 1;
      break;
    }
    if (fre[mid][k] - fre[l - 1][k] == fre[r][k] - fre[mid][k]) {
      if (fre[mid][k + 1] - fre[l - 1][k + 1] >=
          fre[r][k + 1] - fre[mid][k + 1]) {
        mn += req - (fre[mid][k] - fre[l - 1][k]);
        r = mid;
      } else {
        mn += req - (fre[r][k] - fre[mid][k]);
        l = mid + 1;
      }
    } else if (fre[mid][k] - fre[l - 1][k] > fre[r][k] - fre[mid][k]) {
      mn += req - (fre[mid][k] - fre[l - 1][k]);
      l = mid + 1;
    } else {
      mn += req - (fre[r][k] - fre[mid][k]);
      r = mid;
    }
    req /= 2;
    k += 1;
  }
  cout << mn << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    testCase();
  }
  return 0;
}
