#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  for (long long int i = 0; i < t; i++) {
    long long int n, k, n1;
    k = 0;
    cin >> n;
    n1 = n;
    char ch[200000];
    cin >> ch;
    long long int arr[200][100000];
    while (n1 != 1) {
      n1 = n1 / 2;
      k++;
    }
    char cur = 96 + k;
    if (n == 1) {
      if (ch[0] == 'a')
        cout << "0" << endl;
      else
        cout << "1" << endl;
    } else {
      long long int f = 2;
      long long int it = 0;
      for (long long int j = 0; j < n; j += 2) {
        if ((ch[j] == cur && ch[j + 1] == cur + 1) ||
            (ch[j] == cur + 1 && ch[j + 1] == cur)) {
          arr[1][it] = 0;
          it++;
        } else if (ch[j] == cur || ch[j] == cur + 1 || ch[j + 1] == cur ||
                   ch[j + 1] == cur + 1) {
          arr[1][it] = 1;
          it++;
        } else {
          arr[1][it] = 2;
          it++;
        }
      }
      cur--;
      while (f <= k) {
        it = 0;
        long long int a, b, c;
        a = 0;
        b = 0;
        c = 0;
        long long int nf;
        nf = pow(2, f);
        for (long long int j = 0; j < n; j += nf) {
          for (long long int z = j; z < j + nf; z++) {
            if (ch[z] != cur) a++;
          }
          for (long long int z = j; z < (j + nf) / 2; z++) {
            if (ch[z] != cur) b++;
          }
          b += arr[f - 1][2 * it + 1];
          for (long long int z = (j + nf) / 2; z < j + nf; z++) {
            if (ch[z] != cur) c++;
          }
          c += arr[f - 1][2 * it];
          arr[f][it] = min(a, min(b, c));
          it++;
        }
        cur--;
        f++;
      }
      cout << arr[k][0] << endl;
    }
  }
  return 0;
}
