#include <bits/stdc++.h>
using namespace std;
string st;
int findAnd(string &st, int l, int r, char ch) {
  int ans = 0;
  for (int i = l; i <= r; i++) {
    if (st[i] != ch) ans++;
  }
  return ans;
}
int solve(string &st, int l, int r, char ch) {
  if (l == r) {
    if (st[l] == ch) return 0;
    return 1;
  }
  int mid = (l + r) / 2;
  int left = findAnd(st, l, mid, ch) + solve(st, mid + 1, r, ch + 1);
  int right = findAnd(st, mid + 1, r, ch) + solve(st, l, mid, ch + 1);
  return min(left, right);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string st;
    cin >> st;
    char ch = 'a';
    cout << solve(st, 0, n - 1, ch) << endl;
  }
}
