#include <bits/stdc++.h>
using namespace std;

int dp[20][20];
string s;
int solve(int L, int R, char dm) {
    if (L+1 == R) return ((s[L] == dm) ? 0 : 1);
    int l = __lg(L), r = __lg(R);
    if (dp[l][r] != -1) return dp[L][R];
    int lc = 0, rc = 0, M = (L+R) >> 1;
    for (int i=L; i<M; i++) if (s[i] != dm) lc++;
    for (int i=M; i<R; i++) if (s[i] != dm) rc++;
    // cout << "-" << L << " " << R << endl;
    // cout << "oao: " << lc << " " << rc << endl;
    return dp[l][r] = min(lc+solve(M, R, dm+1), rc+solve(L, M, dm+1));
}

int main() {
    int t; cin >> t;
    while (t--) {
        memset(dp, -1, sizeof(dp));
        int n; cin >> n;
        string sa; cin >> sa;
        if (n == 1) {
            if (sa[0] == 'a') cout << 0 << endl;
            else cout << 1 << endl;
            continue;
        }
        s = sa;
        int left = 0, right = 0;
        int M = n/2;
        for (int i=0; i<M; i++) if (s[i] != 'a') left++;
        for (int i=M; i<n; i++) if (s[i] != 'a') right++;
        cout << min(left + solve(M, n, 'b'), right + solve(0, M, 'b')) << endl;
        
    }
}