#include <bits/stdc++.h>
using namespace std;
int find_sym(char a, string s, int from, int to) {
  int k = 0;
  for (int i = from; i < to; ++i) {
    if (s[i] == a) {
      k++;
    }
  }
  return k;
}
int min(int a, int b) {
  if (a < b) {
    return a;
  }
  return b;
}
char g = 'a';
int res = 0;
string s;
void rec(int from, int to) {
  if (from >= to) {
    return;
  }
  int k1, k2;
  k1 = find_sym(g, s, from, to / 2);
  k2 = find_sym(g, s, to / 2, to);
  if (k1 < k2) {
    g++;
    res += to - from - k2;
    rec(from, to / 2);
  } else {
    g++;
    res += to - from - k1;
    rec(to / 2, to);
  }
}
int main() {
  int t;
  cin >> t;
  for (int u = 0; u < t; ++u) {
    int n;
    int res1 = 0;
    cin >> n;
    cin >> s;
    rec(0, n);
    cout << res << endl;
  }
}
