#include <bits/stdc++.h>
using namespace std;
int cnt[131073][26] = {};
int dfs(string& str, int s, int e, char ch) {
  if (s == e) return (str[s] != ch);
  int m = (s + e) / 2, l, r, req = (m - s + 1);
  r = cnt[e][ch - 'a'];
  l = cnt[m][ch - 'a'];
  r -= l;
  if (s > 0) l -= cnt[s - 1][ch - 'a'];
  if (l > r) {
    return (req - l + dfs(str, m + 1, e, ch + 1));
  }
  if (r > l) {
    return (req - r + dfs(str, s, m, ch + 1));
  }
  int left = dfs(str, s, m, ch + 1);
  int right = dfs(str, m + 1, e, ch + 1);
  return (req - l + min(left, right));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    string s;
    cin >> s;
    for (int j = 0; j < 26; j++) cnt[0][j] = 0;
    cnt[0][s[0] - 'a']++;
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < 26; j++) cnt[i][j] = cnt[i - 1][j];
      cnt[i][s[i] - 'a']++;
    }
    cout << dfs(s, 0, n - 1, 'a') << '\n';
  }
}
