#include <bits/stdc++.h>
using namespace std;
int check(string second, char c) {
  if (second.size() == 1) {
    if (second[0] == c) {
      return 0;
    } else {
      return 1;
    }
  } else {
    string a, b;
    a = second.substr(0, second.size() / 2);
    b = second.substr(second.size() / 2, second.size() / 2);
    int ca = 0;
    int cb = 0;
    ca = count(a.begin(), a.end(), c);
    cb = count(b.begin(), b.end(), c);
    if (ca > cb) {
      return (second.size() / 2) - (ca) + check(b, c + 1);
    } else if (cb > ca) {
      return (second.size() / 2) - (cb) + check(a, c + 1);
    } else {
      return min(check(a, c + 1), check(b, c + 1)) + second.size() / 2 - ca;
    }
  }
}
int ans = 0;
int main() {
  std::ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    string second;
    cin >> second;
    cout << check(second, 'a') << "\n";
  }
  return 0;
}
