#include <bits/stdc++.h>
using namespace std;
int solve(string s, int l, int r, int i) {
  if (i == 26) return 0;
  int left_ch = 0;
  if (l == (l + r) / 2) left_ch = 1e9;
  for (int j = l; j < (l + r) / 2; j++) {
    left_ch += s[j] != ('a' + i);
  }
  int right_ch = 0;
  if ((l + r) / 2 == r) right_ch = 1e9;
  for (int j = (l + r) / 2; j < r; j++) {
    right_ch += s[j] != ('a' + i);
  }
  if (right_ch == 1e9 && left_ch == 1e9) return 0;
  if (right_ch == left_ch) {
    return left_ch + min(solve(s, l, (l + r) / 2, i + 1),
                         solve(s, (l + r) / 2, r, i + 1));
  } else {
    int ans = 0;
    if (left_ch < right_ch)
      ans = solve(s, (l + r) / 2, r, i + 1);
    else
      ans = solve(s, l, (l + r) / 2, i + 1);
    return min(left_ch, right_ch) + ans;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    string s;
    cin >> n >> s;
    cout << solve(s, 0, n, 0) << '\n';
  }
  return 0;
}
