#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 10;
int f[26][MAX], n;
string s;
map<pair<pair<int, int>, char>, long long> dp;
long long solve(int l, int r, char c = 'a') {
  if (l == r) {
    if (s[l - 1] != c) return 1;
    return 0;
  }
  int m = (l + r) / 2;
  int left = f[c - 'a'][m] - f[c - 'a'][l - 1],
      right = f[c - 'a'][r] - f[c - 'a'][m];
  return min(m - l + 1 - left + solve(m + 1, r, c + 1),
             r - m - right + solve(l, m, c + 1));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> s;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 26; j++) f[j][i + 1] = 0;
      f[s[i] - 'a'][i + 1]++;
    }
    for (int i = 2; i <= n; i++)
      for (int j = 0; j < 26; j++) f[j][i] += f[j][i - 1];
    dp.clear();
    cout << solve(1, n) << "\n";
  }
  return 0;
}
