#include <bits/stdc++.h>
using namespace std;
string s;
int minn;
void getans(int l, int r, char m, int ans) {
  if (l == r) {
    if (s[l] != m) {
      ans++;
    }
    if (ans < minn) {
      minn = ans;
    }
    return;
  } else {
    int temp = ans;
    for (int i = 0; i <= (l + r) / 2; i++) {
      if (s[i] != m) {
        temp++;
      }
    }
    getans((l + r) / 2 + 1, r, m + 1, temp);
    for (int i = (l + r) / 2 + 1; i <= r; i++) {
      if (s[i] != m) {
        ans++;
      }
    }
    getans(l, (l + r) / 2, m + 1, ans);
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n >> s;
    minn = 100000000;
    getans(0, n - 1, 'a', 0);
    cout << minn << endl;
  }
  return 0;
}
