#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long IMX = INT_MAX;
const long long IMN = INT_MIN;
long long goodString(string &s, long long l, long long r, char c) {
  if (l == r) {
    if (s[l] == c) return 0;
    return 1;
  }
  long long mid = (l + r) / 2;
  long long x = 0, y = 0;
  for (long long(i) = (l); (i) <= (mid); (i)++) {
    if (s[i] != c) x++;
  }
  for (long long(i) = (mid + 1); (i) <= (r); (i)++) {
    if (s[i] != c) y++;
  }
  return min(x + goodString(s, mid + 1, r, c + 1),
             y + goodString(s, l, mid, c + 1));
}
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  cout << goodString(s, 0, n - 1, 'a') << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test;
  cin >> test;
  while (test--) {
    solve();
  }
}
