#include <bits/stdc++.h>
using namespace std;
const int MAXX = (1 << 17);
void answer(bool a) {
  if (a)
    cout << "YES\n";
  else
    cout << "NO\n";
}
int tab[51];
pair<char, int> tree[2 * MAXX + 1]['z' - 'a' + 2];
void clearv2(int i, int p) {
  while (p >= 0) {
    tree[i][0] = {'0', 0};
    for (int j = 1; j < 'z' - 'a' + 1; j++) {
      tree[i][j] = {j - 1, 0};
    }
    i /= 2;
    p--;
  }
}
void clear(int n, int p) {
  for (int i = MAXX; i < n + MAXX + 1; i++) {
    clearv2(i, p);
  }
}
void update(char c, int adr) {
  adr += MAXX;
  tree[adr][0].first = c;
  tree[adr][c + 1 - 'a'].second += 1;
  while (adr / 2 > 0) {
    adr /= 2;
    if (tree[adr][0].first == '0' || tree[adr][0].first == c) {
      tree[adr][0].second += 1;
      tree[adr][c + 1 - 'a'].second += 1;
    } else {
      tree[adr][c + 1 - 'a'].second += 1;
      if (tree[adr][c + 1 - 'a'].second > tree[adr][0].second) {
        tree[adr][0] = tree[adr][c + 1 - 'a'];
      }
    }
  }
}
void out(int q) { cout << q << " "; }
int query(char c = 'a', int adr = 1, int licz = MAXX / 2) {
  int adr1 = adr * 2, adr2 = adr * 2 + 1, fians = 0;
  if (adr >= MAXX) {
    if (tree[adr][0].first == c)
      return 0;
    else
      return 1;
  }
  if (tree[adr1][c + 1 - 'a'].second == tree[adr2][c + 1 - 'a'].second) {
    fians += min(query(c + 1, adr1, licz / 2), query(c + 1, adr2, licz / 2)) +
             (licz - tree[adr2][c + 1 - 'a'].second);
    return fians;
  } else {
    if (tree[adr1][c + 1 - 'a'].second > tree[adr2][c + 1 - 'a'].second) {
      fians += licz - tree[adr1][c + 1 - 'a'].second;
      fians += query(c + 1, adr2, licz / 2);
    } else {
      fians += licz - tree[adr2][c + 1 - 'a'].second;
      fians += query(c + 1, adr1, licz / 2);
    }
  }
  return fians;
}
void solve() {
  int n, k, n2;
  char c;
  cin >> n;
  n2 = n;
  for (int i = 0; i < n; i++) {
    cin >> c;
    update(c, i);
  }
  k = 0;
  int adrr = MAXX;
  while (n > 0) {
    k++;
    n /= 2;
    adrr /= 2;
  }
  cout << query('a', adrr * 2, n2 / 2) << "\n";
  clear(n2, k + 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
}
