#include <bits/stdc++.h>
using namespace std;
long long ffs(string s, char c, long long l, long long r) {
  long long m = (r + l) / 2;
  long long count1 = 0, i;
  for (i = l; i < m; i++) {
    if (s[i] != c) {
      count1++;
    }
  }
  long long count2 = 0;
  for (i = m; i < r; i++) {
    if (s[i] != c) {
      count2++;
    }
  }
  if (r - l == 1) {
    return count2;
  } else if (count1 < count2) {
    return count1 + ffs(s, c + 1, m, r);
  } else if (count2 < count1) {
    return count2 + ffs(s, c + 1, l, m);
  } else
    return min(count1 + ffs(s, c + 1, m, r), count2 + ffs(s, c + 1, l, m));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    char c = 'a';
    cout << ffs(s, c, 0, n) << endl;
  }
  return 0;
}
