#include <bits/stdc++.h>
using namespace std;
long long expo(long long a, long long b, long long mod) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b = b >> 1;
  }
  return res;
}
void extendgcd(long long a, long long b, long long *v) {
  if (b == 0) {
    v[0] = 1;
    v[1] = 0;
    v[2] = a;
    return;
  }
  extendgcd(b, a % b, v);
  long long x = v[1];
  v[1] = v[0] - v[1] * (a / b);
  v[0] = x;
  return;
}
long long mminv(long long a, long long b) {
  long long arr[3];
  extendgcd(a, b, arr);
  return arr[0];
}
long long mminvprime(long long a, long long b) { return expo(a, b - 2, b); }
long long mod_add(long long a, long long b, long long m) {
  a = a % m;
  b = b % m;
  return (((a + b) % m) + m) % m;
}
long long mod_mul(long long a, long long b, long long m) {
  a = a % m;
  b = b % m;
  return (((a * b) % m) + m) % m;
}
long long mod_sub(long long a, long long b, long long m) {
  a = a % m;
  b = b % m;
  return (((a - b) % m) + m) % m;
}
long long mod_div(long long a, long long b, long long m) {
  a = a % m;
  b = b % m;
  return (mod_mul(a, mminvprime(b, m), m) + m) % m;
}
const long long factN = 3e5 + 5;
long long fact[factN];
void factorial(int n, long long m) {
  fact[0] = 1;
  for (int i = 1; i <= n; i++) fact[i] = mod_mul(fact[i - 1], i, m);
}
long long ncr(long long n, long long r, long long m) {
  long long n1 = fact[n];
  long long n2 = mod_mul(fact[r], fact[n - r], m);
  n2 = expo(n2, m - 2, m);
  return mod_mul(n1, n2, m);
}
int check_cnt(string t, char c) {
  int cnt = 0;
  for (int i = 0; i < ((int)(t).size()); i++) {
    if (t[i] != c) cnt++;
  }
  return cnt;
}
int N;
int rec(string s, int l, int r, char ch) {
  if (l > r || r >= ((int)(s).size()) || l >= ((int)(s).size()) || r >= N ||
      l >= N) {
    return 0;
  }
  if (l == r && l < N) {
    if (s[l] == ch)
      return 0;
    else
      return 1;
  }
  int mid = (r - l + 1) / 2;
  string left = s.substr(l, mid);
  string right = s.substr(mid, mid);
  int lc = check_cnt(left, ch);
  int rc = check_cnt(right, ch);
  if (lc < rc) {
    return (lc + rec(right, 0, mid - 1, ch + 1));
  } else if (rc < lc) {
    return (rc + rec(left, 0, mid - 1, ch + 1));
  } else {
    return (min(lc + rec(right, 0, mid - 1, ch + 1),
                rc + rec(left, 0, mid - 1, ch + 1)));
  }
}
void solve(int tc) {
  cin >> N;
  string s;
  cin >> s;
  cout << rec(s, 0, N - 1, 'a') << endl;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int tc = 1;
  cin >> tc;
  for (int i = 1; i <= tc; i++) {
    solve(i);
  }
  return 0;
}
