#include <bits/stdc++.h>
using namespace std;
bool rev(long long x, long long y) { return x > y; }
void input_arr(long long a[], long long n) {
  for (long long i = 0; i < n; i += 1) cin >> a[i];
}
void print_vec(vector<long long> &v) {
  for (auto i : v) cout << i << " ";
  cout << endl;
}
void print_arr(long long a[], long long n) {
  for (long long i = 0; i < n; i += 1) cout << a[i] << " ";
  cout << endl;
}
bool sortbysec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return a.second < b.second;
}
bool sortinrev(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.first > b.first);
}
bool sortinrevbysec(const pair<long long, long long> &a,
                    const pair<long long, long long> &b) {
  return (a.second > b.second);
}
template <typename... T>
void input(T &...args) {
  ((cin >> args), ...);
}
template <typename... T>
void print(T &&...args) {
  ((cout << args << endl), ...);
}
template <typename... T>
void deb(T &&...args) {
  cout << "~~ ";
  ((cout << args << " "), ...);
  cout << endl;
}
void stand8th() {
  long long n;
  input(n);
  string s;
  input(s);
  long long i = 0;
  long long j = n - 1;
  long long cnt = 0;
  long long ans = 0;
  char c = 'a';
  while (i < j) {
    cnt++;
    if (cnt > 10000) break;
    map<char, long long> mp1, mp2;
    for (long long k = i; k < (i + j) / 2 + 1; k += 1) {
      mp1[s[k]]++;
    }
    for (long long k = (i + j) / 2 + 1; k < j + 1; k += 1) {
      mp2[s[k]]++;
    }
    if (mp1[c] == mp2[c] && mp2[c] == (j - i) / 2 + 1) {
      i = (i + j) / 2 + 1;
    } else if (mp1[c] == mp2[c]) {
      char temp = c + 1;
      long long x = 0;
      while (mp1[temp] == mp2[temp]) {
        if (temp == 'z') break;
        temp++;
      }
      ans += (j - i) / 2 + 1 - mp1[c];
      if (mp1[temp] > mp2[temp]) {
        j = (i + j) / 2;
      } else {
        i = (i + j) / 2 + 1;
      }
    } else if (mp1[c] != (j - i) / 2 + 1 && mp2[c] == (j - i) / 2 + 1) {
      j = (j + i) / 2;
    } else if (mp1[c] == (j - i) / 2 + 1 && mp2[c] != (j - i) / 2 + 1) {
      i = (j + i) / 2 + 1;
    } else if (mp1[c] > mp2[c]) {
      ans += (j - i) / 2 + 1 - mp1[c];
      i = (i + j) / 2 + 1;
    } else {
      ans += (j - i) / 2 + 1 - mp2[c];
      j = (i + j) / 2;
    }
    c++;
  }
  if (s[i] != c) {
    ans += 1;
  }
  print(ans);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long tin = 1;
  input(tin);
  while (tin--) {
    stand8th();
  }
  return 0;
}
