#include <bits/stdc++.h>
using namespace std;
string s;
int moves(int l, int r, char c) {
  int ans = 0;
  for (int i = l; i <= r; i++) {
    if (s[i] != c) ans++;
  }
  return ans;
}
int good(int l, int r, char c) {
  if (l == r) {
    if (s[l] == c)
      return 0;
    else
      return 1;
  }
  long long int mid = l + (r - l) / 2;
  int temp1 = good(mid + 1, r, c + 1);
  temp1 += moves(l, mid, c);
  int temp2 = good(l, mid, c + 1);
  temp2 += moves(mid + 1, r, c);
  return min(temp1, temp2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    cin >> s;
    cout << good(0, n - 1, 'a') << endl;
  }
}
