#include <bits/stdc++.h>
using namespace std;
const int N = 10001;
const int M = 300010;
const int HA = 998244353;
const int INF = 2047483647;
const long long INFL = 9023372036854775807;
char s[M];
int sm[M][35];
int sum(int l, int r, int c) { return r - l + 1 + sm[l - 1][c] - sm[r][c]; }
int dfs(int l, int r, int c) {
  if (l == r) {
    return sum(l, r, c);
  }
  int mid = (l + r) >> 1;
  int tot1 = dfs(l, mid, c + 1) + sum(mid + 1, r, c),
      tot2 = sum(l, mid, c) + dfs(mid + 1, r, c + 1);
  return min(tot1, tot2);
}
int main() {
  int t, len;
  cin >> t;
  while (t--) {
    cin >> len;
    for (int i = (0); i <= (30); i++) sm[0][i] = 0;
    scanf("%s", s + 1);
    for (int i = (1); i <= (len); i++) {
      for (int j = (0); j <= (25); j++) {
        sm[i][j] = sm[i - 1][j];
      }
      sm[i][s[i] - 'a']++;
    }
    int ans = dfs(1, len, 0);
    cout << ans << "\n";
  }
  return 0;
}
