#include <bits/stdc++.h>
using namespace std;
class Solution {
 public:
  int solve(string& S) {
    int n = S.length();
    const int A = 26;
    vector<vector<int>> cnts(n + 1, vector<int>(A, 0));
    for (int i = 0; i < n; ++i) {
      cnts[i + 1] = cnts[i];
      cnts[i + 1][S[i] - 'a'] += 1;
    }
    auto count = [&](int l, int r, int c) {
      if (l > r) {
        return 0;
      }
      return r - l + 1 - (cnts[r + 1][c] - cnts[l][c]);
    };
    map<pair<int, int>, int> M;
    function<int(int, int, int)> search = [&](int l, int len, int ch) {
      if (len == 0) {
        return 0;
      }
      int r = l + len - 1;
      if (len == 1) {
        return count(l, r, ch);
      }
      int m = l + (len >> 1);
      int res = count(l, m - 1, ch) + search(m, len >> 1, ch + 1);
      res = min(res, count(m, r, ch) + search(l, len >> 1, ch + 1));
      return res;
    };
    return search(0, n, 0);
  }
};
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Solution sol;
  int t;
  cin >> t;
  while (t-- > 0) {
    int n;
    cin >> n;
    string S;
    cin >> S;
    cout << sol.solve(S) << '\n';
  }
  return 0;
}
