import java.io.*;
import java.util.*;
public class d3prac implements Runnable 
{
    private boolean console=false;
    int ans;
    int n;
    public void solve() 
    {
    	int i;
    	n=in.ni();
    	char a[]=in.ns().toCharArray();
    	if(n==1)
    	{
    		if(a[0]=='a')
    			out.println(0);
    		else
    			out.println(1);
    		return;
    	}
    	else if(n==2)
    	{
    		int ans=2;
    		if(a[0]=='a'||a[1]=='a')
    			ans--;
    		if(a[0]=='b'||a[1]=='b')
    			ans--;
    		out.println(ans);
    		return;
    	}
    	int need[]=new int[26];
    	int p=n;
    	int j=0;
    	ans=Integer.MAX_VALUE;
    	while(p>0)
    	{
    		p/=2;
    		if(p==1)
    		{
    			need[j++]=p;
    			need[j]=p;
    			break;
    		}
    		else
    		{
    			need[j]=p;
    			j++;
    		}
    	}
    	ArrayList<Integer> v[]=new ArrayList[j+1];
    	for(i=0;i<=j;i++)
    		v[i]=new ArrayList();
    	
    	for(i=0;i<26;i++)
    	{
    		if(need[i]==0)
    			break;
    		j=0;
    		while(j<n)
    		{
    			int sum=0;
    			int k=0;
    			while(k<need[i])
    			{
    				if((a[j]-'a')!=i)
    					sum++;
    				k++;
    				j++;
    			}
    			v[i].add(sum);
    		}
    	}
    	
    	calc(2,3,1,v[0].get(0),v);
    	calc(0,1,1,v[0].get(1),v);
    	out.println(ans);
    }
    void calc(int l,int r, int i,int sum,ArrayList<Integer> v[])
    {
    	if(v[i].size()==n)
    	{
    		int m1= sum+v[i].get(l)+v[i+1].get(l+1);
    		int m2= sum+v[i+1].get(l)+v[i].get(l+1);
    		m1=Math.min(m1, m2);
    		if(m1<ans)
    			ans=m1;
    	}
    	else
    	{
    		calc(l*2+2,l*2+3,i+1,sum+v[i].get(l),v);
    		calc(l*2,l*2+1,i+1,sum+v[i].get(r),v);
    	}
    }
    
    @Override
    public void run() {
        try {  init();  } 
        catch (FileNotFoundException e) {  e.printStackTrace();   }
        
        int t= in.ni();
        
        while (t-->0) {
            solve();
            out.flush(); }
    }
    private FastInput in;    private PrintWriter out;
    public static void main(String[] args) throws Exception {	 new d3prac().run();	 }
    
    private void init() throws FileNotFoundException {
        InputStream inputStream = System.in; 	 OutputStream outputStream = System.out;
        try {  if (!console && System.getProperty("user.name").equals("sachan")) {
                outputStream = new FileOutputStream("/home/sachan/Desktop/output.txt");
                inputStream = new FileInputStream("/home/sachan/Desktop/input.txt");   	}
        }	catch (Exception ignored) {	}
        out = new PrintWriter(outputStream); 	 in = new FastInput(inputStream);
    }
    static class FastInput { InputStream obj;
    	public FastInput(InputStream obj) {	this.obj = obj;	}
        byte inbuffer[] = new byte[1024];  int lenbuffer = 0, ptrbuffer = 0;
        int readByte() { if (lenbuffer == -1) throw new InputMismatchException();
            if (ptrbuffer >= lenbuffer) { ptrbuffer = 0;
                try { lenbuffer = obj.read(inbuffer);  }
                catch (IOException e) { throw new InputMismatchException(); } }    
            if (lenbuffer <= 0) return -1;return inbuffer[ptrbuffer++]; }
        
        String ns() { int b = skip();StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b)))	  { sb.appendCodePoint(b);b = readByte(); }return sb.toString();}
        
        int ni() { int num = 0, b;boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') { minus = true;b = readByte(); }
            while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else {
                    return minus ? -num : num; }b = readByte(); }}
        
        long nl() { long num = 0;int b;boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') { minus = true;b = readByte(); }
            while (true) { if (b >= '0' && b <= '9') { num = num * 10L + (b - '0'); } else {
                    return minus ? -num : num; }b = readByte(); } }
        
        boolean isSpaceChar(int c) { return (!(c >= 33 && c <= 126)); }
        int skip() { int b;while ((b = readByte()) != -1 && isSpaceChar(b)) ;return b; }
        float nf() {return Float.parseFloat(ns());}
        double nd() {return Double.parseDouble(ns());}
        char nc() {return (char) skip();}
    }
}

