#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int n;
string s;
long long get_ans(int l, int r, int c) {
  if (r - l == 1) {
    if (s[l] == c) {
      return 0;
    } else {
      return 1;
    }
  }
  long long cnt1, cnt2, res1, res2;
  cnt1 = cnt2 = res1 = res2 = 0;
  for (int i = l; i < (l + r) / 2; i++) {
    if (s[i] != c) {
      cnt1++;
    }
  }
  for (int i = (l + r) / 2; i < r; i++) {
    if (s[i] != c) {
      cnt2++;
    }
  }
  res1 = cnt1 + get_ans((l + r) / 2, r, c + 1);
  res2 = cnt2 + get_ans(l, (l + r) / 2, c + 1);
  return min(res1, res2);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  for (int q = 0; q < t; q++) {
    cin >> n;
    cin >> s;
    cout << get_ans(0, n, (int)'a') << endl;
  }
  return 0;
}
