#include <bits/stdc++.h>
using namespace std;
int minChange(string s, int n, int start, char ch) {
  if (n < 2) return 0;
  if (n == 2) {
    if (s[start] == ch) {
      if (s[start + 1] == ch + 1)
        return 0;
      else
        return 1;
    } else if (s[start] == ch + 1) {
      if (s[start + 1] == ch) return 0;
      return 1;
    }
    return 2;
  }
  int left = 0, right = 0, m;
  for (int i = start; i < start + n / 2; i++) {
    if (s[i] != ch) left++;
  }
  for (int i = start + n / 2; i < start + n; i++) {
    if (s[i] != ch) right++;
  }
  if (left < right) {
    m = minChange(s, n / 2, start + n / 2, ch + 1);
    return m + left;
  } else if (right < left) {
    m = minChange(s, n / 2, start, ch + 1);
    return m + right;
  } else {
    m = minChange(s, n / 2, start, ch + 1);
    int mr = minChange(s, n / 2, start + n / 2, ch + 1);
    m = min(m, mr);
    return min(m + left, m + right);
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    if (n == 1) {
      if (s[0] != 'a')
        cout << "1" << endl;
      else
        cout << "0\n";
      continue;
    }
    cout << minChange(s, n, 0, 'a') << endl;
  }
  return 0;
}
