#include <bits/stdc++.h>
using namespace std;
long long modP(long long x, long long y, long long MOD) {
  long long r = 1;
  x %= MOD;
  while (y > 0) {
    if (y & 1) {
      r = (r * x) % MOD;
    }
    y = y >> 1;
    x = (x * x) % MOD;
  }
  return r;
}
long long max(long long a, long long b) { return (a > b ? a : b); }
long long min(long long a, long long b) { return (a < b ? a : b); }
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, (a % b));
  }
}
long long lcm(long long a, long long b) {
  long long ans = (a / gcd(a, b)) * b;
  return ans;
}
long long do_s(string& s) {
  long long ans = 0;
  for (char ch : s)
    if (ch != 'b') ans++;
  return ans;
}
long long do_c(string& s) {
  int n = s.size();
  long long ans, l = 0, r = 0;
  for (int i = 0; i < n; i++) {
    if (i < (n / 2)) {
      if (s[i] != 'c') l++;
    } else {
      if (s[i] != 'c') r++;
    }
  }
  ans = min(l, r);
  return ans;
}
long long do_a(string& s) {
  long long ans = 0;
  for (char ch : s) {
    if (ch != 'a') ans++;
  }
  return ans;
}
long long do_b(string& s) {
  string x = "", y = "";
  int n = s.size();
  long long ans = 0;
  if (n == 1) {
    if (s[0] != 'b') ans++;
    return ans;
  }
  for (int i = 0; i < n; i++) {
    if (i < (n / 2))
      x.push_back(s[i]);
    else
      y.push_back(s[i]);
  }
  ans = do_s(x) + do_c(y);
  long long res = do_s(y) + do_c(x);
  ans = min(ans, res);
  return ans;
}
long long sr(string& s, char ch, long long l, long long r) {
  if (l > r) return 0;
  if (l == r) {
    if (s[l] != ch)
      return 1;
    else
      return 0;
  }
  long long ans = 0;
  long long left = 0, right = 0, mid = (l + r) / 2;
  for (int i = l; i <= r; i++) {
    if (i <= mid) {
      if (s[i] != ch) left++;
    } else {
      if (s[i] != ch) right++;
    }
  }
  ch++;
  if (left == right) {
    ans = left + sr(s, ch, mid + 1, r);
    long long res = right + sr(s, ch, l, mid);
    ans = min(ans, res);
  } else {
    if (left < right) {
      ans = left + sr(s, ch, mid + 1, r);
    } else
      ans = right + sr(s, ch, l, mid);
  }
  return ans;
}
void solve() {
  long long ans = 0;
  long long n;
  cin >> n;
  string s;
  cin >> s;
  ans = sr(s, 'a', 0, n - 1);
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
