#include <bits/stdc++.h>
using namespace std;
long long int rec(long long int low, long long int high, string ip, char c,
                  vector<vector<long long int>> &dp) {
  if (low == high) {
    if (c == ip[low]) return 0;
    return 1;
  }
  long long int c1 = 0, c2 = 0;
  long long int mid = (low + high) / 2;
  vector<long long int> v1 = dp[mid];
  vector<long long int> v2(26, 0);
  if (low > 0) v2 = dp[low - 1];
  for (long long int i = 0; i < 26; i++) v1[i] = v1[i] - v2[i];
  for (long long int i = 0; i < 26; i++)
    if (i != (c - 'a')) c1 += v1[i];
  vector<long long int> v3 = dp[high];
  vector<long long int> v4 = dp[mid];
  for (long long int i = 0; i < 26; i++) v3[i] = v3[i] - v4[i];
  for (long long int i = 0; i < 26; i++)
    if (i != (c - 'a')) c2 += v3[i];
  if (c1 < c2) return c1 + rec(mid + 1, high, ip, c + 1, dp);
  if (c2 < c1) return c2 + rec(low, mid, ip, c + 1, dp);
  return min((c1 + rec(mid + 1, high, ip, c + 1, dp)),
             c2 + rec(low, mid, ip, c + 1, dp));
}
void solve() {
  long long int n;
  cin >> n;
  string ip;
  cin >> ip;
  vector<vector<long long int>> dp(n + 1, vector<long long int>(26, 0));
  for (long long int i = 0; i < n; i++) {
    dp[i][ip[i] - 'a']++;
    for (long long int j = 0; j < 26; j++) dp[i + 1][j] = dp[i][j];
  }
  cout << rec(0, n - 1, ip, 'a', dp) << endl;
  return;
}
int main() {
  int testcases = 1;
  cin >> testcases;
  while (testcases--) {
    solve();
  }
  return 0;
}
