#include <bits/stdc++.h>
using namespace std;
string s;
int solve(int i, int j, char c) {
  int sum = 1e9;
  int cnt = 0;
  if (i == j) {
    if (s[i] != c)
      return 1;
    else
      return 0;
  }
  int mid = (i + j) / 2;
  for (int l = i; l <= mid; l++) {
    if (s[l] != c) cnt++;
  }
  int ans = cnt + solve(mid + 1, j, c + 1);
  cnt = 0;
  for (int l = mid + 1; l <= j; l++) {
    if (s[l] != c) cnt++;
  }
  int ans2 = cnt + solve(i, mid, c + 1);
  sum = min(ans, ans2);
  return sum;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    cin >> s;
    s = "#" + s;
    cout << solve(1, n, 'a') << endl;
  }
}
