#include <bits/stdc++.h>
using namespace std;
template <typename T>
void setmax(T& x, T y) {
  x = max(x, y);
}
template <typename T>
void setmin(T& x, T y) {
  x = min(x, y);
}
const double PI = acos(-1.0);
const int INF = 1e9 + 47;
const long long LINF = 1LL * INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string s;
int dpT[1 << 17][20];
int u[1 << 17][20];
int cnt[1 << 17][30];
int dp(int l, int lg, int c, int t, int x = 0) {
  if (x) {
    return (1 << lg) - (cnt[l + (1 << lg)][c] - cnt[l][c]);
  }
  if (u[l][lg] == t) return dpT[l][lg];
  u[l][lg] = t;
  if (lg == 0) return dpT[l][lg] = ((s[l] - 'a') != c);
  int res = INF;
  setmin(res,
         dp(l, lg - 1, c, t, 1) + dp(l + (1 << (lg - 1)), lg - 1, c + 1, t));
  setmin(res,
         dp(l, lg - 1, c + 1, t) + dp(l + (1 << (lg - 1)), lg - 1, c, t, 1));
  return dpT[l][lg] = res;
}
void solve(int t) {
  int n;
  cin >> n;
  cin >> s;
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (30); ++j) {
      cnt[i + 1][j] = cnt[i][j] + (s[i] - 'a' == j);
    }
  }
  int k = 0;
  while (n) {
    k++;
    n /= 2;
  }
  k--;
  cout << dp(0, k, 0, t) << endl;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve(t);
  }
  cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
  return 0;
}
