#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
int solve(string& second, int l, int r, char c) {
  if (l == r) return second[l] == c ? 0 : 1;
  int mid = (l + r) / 2;
  int one = solve(second, l, mid, c + 1);
  int two = solve(second, mid + 1, r, c + 1);
  for (int i = mid + 1; i < r + 1; i++) one += (second[i] == c ? 0 : 1);
  for (int i = l; i < mid + 1; i++) two += (second[i] == c ? 0 : 1);
  return min(one, two);
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    string second;
    cin >> second;
    int ans = solve(second, 0, n - 1, 'a');
    cout << ans << endl;
  }
  return 0;
}
