#include <bits/stdc++.h>
using namespace std;
const int N = 131100;
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % 1000000007;
    }
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return ans;
}
long long cnt[26][N], n;
long long fun(char c, string s, long long ss, long long second) {
  if (s.size() == 1) {
    if (s[0] == c)
      return 0;
    else
      return 1;
  }
  long long mid = (ss + second) / 2;
  long long on =
      (second - ss + 1) / 2 - (cnt[c - 'a'][mid] - cnt[c - 'a'][ss - 1]) +
      fun((char)(c + 1), s.substr(s.size() / 2, s.size() / 2), mid + 1, second);
  long long tw = fun((char)(c + 1), s.substr(0, s.size() / 2), ss, mid) +
                 (second - ss + 1) / 2 -
                 (cnt[c - 'a'][second] - cnt[c - 'a'][mid]);
  return min(on, tw);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    cin >> n;
    string s;
    cin >> s;
    for (long long i = 0; i < s.size(); i++) {
      for (int j = 0; j < 26; j++) cnt[j][i + 1] = 0;
      cnt[s[i] - 'a'][i + 1]++;
    }
    for (long long i = 0; i < n; i++) {
      for (int j = 0; j < 26; j++) {
        cnt[j][i + 1] += cnt[j][i];
      }
    }
    long long ans = fun('a', s, 1, n);
    cout << ans << "\n";
  }
  return 0;
}
