#include <bits/stdc++.h>
using namespace std;
string str;
int dp(int x, int y, int k) {
  if (x == y) {
    if (str[x - 1] == 'a' + k)
      return 0;
    else
      return 1;
  }
  int mid = (x + y) / 2;
  int f = 0;
  for (int i = x - 1; i < mid; i++) {
    if (str[i] != 'a' + k) f++;
  }
  int ans = f + dp(mid + 1, y, k + 1);
  f = 0;
  for (int i = mid; i < y; i++) {
    if (str[i] != 'a' + k) f++;
  }
  ans = min(ans, f + dp(x, mid, k + 1));
  return ans;
}
int main() {
  int t, o = 0;
  cin >> t;
  while (t--) {
    int n;
    cin >> n >> str;
    cout << dp(1, n, 0) << endl;
  }
  return 0;
}
