#include <bits/stdc++.h>
using namespace std;
string str;
long long int minCost(long long int l, long long int r, char ch) {
  if (l == r) return (str[l] == ch) ? 0 : 1;
  long long int m = l + (r - l) / 2;
  long long int cost1 = 0, cost2 = 0;
  for (long long int i = l; i <= m; i++)
    if (str[i] != ch) cost1++;
  for (long long int i = m + 1; i <= r; i++)
    if (str[i] != ch) cost2++;
  ch++;
  return min(minCost(l, m, ch) + cost2, minCost(m + 1, r, ch) + cost1);
}
void solve() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  cin >> str;
  str = ' ' + str;
  cout << minCost(1, n, 'a') << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) solve();
}
