#include <bits/stdc++.h>
using namespace std;
const int SIZE = 131072 + 5;
char str[SIZE];
int calCost(int s, int e, char ch) {
  if (s == e) {
    if (ch == str[s]) {
      return 0;
    } else {
      return 1;
    }
  } else {
    int m = (s + e) / 2;
    int fhc = 0, shc = 0;
    for (int i = s; i <= m; i++) {
      if (str[i] != ch) {
        fhc += 1;
      }
    }
    if (fhc == 0) {
      return calCost(m + 1, e, int(ch) + 1);
    }
    for (int i = m + 1; i <= e; i++) {
      if (str[i] != ch) {
        shc += 1;
      }
    }
    if (shc == 0) {
      return calCost(s, m, int(ch) + 1);
    }
    int fans = fhc + calCost(m + 1, e, int(ch) + 1);
    int sans = shc + calCost(s, m, int(ch) + 1);
    return min(fans, sans);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    scanf("%s", str);
    printf("%d\n", calCost(0, n - 1, 'a'));
  }
  return 0;
}
