#include <bits/stdc++.h>
using namespace std;
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.second <= b.second) return true;
  return false;
}
bool prime[10000001];
void sieve() {
  memset(prime, true, sizeof(prime));
  prime[1] = false;
  for (long long i = 2; i * i <= 10000001; i++) {
    if (prime[i] == true) {
      for (long long j = i * i; j <= 10000001; j += i) prime[j] = false;
    }
  }
}
int sprimefactor[1000001];
void smallestprimef() {
  for (long long i = 1; i <= 1000000; i++) sprimefactor[i] = i;
  for (long long i = 2; i * i <= 1000000; i++) {
    if (sprimefactor[i] == i) {
      for (long long j = i * i; j <= 1000000; j++) {
        if (sprimefactor[j] == j) sprimefactor[j] = i;
      }
    }
  }
}
long long egcd(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1;
  long long egc = egcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return egc;
}
long long phi[1000001];
void ph() {
  for (long long i = 1; i < 1000001; i++) phi[i] = i;
  for (long long i = 2; i < 1000001; i++) {
    if (phi[i] == i) {
      phi[i] = i - 1;
      for (long long j = 2 * i; j < 1000001; j += i) {
        phi[j] /= i;
        phi[j] *= (i - 1);
      }
    }
  }
}
long long sumofdigits(long long n) {
  long long sum = 0;
  while (n > 0) {
    sum += (n % 10);
    n /= 10;
  }
  return sum;
}
string s;
long long solve(long long low, long long high, char ch) {
  if (low == high) {
    if (s[low] == ch) return 0;
    return 1;
  }
  long long c1 = 0, c2 = 0, i;
  long long mid = (low + high) / 2;
  for (i = low; i < mid + 1; i++)
    if (s[i] != ch) c1++;
  for (i = mid + 1; i < high + 1; i++)
    if (s[i] != ch) c2++;
  return min(c1 + solve(mid + 1, high, ch + 1), c2 + solve(low, mid, ch + 1));
}
long long i, j, n, x, y;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  long long tt = 1;
  cin >> tt;
  while (tt--) {
    long long c = 0, o = 0, e = 0, flag = 0, pos = -1, x = 0, y = 0, z = 0,
              i = 0, j = 0, k = 0;
    long long mini = INT_MAX, maxi = INT_MIN;
    long long n;
    cin >> n;
    cin >> s;
    long long ans = solve(0, n - 1, 'a');
    cout << ans << "\n";
  }
  return 0;
}
