#include <bits/stdc++.h>
using namespace std;
char tmp[200000];
int count(const string& s, char c) {
  int cnt = 0;
  for (char sc : s) {
    if (sc == c) {
      ++cnt;
    }
  }
  return cnt;
}
int cost(const string& s, char c) {
  if (s.length() == 1) {
    return s[0] == c ? 0 : 1;
  }
  int mid = s.length() / 2;
  string left = s.substr(0, mid);
  string right = s.substr(mid, mid);
  int cost_left = cost(left, c + 1);
  int cost_right = cost(right, c + 1);
  return min(left.length() - count(left, c) + cost_right,
             cost_left + right.length() - count(right, c));
}
int main() {
  int t;
  scanf("%d", &t);
  while (t-- > 0) {
    int n;
    scanf("%d", &n);
    scanf("%s", tmp);
    string s = tmp;
    printf("%d\n", cost(s, 'a'));
  }
}
