#include <bits/stdc++.h>
using namespace std;
long long a[26][131073];
map<pair<long long, pair<long long, long long>>, long long> memo;
long long findans(long long st, long long en, long long req, long long n,
                  string &s) {
  if (st > en) {
    return 0;
  }
  if (st == en) {
    if (s[st] == (req + 'a')) {
      return 0;
    } else {
      return 1;
    }
  }
  if (memo.find(make_pair(st, make_pair(en, req))) != memo.end()) {
    return memo[make_pair(st, make_pair(en, req))];
  }
  long long tn = (en - st + 1);
  long long reqc = (en - st + 1) / 2;
  long long op1 = 0;
  if (st - 1 >= 0) {
    op1 = a[req][st + reqc - 1] - a[req][st - 1];
    op1 = reqc - op1;
  } else {
    op1 = a[req][st + reqc - 1];
    op1 = reqc - op1;
  }
  long long choice1 = op1 + findans(st + (reqc), en, req + 1, n, s);
  long long ts = st + (tn) / 2;
  if (ts - 1 >= 0) {
    op1 = a[req][en] - a[req][ts - 1];
    op1 = reqc - op1;
  } else {
    op1 = a[req][en];
    op1 = reqc - op1;
  }
  long long choice2 = op1 + findans(st, en - (reqc), req + 1, n, s);
  return memo[make_pair(st, make_pair(en, req))] = min(choice1, choice2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long t1;
  cin >> t1;
  while (t1--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    for (long long i = 0; i < 26; i++) {
      for (long long j = 0; j < n; j++) {
        a[i][j] = 0;
      }
    }
    for (long long i = 0; i < n; i++) {
      a[s[i] - 'a'][i] = 1;
    }
    for (long long i = 0; i < 26; i++) {
      for (long long j = 1; j < n; j++) {
        a[i][j] = a[i][j - 1] + a[i][j];
      }
    }
    memo.clear();
    long long ans = findans(0, n - 1, 0, n, s);
    cout << ans << '\n';
  }
  return 0;
}
