#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n;
string s;
ll a[26][1<<17],dp[1<<18][26];
ll f(ll i,ll l,ll r,ll k)
{
    if(l==r)
    {
        if(s[l]=='a'+k)
            return 0;
        return 1;
    }   
    if(dp[i][k]!=-1)
        return dp[i][k];
    ll mid=(l+r)/2;
    dp[i][k]=min((mid-l+1)-a[k][mid]+(l?a[k][l-1]:0)+f(2*i+2,mid+1,r,k+1),(r-mid)-a[k][r]+a[k][mid]+f(2*i+1,l,mid,k+1));
    return dp[i][k];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--)
    {
        cin>>n>>s;

        rep(i,0,26)
        {
            rep(j,0,2*n)
                dp[i][j]=-1;
            rep(j,0,n)
            {
                a[i][j]=(j?a[i][j-1]:0);
                if(s[j]=='a'+i)
                    a[i][j]++;
            }
        }
        cout<<f(0,0,n-1,0)<<"\n";
    }
}
