#include <bits/stdc++.h>
using namespace std;
void start() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
template <class T>
istream& operator>>(istream& in, vector<T>& a) {
  for (auto& i : a) in >> i;
  return in;
}
template <class T>
ostream& operator<<(ostream& out, vector<T>& a) {
  for (auto& i : a) out << i << ' ';
  return out;
}
template <class T, class U>
istream& operator>>(istream& in, vector<pair<T, U> >& a) {
  for (auto& i : a) in >> i.first >> i.second;
  return in;
}
template <class T, class U>
ostream& operator<<(ostream& out, vector<pair<T, U> >& a) {
  for (auto& i : a) out << i.first << ' ' << i.second << "\n";
  return out;
}
template <class T, class U>
ostream& operator<<(ostream& out, pair<T, U>& a) {
  out << a.first << ' ' << a.second << "\n";
  return out;
}
template <class T, class U>
istream& operator>>(istream& in, pair<T, U>& a) {
  in >> a.first >> a.second;
  return in;
}
long long n;
string second;
long long lg = 0;
long long rec(long long l, long long r, long long cur) {
  if (l + 1 == r) {
    if (cur + 'a' != second[l]) {
      return 1;
    }
    return 0;
  }
  map<char, long long> cnt1;
  map<char, long long> cnt2;
  for (long long i = l; i < (l + r) / 2; i++) {
    cnt1[second[i]]++;
  }
  for (long long i = (l + r) / 2; i < r; i++) {
    cnt2[second[i]]++;
  }
  long long ans1 = rec(l, (l + r) / 2, cur + 1);
  long long ans2 = rec((l + r) / 2, r, cur + 1);
  long long val = (r - l) / 2;
  return min(ans1 + (val - cnt2['a' + cur]), ans2 + (val - cnt1['a' + cur]));
}
void solve() {
  cin >> n;
  cin >> second;
  while ((1 << lg) != n) {
    lg++;
  }
  long long ans = rec(0, n, 0);
  cout << ans << "\n";
}
signed main() {
  start();
  long long q = 1;
  cin >> q;
  while (q--) {
    solve();
  }
}
