#include <bits/stdc++.h>
using namespace std;
long long thunder(string &s, long long l, long long r, char c) {
  if (l > r) {
    return 0;
  }
  if ((r - l + 1) == 1) {
    return (s[l] == c) ? 0 : 1;
  }
  long long half = (r - l + 1) / 2, x1 = 0, x2 = 0;
  for (int i = l; i < (l + half); i++) {
    if (s[i] != c) {
      x1++;
    }
  }
  for (int i = l + half; i <= r; i++) {
    if (s[i] != c) {
      x2++;
    }
  }
  return min(thunder(s, l, l + half - 1, c + 1) + x2,
             thunder(s, l + half, r, c + 1) + x1);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    cout << thunder(s, 0, n - 1, 'a') << endl;
  }
  return 0;
}
