import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import java.util.Comparator;
 
public class ai {
    InputStream is;
    PrintWriter out;
    long mod = (long)(1e9 + 7), inf = (long)(3e18);
    int cnt[];
    void solve() throws IOException {
        int t = ni();
        while(t-->0){
            int n = ni();
            String s = ns();
            if(n<3){
                int count = 0;
                for(int i=0;i<n;i++){
                    if(s.charAt(i)!='a')count++;
                }
                System.out.println(count);
            }
            else{
                int arr[][] = new int[n][26];
                for(int i=0;i<n;i++){
                    char ch = s.charAt(i);
                    for(int j=0;j<26;j++){
                        if(i==0){
                            if(j==ch-97){
                                arr[i][j] = 1;
                            }
                        }
                        else{
                            if(j==ch-97){
                                arr[i][j] = arr[i-1][j] + 1;
                            }
                            else{
                                arr[i][j] = arr[i-1][j];
                            }
                        }
                    }
                }
                int ans = 0;
                int l = 0;
                int r = n-1;
                char ch = 'a';
                while(l<r){
                    int mid = (r+l)/2;
                    int a = arr[mid][ch-97];
                    if(l!=0){
                        a -= arr[l-1][ch-97];
                    }
                    int b = arr[r][ch-97] - arr[mid][ch-97];
                    int len = r-l+1;
                        a = (len+1) / 2 - a;
                        b = (len+1) / 2 - b;
 
                    ans += Math.min(a,b);
                    ch++;
//                        System.out.println(a + "              " + b);
                    if(a<=b){
                        l = mid+1;
                    }
                    else{
                        r = mid;
                    }
                }
                if(s.charAt(l)!=ch)ans++;
                System.out.println(ans);
                
            }
        }
    }public long gcd(long a,long b){
        if(a%b==0)return b;
        return gcd(b,a%b);
    }
    public void test(String x){
        x += "A";
        System.out.println(x);
    }
    public void build(long arr[],long brr[],int a[],int n,int l,int r){
        if(l==r){
            arr[n] = brr[n] = a[l];
        }
        else{
            int mid = (l+r)/2;
            build(arr,brr,a,2*n,l,mid);
            build(arr,brr,a,2*n+1,mid+1,r);
            arr[n] = arr[2*n] + arr[2*n+1];
            brr[n] = Math.max(brr[2*n],brr[2*n+1]);
        }
    }
    public long sum(long arr[],int l,int r,int n,int start,int end){
        if(start>end)return 0;
        if(l==start && r==end){
            return arr[n];
        }
        int mid = (l+r)/2;
        return sum(arr,l,mid,2*n,start,Math.min(end,mid)) + sum(arr,mid+1,r,2*n+1,Math.max(mid+1,start),end);
    }
    public void increment(long arr[],long brr[],int n,int l,int r,int tl,int tr,HashMap<Long,Integer> map){
        if(l>r)return;
        if(l==r && tl==tr){
            arr[n] = map.get(arr[n]);
            brr[n] = map.get(brr[n]);
        }
        else{
            int mid = (tl+tr)/2;
            if(brr[2*n]>2)
            increment(arr,brr,2*n,l,Math.min(r,mid),tl,mid,map);
            if(brr[2*n+1]>2)
            increment(arr,brr,2*n+1,Math.max(l,mid+1),r,mid+1,tr,map);
            arr[n] = arr[2*n] + arr[2*n+1];
            brr[n] = Math.max(brr[2*n],brr[2*n+1]);
        }
    }
    public int[] sieve(int n){
        int []ans = new int[n];
        ans[1]=1;
        int i=2;
        while(i<n){
            if(ans[i]==0){
                int j=2*i;
//                ans[i]=i;
                while(j<n){
                    if(ans[j]==0)
                        ans[j] = i;
                    j+=i;
                }
            }
            i++;
        }
        return ans;
    }
    public static void main(String[] args)throws Exception { new ai().run(); }
    void run() throws Exception {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }
 
    byte input[] = new byte[1024];
    int len = 0, ptr = 0;
 
    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }
 
    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
 
    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }
}
