#include <bits/stdc++.h>
using namespace std;
int f[131073][26];
void pref(string& s, int n) {
  for (char c = 'a'; c <= 'z'; c++) {
    if (c == s[0])
      f[0][c - 'a'] = 1;
    else
      f[0][c - 'a'] = 0;
  }
  for (int i = 1; i < n; i++) {
    for (char c = 'a'; c <= 'z'; c++) {
      if (c == s[i])
        f[i][c - 'a'] = 1 + f[i - 1][c - 'a'];
      else
        f[i][c - 'a'] = f[i - 1][c - 'a'];
    }
  }
}
int coun(int i, int pow, char c) {
  int j = i + (1 << pow) - 1;
  return f[j - 1][c - 'a'] - ((i - 1 == 0) ? 0 : f[i - 2][c - 'a']);
}
int answ(string& s, int i, int j, char c) {
  if (j == 0) return (c != s[i - 1]);
  int h1 = (1 << (j - 1)) - coun(i, j - 1, c);
  int h2 = (1 << (j - 1)) - coun(i + (1 << (j - 1)), j - 1, c);
  return min(h1 + answ(s, i + (1 << (j - 1)), j - 1, c + 1),
             h2 + answ(s, i, j - 1, c + 1));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    pref(s, n);
    int q = 1, pow = 0;
    while (q != n) {
      q *= 2;
      pow++;
    }
    cout << answ(s, 1, pow, 'a') << '\n';
  }
}
