#include <bits/stdc++.h>
using namespace std;
int find_set(int v, vector<int> &p) {
  if (v == p[v]) return v;
  return p[v] = find_set(p[v], p);
}
void union_set(int a, int b, vector<int> &p) {
  a = find_set(a, p);
  b = find_set(b, p);
  if (a != b) {
    p[b] = a;
  }
}
int ans = 0;
int flag = 1;
void dfs(int i, vector<int> &vis, vector<int> f[], vector<int> h[], int pre) {
  for (int j = 0; j < f[i].size(); j++) {
    for (int k = 0; k < f[i].size(); k++)
      for (int l = 0; l < h[f[i][j]].size(); l++) {
        if (h[f[i][j]][l] == f[i][k]) {
          flag = 0;
        }
      }
  }
  ans++;
  vis[i] = 1;
  for (int k = 0; k < f[i].size(); k++) {
    if (f[i][k] == pre) {
      continue;
    } else if (vis[f[i][k]] == 0) {
      dfs(f[i][k], vis, f, h, i);
    }
  }
}
long long int c(string s, char x) {
  if (s.size() == 1 && s[0] == x) {
    return 0;
  } else if (s.size() == 1) {
    return 1;
  }
  int n = s.size();
  int cnt1 = 0;
  int cnt2 = 0;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] == x) {
      cnt1++;
    }
  }
  for (int i = n / 2; i < n; i++) {
    if (s[i] == x) {
      cnt2++;
    }
  }
  if (cnt1 == n / 2 || cnt2 == n / 2) {
    return 0;
  }
  return min(n / 2 - cnt1 + c(s.substr(n / 2, n / 2), (char)((int)(x) + 1)),
             n / 2 - cnt2 + c(s.substr(0, n / 2), (char)((int)(x) + 1)));
}
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  long long int ans = c(s, 'a');
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
