#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int compute(int l, int r, string s, char c){
if(l==r) return s[l] == c ? 0 : 1;
int mid = l+(r-l)/2;
int cnt1=0,cnt2=0;
for(int i=l; i<=mid; i++){
if(s[i] != c) cnt1++;
}
for(int i=mid+1; i<=r; i++){
if(s[i] != c) cnt2++;
}
return min(compute(mid+1,r,s,c+1)+cnt1,compute(l,mid,s,c+1)+cnt2);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t,n;
string s;
cin>>t;
while(t-- > 0){
cin>>n>>s;
cout<<compute(0,n-1,s,'a')<<"\n";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgY29tcHV0ZShpbnQgbCwgaW50IHIsIHN0cmluZyBzLCBjaGFyIGMpewogICAgaWYobD09cikgcmV0dXJuIHNbbF0gPT0gYyA/IDAgOiAxOwogICAgaW50IG1pZCA9IGwrKHItbCkvMjsKICAgIGludCBjbnQxPTAsY250Mj0wOwogICAgZm9yKGludCBpPWw7IGk8PW1pZDsgaSsrKXsKICAgICAgICBpZihzW2ldICE9IGMpIGNudDErKzsKICAgIH0KICAgIGZvcihpbnQgaT1taWQrMTsgaTw9cjsgaSsrKXsKICAgICAgICBpZihzW2ldICE9IGMpIGNudDIrKzsKICAgIH0KICAgIHJldHVybiBtaW4oY29tcHV0ZShtaWQrMSxyLHMsYysxKStjbnQxLGNvbXB1dGUobCxtaWQscyxjKzEpK2NudDIpOwp9CgppbnQgbWFpbigpewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKE5VTEwpOwogICAgaW50IHQsbjsKICAgIHN0cmluZyBzOwogICAgY2luPj50OwogICAgd2hpbGUodC0tID4gMCl7CiAgICAgICAgY2luPj5uPj5zOwogICAgICAgIGNvdXQ8PGNvbXB1dGUoMCxuLTEscywnYScpPDwiXG4iOwogICAgfQogICAgcmV0dXJuIDA7Cn0=