#include <bits/stdc++.h>
using namespace std;
long long int tc, cnt = 0, number, many, total = 0;
int rmove[4] = {0, 0, -1, 1};
int cmove[4] = {1, -1, 0, 0};
long long int power(long long int x, long long int y, long long int mod) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return (power(x, y / 2, mod) % mod * power(x, y / 2, mod) % mod) % mod;
  else
    return x * (power(x, y / 2, mod) % mod * power(x, y / 2, mod) % mod) % mod;
}
string str;
int answer = 1e9;
int solve(int left, int right, char chr) {
  int sum = 0;
  for (int i = left; i <= right; i++) {
    if (str[i] != chr) sum++;
  }
  return sum;
}
int backtrack(int left, int right, char chr) {
  if (left == right) return solve(left, right, chr);
  int middle = (right + left - 1) / 2;
  int a = solve(left, middle, chr) + backtrack(middle + 1, right, chr + 1);
  int b = solve(middle + 1, right, chr) + backtrack(left, middle, chr + 1);
  answer = min(a, b);
  return answer;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> tc;
  while (tc--) {
    cin >> many >> str;
    cnt = 0;
    answer = 1e9;
    int temp = many;
    while (temp % 2 == 0) {
      temp /= 2;
      cnt++;
    }
    cout << backtrack(0, many - 1, 'a') << endl;
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
  return 0;
}
