#include <bits/stdc++.h>
using namespace std;
long long n;
string s;
long long f(long long l, long long r, char c1) {
  if (l == r && s[l] != c1)
    return 1;
  else if (l == r && s[l] == c1)
    return 0;
  long long cnt1 = 0, cnt2 = 0;
  long long mid = (l + r) / 2;
  for (long long i = l; i <= mid; i++)
    if (s[i] != c1) cnt1++;
  for (long long i = mid + 1; i <= r; i++)
    if (s[i] != c1) cnt2++;
  long long ans =
      min(cnt1 + f(mid + 1, r, char(c1 + 1)), cnt2 + f(l, mid, char(c1 + 1)));
  return ans;
}
void solve() {
  cin >> n >> s;
  long long final = f(0, n - 1, 'a');
  cout << final << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  cin >> t;
  for (long long i = 0; i < t; i++) solve();
  return 0;
}
