#include <bits/stdc++.h>
using namespace std;
string s;
int ans;
void fun(int x, int y, char c, int cnt) {
  int cnt1 = 0, cnt2 = 0;
  if (x == y) {
    if (s[x] != c) {
      cnt1++;
    }
    ans = min(ans, cnt1 + cnt);
    return;
  }
  for (int i = x; i <= x + (y - x) / 2; i++) {
    if (s[i] != c) {
      cnt1++;
    }
  }
  fun(x + (y - x) / 2 + 1, y, (char)c + 1, cnt + cnt1);
  for (int i = x + (y - x) / 2 + 1; i <= y; i++) {
    if (s[i] != c) {
      cnt2++;
    }
  }
  fun(x, x + (y - x) / 2, (char)c + 1, cnt + cnt2);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    ans = n;
    scanf("%d", &n);
    cin >> s;
    fun(0, n - 1, 'a', 0);
    printf("%d\n", ans);
  }
  return 0;
}
