#include <bits/stdc++.h>
using namespace std;
long long int prime = 998244353;
long long int modulo = 1e9 + 7;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
string s;
int ans = 0;
int dc(char c, int l, int r) {
  if (l == r) {
    if (s[l] == c)
      return 0;
    else
      return 1;
  }
  int mid = (l + r) / 2;
  int x = 0, y = 0;
  for (int i = l; i <= mid; i++) {
    if (s[i] != c) x++;
  }
  for (int i = mid + 1; i <= r; i++) {
    if (s[i] != c) y++;
  }
  c++;
  int a = x + dc(c, mid + 1, r);
  int b = y + dc(c, l, mid);
  return min(a, b);
}
void solve() {
  unordered_map<string, int> look_up;
  unordered_map<long long int, int> lp;
  int n;
  cin >> n >> s;
  s = 'e' + s;
  char c = 'a';
  cout << dc(c, 1, n);
  cout << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
