#include <bits/stdc++.h>
using namespace std;
int t, n, nlen;
string a;
int cal(string a, int st, int ed, int c) {
  int len = ed - st + 1;
  int cnt1 = 0, cnt2 = 0;
  int ans = 0;
  if (len == 1) {
    if (a[st - 1] == c)
      return ans = 0;
    else
      return ans = 1;
  }
  for (int i = st; i < st + len / 2; i++) {
    if (a[i - 1] != c) cnt1++;
  }
  for (int i = st + len / 2; i <= ed; i++) {
    if (a[i - 1] != c) cnt2++;
  }
  if (cnt1 < cnt2) {
    ans = cnt1 + cal(a, st + len / 2, ed, c + 1);
  } else if (cnt1 > cnt2) {
    ans = cnt2 + cal(a, st, st + len / 2 - 1, c + 1);
  } else {
    if (cal(a, st + len / 2, ed, c + 1) < cal(a, st, st + len / 2 - 1, c + 1))
      ans = cnt1 + cal(a, st + len / 2, ed, c + 1);
    else if (cal(a, st + len / 2, ed, c + 1) >
             cal(a, st, st + len / 2 - 1, c + 1))
      ans = cnt2 + cal(a, st, st + len / 2 - 1, c + 1);
    else
      ans = cnt1 + cal(a, st + len / 2, ed, c + 1);
  }
  return ans;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    cin >> n >> a;
    int tmp = cal(a, 1, n, 'a');
    cout << tmp << endl;
  }
  return 0;
}
