#include<bits/stdc++.h>
#include <cstdio>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define M               19
#define N               131075
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1e9+7
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
string s;
int dp[26][N];
int  fun(int l, int r, char c)
{
  ////lef t
////basde case
// cout << l << "  " << r << endl;
  if (l == r)
  {
    /// cout << "come" << endl;
    if (s[l] == c)
      return 0;
    else
      return 1;
  }

  ///
  int mid = (l + r) / 2;
  //character c in left and character c in right
  //cout << (int)c - 'a' << "  " << mid << endl;
  int leftc = dp[(int)c - 'a'][mid];
  if (l != 0)
    leftc -= dp[(int)c - 'a'][l - 1];


  int rightc = dp[(int)c - 'a'][r];
  if (mid != 0)
    rightc -= dp[(int)c - 'a'][mid];

  //cout << leftc << " goes inside " << rightc << endl;
  int ll = fun(l, mid, c + 1) + (r - mid - rightc);
  int rr = fun(mid + 1, r, c + 1) + (mid - l + 1 - leftc);
  //cout << leftc << " goes " << (int)c - 'a' << "  inside " << rightc << endl;
  //cout << ll << "  " << rr << "  " << l << " " << mid << " " << r << "  " << (r - mid  - rightc) << "  " << (mid - l + 1 - leftc) << endl;
  return min(ll, rr);


}
int32_t main()
{
  c_p_c();
  w(t)
  {
    int n; cin >> n;
    cin >> s;
    for (int i = 0; i < 26; i++)
      dp[i][0] = 0;
    dp[(int)s[0] - 'a'][0]++;

    for (int i = 1; i < n; i++)
    {
      int num = (int)s[i] - 'a';
      //cout << num << " ";
      for (int j = 0; j < 26; j++)
      {
        dp[j][i] = dp[j][i - 1];
      }
      dp[num][i]++;
    }
    // cout << dp[1][1] << endl;
    cout << fun(0, n - 1, 'a') << '\n';
  }
  return 0;
}
