#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
bool sortcol(const vector<int>& v1, const vector<int>& v2) {
  return v1[1] < v2[1];
}
void fastio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
bool sortbysecdesc(const pair<long long int, long long int>& a,
                   const pair<long long int, long long int>& b) {
  if (a.first > b.first) return true;
  if (a.first == b.first) return a.second < b.second;
  return false;
}
long long int power(long long int x, long long int y) {
  long long int res = 1;
  x = x % mod;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res;
}
int fun(int l, int r, int x, int a[]) {
  if (l == r) {
    if (a[l] == x) return 0;
    return 1;
  }
  int t1 = 0, t2 = 0;
  int mid = (l + r) / 2;
  for (int i = l; i <= mid; i++)
    if (a[i] != x) t1++;
  for (int i = mid + 1; i <= r; i++)
    if (a[i] != x) t2++;
  int ans1 = t1 + fun(mid + 1, r, x + 1, a);
  int ans2 = t2 + fun(l, mid, x + 1, a);
  return min(ans1, ans2);
}
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int a[n + 1];
  for (int i = 0; i < n; i++) a[i + 1] = s[i] - 'a';
  cout << fun(1, n, 0, a) << "\n";
}
int main() {
  int tc;
  cin >> tc;
  while (tc--) solve();
}
