#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 150005;
string str;
int solve(int l, int r, char t) {
  if (l >= r) return str[l] != t;
  int mid = l + r >> 1;
  int res = 0;
  int res1 = solve(l, mid, (char)(t + 1));
  int res2 = solve(mid + 1, r, (char)(t + 1));
  int cnt = 0;
  for (int i = mid + 1; i <= r; i++)
    if (str[i] != t) cnt++;
  res = cnt + res1;
  cnt = 0;
  for (int i = l; i <= mid; i++)
    if (str[i] != t) cnt++;
  res = min(res, cnt + res2);
  return res;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    cin >> str;
    str = ' ' + str;
    cout << solve(1, n, 'a') << '\n';
  }
  return 0;
}
