#include <bits/stdc++.h>
using namespace std;
int solve(const string& s, int l, int r, char c) {
  if (l == r) {
    return (s[r] != c);
  }
  int len = (r - l + 1) / 2;
  int l_cnt1 = 0;
  int l_cnt2 = 0;
  for (int i = l; i <= l + len - 1; ++i) {
    if (s[i] == c) {
      ++l_cnt1;
    } else if (s[i] == char(c + 1)) {
      ++l_cnt2;
    }
  }
  int r_cnt1 = 0;
  int r_cnt2 = 0;
  for (int i = l + len; i <= r; ++i) {
    if (s[i] == c) {
      ++r_cnt1;
    } else if (s[i] == char(c + 1)) {
      ++r_cnt2;
    }
  }
  if (l_cnt1 > r_cnt1) {
    return len - l_cnt1 + solve(s, l + len, r, char(c + 1));
  } else if (l_cnt1 < r_cnt1) {
    return len - r_cnt1 + solve(s, l, l + len - 1, char(c + 1));
  } else if (l_cnt1 == r_cnt1) {
    if (l_cnt2 > r_cnt2) {
      return len - l_cnt1 + solve(s, l, l + len - 1, char(c + 1));
    } else {
      return len - l_cnt1 + solve(s, l + len, r, char(c + 1));
    }
  }
  return -1;
}
int main(int argc, char** argv) {
  int t;
  cin >> t;
  string s;
  for (; t > 0; --t) {
    int n;
    cin >> n >> s;
    cout << solve(s, 0, n - 1, 'a') << "\n";
  }
  return 0;
}
