#include <bits/stdc++.h>
using namespace std;
const int mx = 2e5;
int bit[mx + 5][30];
int n;
string s;
void update(int ind, int val) {
  ++ind;
  while (ind <= n) {
    bit[ind][val]++;
    ind += ind & (-ind);
  }
}
int query(int ind, int val) {
  ++ind;
  int sum = 0;
  while (ind > 0) {
    sum += bit[ind][val];
    ind -= ind & (-ind);
  }
  return sum;
}
int solve(char c, int l, int r) {
  if (l > r) return 0;
  if (l == r) return s[l] != c;
  int mid = (l + r) / 2;
  int cnt = (mid - l + 1) - (query(mid, c - 'a') - query(l - 1, c - 'a'));
  int cnt2 = (r - mid) - (query(r, c - 'a') - query(mid, c - 'a'));
  return min(cnt + solve(c + 1, mid + 1, r), cnt2 + solve(c + 1, l, mid));
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> s;
    for (int i = 0; i < n; ++i) {
      update(i, s[i] - 'a');
    }
    cout << solve('a', 0, n - 1) << endl;
    for (int i = 0; i <= n; ++i)
      for (int j = 0; j < 27; ++j) bit[i][j] = 0;
  }
}
