#include <bits/stdc++.h>
using namespace std;
string k;
long long check(int l, int r, char s) {
  if (r - l == 1) {
    return k[l] != s;
  }
  long long c1 = 0, c2 = 0, mid = (l + r) / 2;
  for (long long a = l; a < mid; a++) {
    if (k[a] != s) c1++;
  }
  for (long long a = mid; a < r; a++) {
    if (k[a] != s) c2++;
  }
  return min((c1 + check(mid, r, s + 1)), (c2 + check(l, mid, s + 1)));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    cin >> k;
    cout << check(0, n, 'a') << endl;
  }
}
