#include <bits/stdc++.h>
using namespace std;
int ans = 1000000;
void rec(int sco, string s, char c) {
  int k = 0;
  if (s.length() == 1) {
    if (s[0] != c) {
      sco++;
    }
    ans = min(ans, sco);
    return;
  }
  for (int i = 0; i < s.length() / 2; i++) {
    if (s[i] != c) {
      k++;
    }
  }
  rec(sco + k, s.substr(s.length() / 2, s.length()), c + 1);
  k = 0;
  for (int i = s.length() / 2; i < s.length(); i++) {
    if (s[i] != c) {
      k++;
    }
  }
  rec(sco + k, s.substr(0, s.length() / 2), c + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    ans = 1000000;
    int n;
    cin >> n;
    string s;
    cin >> s;
    rec(0, s, 'a');
    cout << ans << endl;
  }
}
