#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int N = 2e5 + 1;
ll dp[N][20];
ll dp2[N][17];
ll f(string s, ll start, ll logy,ll c){
    if(logy == 0){
        if(s[start] - 'a' == c){
            return 0;
        }
        else{
            return 1;
        }
    }
    if(dp[start][logy] != -1){
        return dp[start][logy];
    }
    ll ans = INF;
    ll len = pow(2, logy - 1);
    ll cnt = 0;
    //for(ll i = start; i < start + len; i++){
    //    if(s[i] - 'a' != c){
    //        cnt++;
    //    }
    //}
    ll cnt1 = dp2[start][logy - 1];
    //ans = cnt + f(s, start + len, logy - 1, c + 1);
    //cnt = 0; 
    //for(ll i = start + len; i < start + 2 * len; i++){
    //    if(s[i] - 'a' != c){
    //        cnt++;
    //    }
    //}
    ll cnt2 = dp2[start + len][logy - 1];
    if(cnt1 > cnt2){
        ans = cnt2 + f(s, start, logy - 1, c + 1);
    }
    else{
        ans = cnt1 + f(s, start + len, logy - 1, c + 1);
    }
    
    return dp[start][logy] = ans;
} 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    cin >> T;
    while (T--) {
        ll n;
        cin >> n;
        for(i = 0; i <= n; i++){
            for(j = 0; j < 20; j++){
                dp[i][j] = -1;
                dp2[i][j] = 0;
            }
        }
        string s;
        cin >> s;
        ll logy = log2(n);
        ll c = 0;
        for(ll len = logy - 1; len >= 0; len--){
            ll done = 0;
            ll start = 0;
            for(i = 0; i < n; i++){
                if(s[i] - 'a' != c){
                    dp2[start][len]++;
                }
                done++;
                if(done == pow(2, len)){
                    done = 0;
                    start = i + 1;
                }
            }
            c++;
        }
        
        
        ll ans = f(s, 0, logy, 0);
        cout << ans << endl;
    }
    return 0;
}