#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / gcd(a, b);
}
long long int pow(long long int base, long long int po,
                  long long int mod = 1000000007) {
  long long int ret = 1;
  while (po) {
    if (po % 2) {
      ret = (ret * base) % 1000000007;
    }
    base = (base * base) % 1000000007;
    po /= 2;
  }
  return ret;
}
long long int invMod(long long int val) {
  return pow(val, 1000000007 - 2, 1000000007);
}
int main() {
  int t, n, k;
  string str;
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> str;
    int i = 0;
    int j = n - 1;
    int mn = n;
    int cur = n / 2;
    int flg = 0;
    int charCntr = 0;
    while (i < j) {
      if (!flg) {
        for (int z = 0; z < cur; z++) {
          if (str[i + z] == ('a' + charCntr)) {
            mn--;
          }
        }
        i = i + cur;
      } else {
        for (int z = 0; z < cur; z++) {
          if (str[j - z] == ('a' + charCntr)) {
            mn--;
          }
        }
        j = j - cur;
      }
      flg = !flg;
      cur = cur / 2;
      charCntr++;
    }
    if (str[i] == ('a' + charCntr)) mn--;
    i = 0;
    j = n - 1;
    int mn1 = n;
    cur = n / 2;
    flg = 1;
    charCntr = 0;
    while (i < j) {
      if (!flg) {
        for (int z = 0; z < cur; z++) {
          if (str[i + z] == ('a' + charCntr)) {
            mn1--;
          }
        }
        i = i + cur;
      } else {
        for (int z = 0; z < cur; z++) {
          if (str[j - z] == ('a' + charCntr)) {
            mn1--;
          }
        }
        j = j - cur;
      }
      flg = !flg;
      cur = cur / 2;
      charCntr++;
    }
    if (str[i] == ('a' + charCntr)) mn1--;
    cout << min(mn, mn1) << endl;
  }
}
