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

int dp[200000];
string s;

int solve(int L, int R, char c, int sta) {
    int l = __lg(L), r = __lg(R);
    if (dp[sta] != -1) return dp[sta]; 
    if (L+1 == R) return dp[sta] = ((s[L] == c) ? 0: 1);
    int left = 0, right = 0, M = (L+R) >> 1; 
    for (int i=L; i<M; i++) if (s[i] != c) left++;
    for (int i=M; i<R; i++) if (s[i] != c) right++;
    return dp[sta] = min(left+solve(M, R, c+1, sta<<1), right+solve(L, M, c+1, (sta<<1)+1));
}

int main() {
    int t; cin >> t;
    while (t--) {
        int n; cin >> n;
        cin >> s;
        memset(dp, -1, sizeof(dp));
        cout << solve(0, n, 'a', 1) << endl;
    }
}