#include <bits/stdc++.h>
using namespace std;
void read(long long int n = 10) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(n) << fixed;
}
long long int M = 1e9 + 7;
long long int M1 = 998244353;
long long int solve(string& str, long long int l, long long int r, char c) {
  if (l > r) return 0;
  if (l == r) {
    if (str[l] == c)
      return 0;
    else
      return 1;
  }
  long long int len = r - l + 1;
  map<char, long long int> freql, freqr;
  for (long long int i = l, j = 0; j < len / 2; j++, i++) freql[str[i]]++;
  for (long long int i = l + len / 2, j = 0; j < len / 2; j++, i++)
    freqr[str[i]]++;
  long long int ans1, ans2;
  if (freql[c] >= freqr[c])
    ans1 = len / 2 - freql[c] + solve(str, l + len / 2, r, c + 1);
  else if (freql[c] <= freqr[c])
    ans2 = len / 2 - freqr[c] + solve(str, l, l + len / 2 - 1, c + 1);
  if (freql[c] > freqr[c])
    return ans1;
  else if (freql[c] < freqr[c])
    return ans2;
  return min(ans1, ans2);
}
int32_t main() {
  read();
  long long int tcf;
  cin >> tcf;
  while (tcf--) {
    long long int n;
    cin >> n;
    string str;
    cin >> str;
    long long int coount = 0;
    cout << solve(str, 0, n - 1, 'a') << "\n";
  }
}
