#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
string s;
long long recur(long long st, long long en, long long req) {
  if (st > en) return 0;
  char a = req + 'a';
  if (st == en) {
    if (s[st] != a) return 1;
    return 0;
  }
  long long mid = (st + en) / 2;
  long long s1 = 0;
  long long s2 = 0;
  for (long long i = st; i <= mid; i++) {
    if (s[i] != a) s1++;
  }
  for (long long i = mid + 1; i <= en; i++) {
    if (s[i] != a) s2++;
  }
  long long ans1 = s1 + recur(mid + 1, en, req + 1);
  long long ans2 = s2 + recur(st, mid, req + 1);
  return min(ans1, ans2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n >> s;
    long long ans = recur(0, n - 1, 0);
    cout << ans << '\n';
  }
}
