#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int dp(int l, int r, char c) {
  if (l == r) return c != s[l];
  int mid = (l + r) / 2;
  int c1 = dp(mid + 1, r, c + 1);
  int c2 = dp(l, mid, c + 1);
  for (int i = l; i <= mid; ++i) c1 += s[i] != c;
  for (int i = mid + 1; i <= r; ++i) c2 += s[i] != c;
  return min(c1, c2);
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    cin >> n >> s;
    cout << dp(0, n - 1, 'a') << '\n';
  }
}
