#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
int dp[N][26];
int find(int s, int e, int c) {
  if (s == e) {
    return (dp[s][c] - dp[s - 1][c]) == 1 ? 0 : 1;
  }
  int mid = (s + e) / 2;
  int len = mid - s + 1;
  int left = len - (dp[mid][c] - dp[s - 1][c]);
  int right = len - (dp[e][c] - dp[mid][c]);
  int a = left + find(mid + 1, e, c + 1);
  int b = right + find(s, mid, c + 1);
  return min(a, b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int test;
  cin >> test;
  while (test--) {
    int n;
    cin >> n;
    char arr[n + 1];
    for (int i = 1; i <= n; i++) {
      cin >> arr[i];
    }
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j < 26; j++) {
        dp[i][j] = 0;
      }
    }
    for (int i = 1; i <= n; i++) {
      int t = arr[i] - 'a';
      dp[i][t]++;
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < 26; j++) {
        dp[i][j] += dp[i - 1][j];
      }
    }
    cout << find(1, n, 0) << "\n";
  }
}
