import java.util.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class temp {
	
	public int find(int c,int l,int r,String s,int f[][])
	{
		if(l==r)
		{
			if(s.charAt(l)!=(char)(c+97))
				return 1;
			return 0;
		}
		
		int mid = (l+r)/2;
		int ans = Integer.MAX_VALUE;
		int left = (mid-l+1) - (f[mid][c] - ((l-1)>=0 ? f[l-1][c] : 0));
		int right = (r-mid) - (f[r][c] - f[mid][c]);
		ans = Math.min(left + find(c+1,mid+1,r,s,f) , right + find(c+1,l,mid,s,f));
		return ans;
	}
	
	void solve() throws IOException
	{
		FastReader sc=new FastReader();
		int t = sc.nextInt();
		while(t-->0)
		{
			int n = sc.nextInt();
			String s = sc.next();
			int f[][] = new int[n][26];
			for(int i=0;i<n;i++)
			{
				if(i!=0)
				{
					for(int j=0;j<26;j++)
						f[i][j]+=f[i-1][j];
				}
				f[i][s.charAt(i)%97]++;
			}
			
			System.out.println(find(0,0,n-1,s,f));
		}
	}
	
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		new temp().solve();
	}
	class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
 
}