#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int testcase;
  cin >> testcase;
  for (long long int t = 0; t < testcase; t++) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    if (n == 2) {
      int ans = 0;
      if (s[0] == 'a') {
        if (s[1] != 'b') {
          ans++;
        }
        cout << ans << '\n';
        continue;
      }
      if (s[1] == 'a') {
        if (s[0] != 'b') {
          ans++;
        }
        cout << ans << '\n';
      }
    }
    if (n == 4) {
      int ans1 = 0, ans2 = 0, ans3 = 0, ans4 = 0;
      string one = "aabc", two = "aacb";
      for (int i = 0; i < n; i++) {
        if (s[i] != one[i]) {
          ans1++;
        }
        if (s[i] != two[i]) {
          ans2++;
        }
      }
      reverse(one.begin(), one.end());
      reverse(two.begin(), two.end());
      for (int i = 0; i < n; i++) {
        if (s[i] != one[i]) {
          ans3++;
        }
        if (s[i] != two[i]) {
          ans4++;
        }
      }
      cout << min({ans1, ans2, ans3, ans4}) << '\n';
      continue;
    }
    string same, same1;
    for (int i = 0; i < n / 2; i++) {
      same += "a";
      same1 += "a";
    }
    for (int i = n / 2; i < 3 * n / 4; i++) {
      same += "b";
      same1 += "b";
    }
    for (int i = 3 * n / 4; i < 7 * n / 8; i++) {
      same += "0";
      same1 += "c";
    }
    for (int i = 7 * n / 8; i < n; i++) {
      same += "c";
      same1 += "0";
    }
    int main_ans = 0;
    int ans1 = 0, ans2 = 0, ans3 = 0, ans4 = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] != same[i]) {
        if (same[i] != '0' || (s[i] != 'd')) ans1++;
      }
      if (s[i] != same1[i]) {
        if (same[i] != '0' || (s[i] != 'd')) ans2++;
      }
    }
    reverse(same.begin(), same.end());
    reverse(same1.begin(), same1.end());
    for (int i = 0; i < n; i++) {
      if (s[i] != same[i]) {
        if (same[i] != '0' || (s[i] != 'd')) ans3++;
      }
      if (s[i] != same1[i]) {
        if (same[i] != '0' || (s[i] != 'd')) ans4++;
      }
    }
    same.clear(), same1.clear();
    main_ans = min({ans1, ans2, ans3, ans4});
    ans1 = ans2 = ans3 = ans4 = 0;
    for (int i = 0; i < n / 2; i++) {
      same += "a";
      same1 += "a";
    }
    for (int i = 3 * n / 4; i < 7 * n / 8; i++) {
      same += "c";
      same1 += "0";
    }
    for (int i = 7 * n / 8; i < n; i++) {
      same += "0";
      same1 += "c";
    }
    for (int i = n / 2; i < 3 * n / 4; i++) {
      same += "b";
      same1 += "b";
    }
    for (int i = 0; i < n; i++) {
      if (s[i] != same[i]) {
        if (same[i] != '0' || s[i] != 'd') ans3++;
      }
      if (s[i] != same1[i]) {
        if (same1[i] != '0' || s[i] != 'd') ans4++;
      }
    }
    reverse(same.begin(), same.end());
    reverse(same1.begin(), same1.end());
    for (int i = 0; i < n; i++) {
      if (s[i] != same[i]) {
        if (same[i] != '0' || (s[i] != 'd')) ans1++;
      }
      if (s[i] != same1[i]) {
        if (same1[i] != '0' || s[i] != 'd') ans2++;
      }
    }
    main_ans = min({ans2, ans1, ans3, ans4});
    cout << main_ans << '\n';
  }
}
