#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
vector<vector<pair<long long, long long>>> adjList;
vector<bool> visited;
vector<long long> distance;
void search(string &s, long long start, long long mid, long long end,
            vector<vector<long long>> &count, long long &ans, char c) {
  if (start > end)
    return;
  else {
    if (count[c - 'a'][mid + 1] - count[c - 'a'][start] >=
        count[c - 'a'][end + 1] - count[c - 'a'][mid + 1]) {
      ans = ans + (end - start + 1) / 2 -
            (count[c - 'a'][mid + 1] - count[c - 'a'][start]);
      start = mid + 1;
      search(s, start, (start + end) / 2, end, count, ans, c + 1);
    } else {
      ans = ans + (end - start + 1) / 2 -
            (count[c - 'a'][end + 1] - count[c - 'a'][mid + 1]);
      end = mid;
      search(s, start, (start + end) / 2, end, count, ans, c + 1);
    }
  }
}
void solve() {
  long long n;
  cin >> n;
  vector<vector<long long>> count(26, vector<long long>(n + 1));
  string s;
  cin >> s;
  for (long long i = 0; i < n; i++) {
    count[s[i] - 'a'][i + 1] = 1;
  }
  for (long long i = 0; i < 26; i++) {
    for (long long j = 1; j < n + 1; j++) {
      count[i][j] += count[i][j - 1];
    }
  }
  long long ans = 0;
  long long start = 0;
  long long end = n - 1;
  search(s, start, (start + end) / 2, end, count, ans, 'a');
  cout << ans + 1 << "\n";
}
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) solve();
}
