#include <bits/stdc++.h>
using namespace std;
int goodstring(string s, char c) {
  if (s.size() == 1) {
    if (s[0] == c) {
      return 0;
    } else {
      return 1;
    }
  } else {
    int count1 = 0, count2 = 0;
    for (int i = 0; i < s.size() / 2; i++) {
      if (s[i] != c) {
        count1++;
      }
    }
    for (int i = s.size() / 2; i < s.size(); i++) {
      if (s[i] != c) {
        count2++;
      }
    }
    return min(
        count2 + goodstring(s.substr(0, s.size() / 2), char(c + 1)),
        count1 + goodstring(s.substr(s.size() / 2, s.size() / 2), char(c + 1)));
  }
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    cout << goodstring(s, 'a') << endl;
  }
}
