#include <bits/stdc++.h>
using namespace std;
string s;
int minMoves(int left, int right, char ch) {
  if (left == right) return s[left] != ch;
  int mid = (left + right) / 2;
  int cnt_left = minMoves(mid + 1, right, ch + 1);
  for (int i = left; i <= mid; ++i) {
    cnt_left += s[i] != ch;
  }
  int cnt_right = minMoves(left, mid, ch + 1);
  for (int i = mid + 1; i <= right; ++i) {
    cnt_right += s[i] != ch;
  }
  return min(cnt_left, cnt_right);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    string s;
    cin >> n >> s;
    cout << minMoves(0, n - 1, 'a') << endl;
  }
}
