#include <bits/stdc++.h>
using namespace std;
long long inf = (long long)1e18, sized = (long long)1e6 + 6;
vector<long long> v;
string s;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t, i, j, k, n;
  long long a, b, m, x, y;
  cin >> t;
  while (t--) {
    cin >> n;
    x = 0;
    y = n;
    long long ans = 0, q;
    cin >> s;
    j = 0;
    k = 0;
    m = 0;
    while (x < y - 1) {
      for (i = x; i < (x + y) / 2; i++)
        if (s[i] == 'a' + j) k++;
      for (i = (x + y) / 2; i < y; i++)
        if (s[i] == 'a' + j) m++;
      if (m > k) {
        k = 0;
        m = 0;
        for (i = (x + y) / 2; i < y; i++)
          if (s[i] != 'a' + j) k++;
        y = (x + y) / 2;
        ans += k;
      } else if (k > m) {
        m = 0;
        k = 0;
        for (i = x; i < (x + y) / 2; i++)
          if (s[i] != 'a' + j) m++;
        x = (x + y) / 2;
        ans += m;
      } else {
        m = 0;
        for (i = x; i < (x + y) / 2; i++)
          if (s[i] != 'a' + j) m++;
        ans += m;
        m = 0;
        k = 0;
        q = 1;
        while (m == k && q + j < log2(n) + 2) {
          m = 0;
          k = 0;
          for (i = x; i < (x + y) / 2; i++)
            if (s[i] == 'a' + j + q) k++;
          for (i = (x + y) / 2; i < y; i++)
            if (s[i] == 'a' + j + q) m++;
          q++;
        }
        if (m > k)
          x = (x + y) / 2;
        else
          y = (x + y) / 2;
        m = 0;
        k = 0;
      }
      j++;
      m = 0;
      k = 0;
    }
    cout << ans << endl;
  }
  return 0;
}
