#include <bits/stdc++.h>
using namespace std;
int st(int x, int pos) { return x = x | (1 << pos); }
int Reset(int x, int pos) { return x = x & ~(1 << pos); }
int cm[131073][17], dp[131073][17][17];
string A;
long long solve(long long pos, long long k, long long ch) {
  int& ret = dp[pos][k][ch];
  if (k == 0) {
    if ((A[pos - 1] - 'a') == ch) {
      return 0;
    } else {
      return 1;
    }
  }
  int p = (1 << (k - 1)) - (cm[(1 << (k - 1)) + pos - 1][ch] - cm[pos - 1][ch]);
  int q = (1 << (k - 1)) -
          (cm[(1 << k) + pos - 1][ch] - cm[(1 << (k - 1)) + pos - 1][ch]);
  if (ret != -1) return ret;
  return ret = min(p + solve(((1 << (k - 1)) + pos), k - 1, ch + 1),
                   q + solve(pos, k - 1, ch + 1));
}
int main() {
  long long test;
  cin >> test;
  for (int cs = 1; cs <= test; cs++) {
    long long n, z;
    cin >> n;
    cin >> A;
    for (long long i = 0; i < 30; i++) {
      if ((1LL << i) & n) {
        z = i;
      }
    }
    for (long long i = 0; i <= n; i++) {
      for (long long j = 0; j <= z; j++) {
        for (long long l = 0; l < 26; l++) dp[i][j][l] = -1;
      }
    }
    for (long long i = 0; i <= n; i++) {
      for (long long j = 0; j < 26; j++) cm[i][j] = 0;
    }
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < 26; j++) cm[i + 1][j] = cm[i][j];
      cm[i + 1][A[i] - 'a']++;
    }
    cout << solve(1, z, 0) << endl;
  }
}
