#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
const int N = 2e5 + 5;
const ll INF = 1e18 + 1;
const int MOD = 1e9 + 7;
ll check(string &s, ll l, ll r, char cur) {
  if (l > r) return 0;
  if (l == r && s[l] == cur)
    return 0;
  else if (l == r)
    return 1;
  ll mid = l + (r - l) / 2;
  ll cnt1 = 0, cnt2 = 0;
  for (ll i = 0; i <= mid; i++)
    if (s[i] != cur) cnt1++;
  for (ll i = mid + 1; i <= r; i++)
    if (s[i] != cur) cnt2++;
  if (cnt1 > cnt2)
    return cnt2 + check(s, l, mid, cur + 1);
  else
    return cnt1 + check(s, mid + 1, r, cur + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    cout << check(s, 0, n - 1, 'a') << "\n";
  }
  return 0;
}
