#include <bits/stdc++.h>
using namespace std;
inline void fastio() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
}
using LL = long long;
using LD = long double;
const LL INF = LLONG_MAX;
const LL MOD = 998244353;
const LL N = 2e6 + 1;
LL recurse(string& s, int st, int en, char c, vector<vector<LL>>& presum) {
  if (st == en) {
    if (c != s[st]) {
      return 1;
    } else {
      return 0;
    }
  }
  int mid = (st + en) / 2;
  int half = (en - st + 1) / 2;
  LL val1 = half - (presum[c - 'a'][en + 1] - presum[c - 'a'][mid + 1]);
  LL val2 = half - (presum[c - 'a'][mid + 1] - presum[c - 'a'][st]);
  val1 += recurse(s, st, mid, char(c + 1), presum);
  val2 += recurse(s, mid + 1, en, char(c + 1), presum);
  return min(val1, val2);
}
int main() {
  fastio();
  LL t;
  cin >> t;
  while (t--) {
    LL n;
    cin >> n;
    string s;
    cin >> s;
    if (n == 1) {
      if (s[0] == 'a')
        cout << "0\n";
      else
        cout << "1\n";
      continue;
    }
    vector<vector<LL>> presum(20, vector<LL>(n + 1, 0));
    for (int i = 0; i < 20; ++i) {
      for (int j = 1; j <= n; ++j) {
        presum[i][j] = presum[i][j - 1] + (s[j - 1] == char('a' + i) ? 1 : 0);
      }
    }
    cout << recurse(s, 0, n - 1, 'a', presum) << "\n";
  }
}
