#include <bits/stdc++.h>
using namespace std;
int n, t;
string s;
int B(int x, int z, int p) {
  int i, u = 0, v = 0, y = x + z >> 1;
  if (x + 1 < z) {
    for (i = 0; i < y; i++) u += s[i] != p;
    for (; i < z; i++) v += s[i] != p;
    return min(u + B(y, z, p + 1), B(x, y, p + 1) + v);
  } else
    return s[y] != p;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (cin >> t; t--;) {
    cin >> n >> s;
    cout << B(0, n, 97) << '\n';
  }
}
