#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
int daq(string& s, char c, int l, int r, vector<int>& amount) {
  if (l == r) {
    amount[s[l] - 'a'] = 1;
    return s[l] == c ? 0 : 1;
  }
  vector<int> la(26, 0), ra(26, 0);
  int mid = (l + r) / 2;
  int ans, lmin = daq(s, c + 1, l, mid, la),
           rmin = daq(s, c + 1, mid + 1, r, ra);
  ans = min(lmin + mid - l + 1 - ra[c - 'a'], rmin + mid - l + 1 - la[c - 'a']);
  for (int i = 0; i < 26; i++) amount[i] = la[i] + ra[i];
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T;
  cin >> T;
  while (T--) {
    vector<int> haha(26, 0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    cout << daq(s, 'a', 0, n - 1, haha) << "\n";
  }
  return 0;
}
