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