#include <bits/stdc++.h>
using namespace std;
long long powerr(long long x, long long y);
long long mpower(long long x, long long y, long long p);
long long gcdExtended(long long a, long long b);
bool isPrime(long long n);
vector<long long> v[100001];
char v1[100001];
string f;
long long flag = 0;
int vis[30];
void dfs(long long n) {
  vis[n] = 1;
  long long i;
  f = f + v1[n];
  for (i = 0; i < v[n].size(); i++) {
    if (!vis[v[n][i]]) {
      dfs(v[n][i]);
    }
  }
}
void dfsu(long long n, long long m) {
  vis[n] = 1;
  long long i;
  for (i = 0; i < v[n].size(); i++) {
    if (!vis[v[n][i]]) {
      dfsu(v[n][i], n);
    } else if (v[n][i] != m) {
      flag = 1;
      break;
    }
  }
}
int divide(string s, long long l, long long r, long long x) {
  char c = 'a' + x;
  if (l == r) {
    if (s[l] == c)
      return 0;
    else
      return 1;
  }
  long long cnt1, cnt2;
  cnt1 = 0;
  cnt2 = 0;
  long long mid = (l + r) / 2;
  long long i;
  for (i = l; i < mid + 1; i++) {
    if (s[i] != c) cnt1++;
  }
  for (i = mid + 1; i < r + 1; i++) {
    if (s[i] != c) {
      cnt2++;
    }
  }
  if (cnt1 > cnt2) {
    return cnt2 + divide(s, l, mid, x + 1);
  } else if (cnt2 > cnt1)
    return cnt1 + divide(s, mid + 1, r, x + 1);
  else
    return min(cnt1 + divide(s, mid + 1, r, x + 1),
               cnt2 + divide(s, l, mid, x + 1));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t, j, k, l, h, p, q, r, x, i, y, z, a, b, c, d, n, m,
      M = 1000000007;
  char ch, ch2, ch3;
  string s1, s2, s3;
  set<pair<long long, long long> > S1, S;
  t = 1;
  cin >> t;
  x = 0;
  while (t--) {
    cin >> n;
    string s;
    cin >> s;
    long long ans = divide(s, 0, n - 1, 0);
    cout << ans;
    cout << "\n";
  }
}
long long gcdExtended(long long a, long long b) {
  if (b == 0) {
    return a;
  } else
    return gcdExtended(b, a % b);
}
long long mpower(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;
}
long long powerr(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  long long p = sqrt(n);
  for (int i = 5; i <= p; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
