#include <bits/stdc++.h>
using namespace std;
long long n;
string s;
vector<vector<long long> > ar;
map<pair<long long, long long>, pair<bool, long long> > mapa;
long long evaluate(long long l, long long r, long long niv) {
  pair<bool, long long> temp = mapa[pair<long long, long long>(l, r)];
  if (temp.first) return temp.second;
  temp.first = true;
  if ((r - l + 1) >= 2) {
    long long mitad = (r + l) / 2;
    temp.second = min(((r - l + 1) / 2 - ar[niv][r] + ar[niv][mitad]) +
                          evaluate(l, mitad, niv + 1),
                      ((r - l + 1) / 2 - ar[niv][mitad] + ar[niv][l - 1]) +
                          evaluate(mitad + 1, r, niv + 1));
  } else {
    temp.second = 1 * (s[l - 1] != 97 + niv);
  }
  mapa[pair<long long, long long>(l, r)] = temp;
  return temp.second;
}
void solve() {
  mapa.clear();
  cin >> n;
  cin >> s;
  ar.assign(18, vector<long long>(n + 1, 0));
  for (long long i = 1; i <= n; i++) {
    for (long long i2 = 0; i2 <= 17; i2++) {
      ar[i2][i] = ar[i2][i - 1] + (s[i - 1] == 97 + i2);
    }
  }
  cout << evaluate(1, n, 0) << endl;
}
int main() {
  ifstream fin("text.in");
  ofstream fout("text.out");
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
