#include <bits/stdc++.h>
using namespace std;
int cnt[200000][26];
string str;
int fn(int start, int end, char ch) {
  int len = end - start + 1;
  if (len == 1) {
    int ans = 1;
    if (str[start] == ch) ans = 0;
    return ans;
  }
  int mid = (start + end) / 2;
  int curr1 = cnt[mid][ch - 'a'] - cnt[start - 1][ch - 'a'];
  int curr2 = cnt[end][ch - 'a'] - cnt[mid][ch - 'a'];
  curr1 = len / 2 - curr1;
  curr2 = len / 2 - curr2;
  int next1 = fn(start, mid, ch + 1);
  int next2 = fn(mid + 1, end, ch + 1);
  int ans = min(curr1 + next2, curr2 + next1);
  return ans;
}
void TestingChaluKarEyy() {
  int n;
  cin >> n;
  string xx;
  cin >> xx;
  str = "1";
  str += xx;
  for (int i = 0; i <= 25; ++i) cnt[0][i] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= 25; ++j) cnt[i][j] = cnt[i - 1][j];
    ++cnt[i][str[i] - 'a'];
  }
  cout << fn(1, n, 'a') << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int TestingKaravvuChhe;
  cin >> TestingKaravvuChhe;
  while (TestingKaravvuChhe--) {
    TestingChaluKarEyy();
  }
}
