#include <bits/stdc++.h>
using namespace std;
string s;
int yekdast(char c, int l, int r) {
  int ans = 0;
  for (int i = l; i <= r; i++) {
    if (s[i] != c) ans++;
  }
  return ans;
}
int check(char c, int l, int r) {
  if ((r - l) > 1) {
    int mid1 = (floor((l * 1.0 + r * 1.0) / 2.0)),
        mid2 = (ceil((l * 1.0 + r * 1.0) / 2.0));
    int first = check(char(c + 1), l, mid1) + yekdast(c, mid2, r);
    int second = check(char(c + 1), mid2, r) + yekdast(c, l, mid1);
    return min(first, second);
  } else if (r == l + 1) {
    int first = check(char(c + 1), l, l) + yekdast(c, r, r);
    int second = check(char(c + 1), r, r) + yekdast(c, l, l);
    return min(first, second);
  } else {
    return yekdast(c, l, r);
  }
}
int t, n;
int main() {
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> n >> s;
    cout << check('a', 0, n - 1) << endl;
  }
}
